class-wc-widget-brand-description.php
1 year ago
class-wc-widget-brand-nav.php
7 months ago
class-wc-widget-brand-thumbnails.php
1 year ago
class-wc-widget-cart.php
3 years ago
class-wc-widget-layered-nav-filters.php
2 years ago
class-wc-widget-layered-nav.php
3 months ago
class-wc-widget-price-filter.php
8 months ago
class-wc-widget-product-categories.php
7 months ago
class-wc-widget-product-search.php
5 years ago
class-wc-widget-product-tag-cloud.php
5 years ago
class-wc-widget-products.php
1 year ago
class-wc-widget-rating-filter.php
5 years ago
class-wc-widget-recent-reviews.php
2 months ago
class-wc-widget-recently-viewed.php
1 year ago
class-wc-widget-top-rated-products.php
5 years ago
class-wc-widget-recent-reviews.php
99 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Recent Reviews Widget. |
| 4 | * |
| 5 | * @package WooCommerce\Widgets |
| 6 | * @version 2.3.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Widget recent reviews class. |
| 13 | */ |
| 14 | class WC_Widget_Recent_Reviews extends WC_Widget { |
| 15 | |
| 16 | /** |
| 17 | * Constructor. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | $this->widget_cssclass = 'woocommerce widget_recent_reviews'; |
| 21 | $this->widget_description = __( 'Display a list of recent reviews from your store.', 'woocommerce' ); |
| 22 | $this->widget_id = 'woocommerce_recent_reviews'; |
| 23 | $this->widget_name = __( 'Recent Product Reviews', 'woocommerce' ); |
| 24 | $this->settings = array( |
| 25 | 'title' => array( |
| 26 | 'type' => 'text', |
| 27 | 'std' => __( 'Recent reviews', 'woocommerce' ), |
| 28 | 'label' => __( 'Title', 'woocommerce' ), |
| 29 | ), |
| 30 | 'number' => array( |
| 31 | 'type' => 'number', |
| 32 | 'step' => 1, |
| 33 | 'min' => 1, |
| 34 | 'max' => '', |
| 35 | 'std' => 10, |
| 36 | 'label' => __( 'Number of reviews to show', 'woocommerce' ), |
| 37 | ), |
| 38 | ); |
| 39 | |
| 40 | parent::__construct(); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Output widget. |
| 45 | * |
| 46 | * @see WP_Widget |
| 47 | * @param array $args Arguments. |
| 48 | * @param array $instance Widget instance. |
| 49 | */ |
| 50 | public function widget( $args, $instance ) { |
| 51 | global $comments, $comment; |
| 52 | |
| 53 | if ( $this->get_cached_widget( $args ) ) { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | ob_start(); |
| 58 | |
| 59 | $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; |
| 60 | $comments = get_comments( |
| 61 | array( |
| 62 | 'number' => $number, |
| 63 | 'status' => 'approve', |
| 64 | 'post_status' => 'publish', |
| 65 | 'post_type' => 'product', |
| 66 | 'parent' => 0, |
| 67 | 'update_comment_post_cache' => true, |
| 68 | ) |
| 69 | ); // WPCS: override ok. |
| 70 | |
| 71 | if ( $comments ) { |
| 72 | $this->widget_start( $args, $instance ); |
| 73 | |
| 74 | echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_review_list', '<ul class="product_list_widget">' ) ); |
| 75 | |
| 76 | foreach ( (array) $comments as $comment ) { |
| 77 | wc_get_template( |
| 78 | 'content-widget-reviews.php', |
| 79 | array( |
| 80 | 'comment' => $comment, |
| 81 | 'product' => wc_get_product( $comment->comment_post_ID ), |
| 82 | ) |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | echo wp_kses_post( apply_filters( 'woocommerce_after_widget_product_review_list', '</ul>' ) ); |
| 87 | |
| 88 | $this->widget_end( $args ); |
| 89 | |
| 90 | } |
| 91 | |
| 92 | $content = ob_get_clean(); |
| 93 | |
| 94 | echo $content; // WPCS: XSS ok. |
| 95 | |
| 96 | $this->cache_widget( $args, $content ); |
| 97 | } |
| 98 | } |
| 99 |