null, 'showImage' => true, 'showDescription' => true, 'showPrice' => true, 'showButton' => true, 'buttonText' => __('Buy Now', 'fluent-crm'), 'backgroundColor' => '#fffeeb', 'contentColor' => '', 'pricingColor' => '', 'template' => 'left', ]; $attrs = isset($data['attrs']) && is_array($data['attrs']) ? $data['attrs'] : []; $atts = wp_parse_args($attrs, $defaultAtts); $productId = absint($atts['productId']); if (!$productId) { return ''; } $product = self::getProductData($productId); if (!$product) { return ''; } $template = self::normalizeTemplate(Arr::get($atts, 'template', 'left')); $showImage = RenderValueHelper::normalizeBool(Arr::get($atts, 'showImage'), true); $showDescription = RenderValueHelper::normalizeBool(Arr::get($atts, 'showDescription'), true); $showPrice = RenderValueHelper::normalizeBool(Arr::get($atts, 'showPrice'), true); $showButton = RenderValueHelper::normalizeBool(Arr::get($atts, 'showButton'), true); $tableStyle = 'border-radius: 5px;'; $contentColorStyle = ''; if ($bgColor = Arr::get($atts, 'backgroundColor')) { $tableStyle .= 'background-color:' . sanitize_text_field($bgColor) . ';'; } if ($contentColor = Arr::get($atts, 'contentColor')) { $safeContentColor = sanitize_text_field($contentColor); $tableStyle .= 'color:' . $safeContentColor . ';'; $contentColorStyle = 'color:' . $safeContentColor . ';'; } $priceStyle = ''; if ($pricingColor = Arr::get($atts, 'pricingColor')) { $priceStyle = 'color:' . sanitize_text_field($pricingColor) . ';'; } $contentHtml = sprintf( '

%3$s

', $contentColorStyle, esc_url($product['permalink']), wp_kses_post($product['name']) ); if ($showDescription && !empty($product['short_description'])) { $contentHtml .= sprintf( '
%2$s
', $contentColorStyle, wp_kses_post($product['short_description']) ); } if ($showPrice) { $contentHtml .= sprintf( '
%2$s
', $priceStyle, ProductListRenderer::preparePriceHtml($product['price_html'], __('Free', 'fluent-crm')) ); } $image = ''; if ($showImage && $template !== 'none') { $customImage = trim((string)Arr::get($atts, 'customImage')); $image = $customImage ? esc_url_raw($customImage) : $product['image']; } if (!$image) { $template = 'none'; } if ($showButton) { $fallbackButton = '' . esc_html(Arr::get($atts, 'buttonText', __('Buy Now', 'fluent-crm'))) . ''; $contentHtml .= '
' . ($buttonHtml ?: $fallbackButton) . '
'; } $contentStyle = ''; if ($template === 'none' || $template === 'top') { $contentStyle = 'text-align:center;'; } $imageTd = ''; if ($image) { if ($template === 'top') { $contentHtml = '' . esc_attr(wp_strip_all_tags($product['name'])) . '' . $contentHtml; } elseif ($template === 'left') { $imageContent = '' . esc_attr(wp_strip_all_tags($product['name'])) . ''; $imageTd = self::getContentTd($imageContent, $template); } } ob_start(); ?>
' . $contentHtml . '
'; } private static function normalizeTemplate($template) { $template = is_string($template) ? trim($template) : 'left'; return in_array($template, ['left', 'top', 'none'], true) ? $template : 'left'; } }