2011-08-29 10:38:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Recent Reviews Widget.
|
2012-08-14 17:37:50 +00:00
|
|
|
*
|
2018-03-09 20:45:45 +00:00
|
|
|
* @package WooCommerce/Widgets
|
|
|
|
* @version 2.3.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Widget recent reviews class.
|
2011-08-29 10:38:01 +00:00
|
|
|
*/
|
2013-05-24 15:51:58 +00:00
|
|
|
class WC_Widget_Recent_Reviews extends WC_Widget {
|
2012-08-14 17:37:50 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Constructor.
|
2012-08-14 17:37:50 +00:00
|
|
|
*/
|
2013-05-24 15:51:58 +00:00
|
|
|
public function __construct() {
|
|
|
|
$this->widget_cssclass = 'woocommerce widget_recent_reviews';
|
2017-08-25 11:07:17 +00:00
|
|
|
$this->widget_description = __( 'Display a list of recent reviews from your store.', 'woocommerce' );
|
2013-05-24 15:51:58 +00:00
|
|
|
$this->widget_id = 'woocommerce_recent_reviews';
|
2017-08-25 11:07:17 +00:00
|
|
|
$this->widget_name = __( 'Recent Product Reviews', 'woocommerce' );
|
2013-05-24 15:51:58 +00:00
|
|
|
$this->settings = array(
|
|
|
|
'title' => array(
|
|
|
|
'type' => 'text',
|
2016-10-12 10:16:30 +00:00
|
|
|
'std' => __( 'Recent reviews', 'woocommerce' ),
|
2016-08-27 01:46:45 +00:00
|
|
|
'label' => __( 'Title', 'woocommerce' ),
|
2013-05-24 15:51:58 +00:00
|
|
|
),
|
|
|
|
'number' => array(
|
|
|
|
'type' => 'number',
|
|
|
|
'step' => 1,
|
|
|
|
'min' => 1,
|
|
|
|
'max' => '',
|
|
|
|
'std' => 10,
|
2016-08-27 01:46:45 +00:00
|
|
|
'label' => __( 'Number of reviews to show', 'woocommerce' ),
|
|
|
|
),
|
2013-05-24 15:51:58 +00:00
|
|
|
);
|
2014-11-15 01:12:59 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
parent::__construct();
|
2011-08-29 10:38:01 +00:00
|
|
|
}
|
2012-08-14 17:37:50 +00:00
|
|
|
|
|
|
|
/**
|
2016-01-06 18:58:38 +00:00
|
|
|
* Output widget.
|
2012-08-14 17:37:50 +00:00
|
|
|
*
|
|
|
|
* @see WP_Widget
|
2018-03-09 20:45:45 +00:00
|
|
|
* @param array $args Arguments.
|
|
|
|
* @param array $instance Widget instance.
|
2012-08-14 17:37:50 +00:00
|
|
|
*/
|
2018-03-09 20:45:45 +00:00
|
|
|
public function widget( $args, $instance ) {
|
2014-06-08 20:33:11 +00:00
|
|
|
global $comments, $comment;
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2014-11-15 01:12:59 +00:00
|
|
|
if ( $this->get_cached_widget( $args ) ) {
|
2011-08-29 10:38:01 +00:00
|
|
|
return;
|
2014-11-15 01:12:59 +00:00
|
|
|
}
|
2011-08-29 10:38:01 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
ob_start();
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2014-11-15 01:12:59 +00:00
|
|
|
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
|
2018-03-09 20:45:45 +00:00
|
|
|
$comments = get_comments(
|
|
|
|
array(
|
|
|
|
'number' => $number,
|
|
|
|
'status' => 'approve',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'post_type' => 'product',
|
|
|
|
'parent' => 0,
|
|
|
|
)
|
|
|
|
); // WPCS: override ok.
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2012-10-18 10:33:47 +00:00
|
|
|
if ( $comments ) {
|
2014-11-15 01:12:59 +00:00
|
|
|
$this->widget_start( $args, $instance );
|
|
|
|
|
2018-04-13 11:20:46 +00:00
|
|
|
echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_review_list', '<ul class="product_list_widget">' ) );
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-05-13 14:12:12 +00:00
|
|
|
foreach ( (array) $comments as $comment ) {
|
2018-04-13 11:20:46 +00:00
|
|
|
wc_get_template( 'content-widget-reviews.php', array(
|
|
|
|
'comment' => $comment,
|
|
|
|
'product' => wc_get_product( $comment->comment_post_ID ),
|
|
|
|
) );
|
2012-10-18 10:33:47 +00:00
|
|
|
}
|
2011-08-29 10:38:01 +00:00
|
|
|
|
2018-04-13 11:20:46 +00:00
|
|
|
echo wp_kses_post( apply_filters( 'woocommerce_after_widget_product_review_list', '</ul>' ) );
|
2014-11-15 01:12:59 +00:00
|
|
|
|
|
|
|
$this->widget_end( $args );
|
2018-04-13 11:20:46 +00:00
|
|
|
|
2012-10-18 10:33:47 +00:00
|
|
|
}
|
2011-08-29 10:38:01 +00:00
|
|
|
|
2012-05-13 21:39:21 +00:00
|
|
|
$content = ob_get_clean();
|
|
|
|
|
2018-03-09 20:45:45 +00:00
|
|
|
echo $content; // WPCS: XSS ok.
|
2012-05-13 21:39:21 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
$this->cache_widget( $args, $content );
|
2011-08-29 10:38:01 +00:00
|
|
|
}
|
2013-05-24 15:51:58 +00:00
|
|
|
}
|