default_settings = apply_filters( 'abr_widget_posts_settings', array( 'title' => '', 'template' => 'list', 'posts_per_page' => 5, 'review_type' => 'all', 'orderby' => 'date', 'order' => 'desc', 'time_frame' => '', 'category' => false, 'thumbnail' => 'large', 'post_meta' => array( 'date' ), 'post_meta_compact' => false, 'thumbnail_large' => 'large', 'post_meta_large' => array( 'date' ), 'post_meta_large_compact' => false, 'thumbnail_small' => 'large', 'post_meta_small' => array( 'date' ), 'post_meta_small_compact' => false, 'avoid_duplicate' => false, 'output' => 'widget', ) ); $widget_details = array( 'classname' => 'abr_reviews_posts_widget', 'description' => esc_html__( 'Display a list of your reviews posts.', 'absolute-reviews' ), ); parent::__construct( 'abr_reviews_posts_widget', esc_html__( 'Reviews Posts', 'absolute-reviews' ), $widget_details ); } /** * Outputs the content for the current widget instance. * * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance Settings for the current widget instance. */ public function widget( $args, $instance ) { global $abr_posts; global $wp_query; if ( ! $abr_posts ) { $abr_posts = array(); } $params = array_merge( $this->default_settings, $instance ); $posts_args = array( 'posts_per_page' => $params['posts_per_page'], 'order' => $params['order'], 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, ); if ( $params['category'] ) { $category = $params['category']; $posts_args['cat'] = $category; } // Avoid Duplicate. if ( $params['avoid_duplicate'] ) { $main_posts = array(); if ( isset( $wp_query->posts ) && $wp_query->posts ) { $main_posts = wp_list_pluck( $wp_query->posts, 'ID' ); } if ( $main_posts ) { $posts_args['post__not_in'] = array_merge( $main_posts, $abr_posts ); } else { $posts_args['post__not_in'] = $abr_posts; } } // Review type. if ( 'all' !== $params['review_type'] ) { $posts_args['meta_query'] = array( 'relation' => 'OR', array( 'key' => '_abr_review_type', 'value' => $params['review_type'], ), ); } // Post order. if ( class_exists( 'Post_Views_Counter' ) && 'meta_value_num' === $params['orderby'] ) { // Post Views. $posts_args['orderby'] = 'post_views'; } else { $posts_args['orderby'] = $params['orderby']; } if ( $params['time_frame'] ) { $posts_args['date_query'] = array( array( 'column' => 'post_date_gmt', 'after' => $params['time_frame'] . ' ago', ), ); } $posts = new WP_Query( apply_filters_ref_array( 'abr_reviews_posts_widget_args', array( $posts_args, & $params ) ) ); if ( $posts->have_posts() ) { // Before Widget. echo $args['before_widget']; // XSS. // Title. if ( $params['title'] ) { echo $args['before_title'] . apply_filters( 'widget_title', $params['title'], $instance, $this->id_base ) . $args['after_title']; // XSS. } $review_id = get_the_ID(); // Class Template. $class = sprintf( 'abr-posts-template-%s', $params['template'] ); // Class Number of Posts. $class .= sprintf( ' abr-posts-per-page-%s', (int) $params['posts_per_page'] ); ?>
default_settings, $instance ); $allowed_post_meta = abr_allowed_post_meta(); $image_sizes = abr_get_list_available_image_sizes(); $templates = apply_filters( 'abr_reviews_posts_templates', array() ); ?>
/>
0 ? '- ' . str_repeat( ' ', $depth * 3 ) : ''; $selected = array_map( 'intval', $args['selected'] ); $cat_name = apply_filters( 'list_cats', $category->name, $category ); $output .= sprintf( '', esc_attr( $depth ), esc_attr( $category->term_id ), esc_html( $pad . $cat_name ), selected( in_array( $category->term_id, $selected, true ), true ) ); $output .= "\n"; } } /** * Register Widget */ function abr_reviews_posts_init() { register_widget( 'ABR_Reviews_Posts_Widget' ); } add_action( 'widgets_init', 'abr_reviews_posts_init' );