* @copyright Copyright 2014, Chris Aprea * @link http://wpaxl.com/themes/adoration * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ // Exit if accessed directly defined( 'ABSPATH' ) || exit; // Exit early if we detect that WooCommerce isn't activated. if ( ! is_woocommerce_activated() ) { return; } class Adoration_WC_Widget_Recent_Reviews extends WC_Widget { /** * Constructor */ public function __construct() { $this->widget_cssclass = 'woocommerce widget_recent_reviews'; $this->widget_description = esc_html__( 'Display a list of your most recent reviews on your site.', 'adoration' ); $this->widget_id = 'woocommerce_recent_reviews_adoration'; $this->widget_name = esc_html__( 'WooCommerce Recent Reviews', 'adoration' ); $this->settings = array( 'title' => array( 'type' => 'text', 'std' => esc_html__( 'Recent Reviews', 'adoration' ), 'label' => esc_html__( 'Title', 'adoration' ) ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 10, 'label' => esc_html__( 'Number of reviews to show', 'adoration' ) ) ); parent::__construct(); } /** * widget function. * * @see WP_Widget * * @param array $args * @param array $instance * * @return void */ public function widget( $args, $instance ) { global $comments, $comment; // Allow developers to short-circuit this function. $pre = apply_filters( 'adoration_pre_recent_reviews', false, $args, $instance ); if ( false !== $pre ) { echo $pre; return; } if ( $this->get_cached_widget( $args ) ) { return; } ob_start(); $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product' ) ); if ( $comments ) { $this->widget_start( $args, $instance ); echo '
'; $this->widget_end( $args ); } $content = ob_get_clean(); echo $content; $this->cache_widget( $args, $content ); } }