'', '2' => '', '3' => '', '4' => '', '5' => '', ); } /** * Server-side render for the Testimonial module. * * Mirrors the D4 render() markup (and the VB edit component) exactly: * same class names, same SVG quote icons, same conditional layout matrix * (img_position x reviewer_position x ratings_position x review_design). * Keep byte-for-byte identical with src/divi5/modules/testimonial/edit.jsx. * * @param array $attrs Block attributes. * @param string $content Block content (unused). * @param WP_Block $block Parsed block. * @param ModuleElements $elements Module elements helper. * * @return string */ public static function render_callback($attrs, $content, $block, $elements) { $advanced = $attrs['module']['advanced'] ?? []; // D4 parity (dt_if_not_migrated()): legacy installs (the `ba_version` // option exists) shipped different D4 defaults for these fields. // module.json carries the NEW-USER default; when the attr is absent on // a legacy install we fall back to the legacy default so migrated // layouts render unchanged. $is_legacy = (bool) get_option('ba_version'); $alignment = $advanced['alignment']['desktop']['value'] ?? 'center'; $img_position = $advanced['imgPosition']['desktop']['value'] ?? 'relative'; $reviewer_position = $advanced['reviewerPosition']['desktop']['value'] ?? ($is_legacy ? 'bottom' : 'top'); $ratings_position = $advanced['ratingsPosition']['desktop']['value'] ?? ($is_legacy ? '_default' : 'bottom'); $use_rating = $advanced['useRating']['desktop']['value'] ?? ($is_legacy ? 'off' : 'on'); $hide_quote = $advanced['hideQuote']['desktop']['value'] ?? ($is_legacy ? 'off' : 'on'); $rating = (int) ($advanced['rating']['desktop']['value'] ?? '5'); $icon_placement = $advanced['iconPlacement']['desktop']['value'] ?? 'background'; $use_custom_icon = $advanced['useCustomIcon']['desktop']['value'] ?? 'off'; $selected_icon = $advanced['selectedIcon']['desktop']['value'] ?? '5'; $website_url = DynamicValue::resolve($advanced['websiteUrl']['desktop']['value'] ?? ''); $company_url = DynamicValue::resolve($advanced['companyUrl']['desktop']['value'] ?? ''); $link_target = ('on' === ($advanced['linkNewWindow']['desktop']['value'] ?? 'off')) ? '_blank' : '_self'; // The D5 upload field stores the image as an object (`{ src, ... }`); // accept both that and a plain URL string (the migrated D4 value). $image_val = DynamicValue::resolve($attrs['image']['innerContent']['desktop']['value'] ?? ''); $image_src = is_array($image_val) ? ($image_val['src'] ?? '') : $image_val; $image_alt = $attrs['image']['advanced']['alt']['desktop']['value'] ?? ''; $name_val = $attrs['name']['innerContent']['desktop']['value'] ?? ''; $title_val = $attrs['title']['innerContent']['desktop']['value'] ?? ''; $testimonial_val = $attrs['testimonial']['innerContent']['desktop']['value'] ?? ''; // Quote icon (mirrors D4 render_quote_icon()): rendered only when the // quote is not hidden AND the chosen placement matches. With a custom // icon image the span stays empty (the image is a CSS background). $icons = self::get_quote_icons(); $render_quote_icon = function ($cls, $placement) use ($hide_quote, $icon_placement, $use_custom_icon, $selected_icon, $icons) { if ('off' !== $hide_quote || $icon_placement !== $placement) { return ''; } $svg = ('off' === $use_custom_icon) ? ($icons[$selected_icon] ?? '') : ''; return sprintf( '
', esc_attr($cls), $svg ); }; // Star rating (mirrors D4 render_rating()). $render_rating = function ($pos) use ($use_rating, $ratings_position, $rating) { if ('on' !== $use_rating || $ratings_position !== $pos) { return ''; } $stars = ''; for ($i = 0; $i < $rating; $i++) { $stars .= '★'; } return sprintf('', $stars); }; // Reviewer image (mirrors D4 _render_image()). $render_image = function ($positions) use ($image_src, $image_alt, $img_position) { if (empty($image_src) || !in_array($img_position, $positions, true)) { return ''; } return sprintf( '%1$s
', DynamicValue::resolve($testimonial_val)) : '' ); $children = sprintf( '