[$this, 'render'], ] ); } /** * Render callback * * @param array $attributes Block attributes * @param string $content Block content * @param WP_Block $block Block instance * @return string Rendered block HTML */ public function render(array $attributes, string $content, WP_Block $block):string { $count = $attributes['count'] ?? 5; $showRating = $attributes['showRating'] ?? true; $showDate = $attributes['showDate'] ?? true; $showReviewLink = $attributes['showReviewLink'] ?? true; $showViewAllLink = $attributes['showViewAllLink'] ?? true; $showStats = $attributes['showStats'] ?? true; $minStars = $attributes['minStars'] ?? 4; // Only show 4+ star reviews $inheritUser = $attributes['inheritUser']??null; if ($inheritUser) { global $post; $inheritUser = $post->post_author; }else { $inheritUser = null; } try { $gmb = JVB()->connect('gmb', $inheritUser); if (!$gmb->isSetUp()) { error_log('GMB Not set up for: '.(int)$inheritUser); return ''; } $gotReviews = $gmb->getReviews(); // Get all data $allReviews = $gotReviews['reviews']??[]; $reviewUrl = $gmb->getReviewUrl(); $viewAllUrl = $gmb->getReviewsViewUrl(); $average = $gotReviews['averageRating']??null; $total = $gotReviews['totalReviewCount']??null; // Filter reviews by minimum stars $reviews = []; if (!empty($allReviews)) { foreach ($allReviews as $review) { $rating = $review['starRating'] ?? 0; if ($rating >= $minStars) { $reviews[] = $review; if (count($reviews) >= $count) { break; // Got enough reviews } } } } if (empty($reviews) && empty($reviewUrl) && empty($stats)) { error_log('No reviews to display...'); return ''; } ob_start(); ?>
= 0.5; for ($i = 1; $i <= 5; $i++) { if ($i <= $fullStars) { echo jvbIcon('star', ['style' => 'fill']); } elseif ($i == $fullStars + 1 && $hasHalfStar) { echo jvbIcon('star-half', ['style'=> 'fill']); } else { echo jvbIcon('star', ['style' => 'light']); } } ?> Average
0) { ?>{ = number_format($total ) . ' ' . _n('Review', 'Reviews', $total, 'jvb')?> Total }
'fill']); // Review text if (!empty($comment)) { ?>= apply_filters('wpautop', $comment) ?>
= jvbIcon('user-circle')?>0) { ?>'fill']) : jvbIcon('star', ['style' => 'light']); } ?>= esc_html($reviewer)?>