block.json
6 months ago
controller.php
6 months ago
empty.php
6 months ago
index.asset.php
6 months ago
index.js
6 months ago
style-index-rtl.css
4 months ago
style-index.css
4 months ago
view.php
6 months ago
view.php
64 lines
| 1 | <ul <?php echo wp_kses_data( get_block_wrapper_attributes() ); ?> role="list" aria-label="<?php esc_attr_e( 'Customer reviews', 'surecart' ); ?>"> |
| 2 | <?php |
| 3 | $review_index = 0; |
| 4 | $total_reviews = count( $reviews ?? [] ); |
| 5 | |
| 6 | foreach ( $reviews ?? [] as $review ) : |
| 7 | if ( empty( $review->id ) ) { |
| 8 | continue; |
| 9 | } |
| 10 | |
| 11 | ++$review_index; |
| 12 | |
| 13 | // Get an instance of the current Post Template block. |
| 14 | $block_instance = $block->parsed_block; |
| 15 | |
| 16 | // Set the block name to one that does not correspond to an existing registered block. |
| 17 | // This ensures that for the inner instances of the Post Template block, we do not render any block supports. |
| 18 | $block_instance['blockName'] = 'core/null'; |
| 19 | $filter_block_context = static function ( $context ) use ( $review ) { |
| 20 | $context['review'] = $review; |
| 21 | $context['reviewId'] = $review->id; |
| 22 | return $context; |
| 23 | }; |
| 24 | |
| 25 | // Use an early priority to so that other 'render_block_context' filters have access to the values. |
| 26 | add_filter( 'render_block_context', $filter_block_context, 1 ); |
| 27 | |
| 28 | // Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling |
| 29 | // `render_callback` and ensure that no wrapper markup is included. |
| 30 | $block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) ); |
| 31 | $has_button = ( new \WP_HTML_Tag_Processor( $block_content ?? '' ) )->next_tag( 'button' ); |
| 32 | $has_link = ( new \WP_HTML_Tag_Processor( $block_content ?? '' ) )->next_tag( 'a' ); |
| 33 | $html_tag = $has_link || $has_button ? 'form' : 'a'; |
| 34 | |
| 35 | remove_filter( 'render_block_context', $filter_block_context, 1 ); |
| 36 | |
| 37 | // Wrap the render inner blocks in a `li` element with the appropriate post classes. |
| 38 | $post_classes = implode( ' ', get_post_class( 'wp-block-post' ) ); |
| 39 | |
| 40 | $controller = new \SureCart\Models\Blocks\ProductReviewBlock(); |
| 41 | $state = $controller->state(); |
| 42 | $context = $controller->context(); |
| 43 | |
| 44 | wp_interactivity_state( 'surecart/product-review', $state ); |
| 45 | |
| 46 | // translators: 1: number of stars, 2: review number, 3: total reviews. |
| 47 | $review_aria_label = sprintf( |
| 48 | __( 'Review with %1$d out of 5 stars. %2$d of %3$d.', 'surecart' ), |
| 49 | (int) ( $review->stars ?? 0 ), |
| 50 | $review_index, |
| 51 | $total_reviews |
| 52 | ); |
| 53 | ?> |
| 54 | |
| 55 | <li |
| 56 | class="sc-product-review-link sc-has-animation-fade-up" |
| 57 | data-wp-key="review-template-item-<?php echo esc_attr( $review->id ); ?>" |
| 58 | aria-label="<?php echo esc_attr( $review_aria_label ); ?>" |
| 59 | > |
| 60 | <?php echo $block_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 61 | </li> |
| 62 | <?php endforeach; ?> |
| 63 | </ul> |
| 64 |