defaults = array( 'title' => __( 'Featured Posts', 'advance-widget-pack' ), 'post_count' => '5', 'check_image' => '0', 'check_category' => '0', 'check_author' => '0', 'check_comments' => '0', 'check_excerpt' => '0', 'check_views' => '0', 'check_date' => '0', 'posts_category' => '', ); $widget_ops = array( 'classname' => 'post_plugin awp_widget', 'description' => __( 'Widget to display post details', 'advance-widget-pack' ), ); $control_ops = array( 'width' => 200, 'height' => 250, ); parent::__construct( false, __( 'AWP Featured Posts', 'advance-widget-pack' ), $widget_ops, $control_ops ); } public function form( $instance ) { $instance = wp_parse_args( (array) $instance, $this->defaults ); $title = $instance['title']; $post_count = $instance['post_count']; $category = $instance['posts_category']; ?>
id="get_field_id( 'check_image' ) ); ?>" name="get_field_name( 'check_image' ) ); ?>" />
id="get_field_id( 'check_date' ) ); ?>" name="get_field_name( 'check_date' ) ); ?>" />
id="get_field_id( 'check_author' ) ); ?>" name="get_field_name( 'check_author' ) ); ?>" />
id="get_field_id( 'check_category' ) ); ?>" name="get_field_name( 'check_category' ) ); ?>" />
id="get_field_id( 'check_comments' ) ); ?>" name="get_field_name( 'check_comments' ) ); ?>" />
id="get_field_id( 'check_excerpt' ) ); ?>" name="get_field_name( 'check_excerpt' ) ); ?>" />
id="get_field_id( 'check_views' ) ); ?>" name="get_field_name( 'check_views' ) ); ?>" />
$this->get_field_name( 'posts_category' ), 'selected' => $category, 'orderby' => 'Name', 'hierarchical' => 1, 'show_option_all' => __( 'All Categories', 'advance-widget-pack' ), 'hide_empty' => '0', ) ); ?>
defaults ); $post_count = absint( $instance['post_count'] ); $category = absint( $instance['posts_category'] ); $title = apply_filters( 'widget_title', $instance['title'] ); echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- sidebar-provided wrapper markup, trusted per WP core convention. if ( $title ) { echo $args['before_title'] . esc_html( $title ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- title text is esc_html()'d; before/after_title are sidebar-provided wrapper markup. } $cache_key = 'awp_featured_posts_' . awp_cache_generation() . '_' . $category . '_' . $post_count; $post_ids = get_transient( $cache_key ); if ( false === $post_ids ) { $query_args = array( 'posts_per_page' => $post_count, 'post_type' => 'post', 'post_status' => 'publish', 'order' => 'DESC', 'no_found_rows' => true, 'update_post_term_cache' => false, ); if ( $category ) { $query_args['cat'] = $category; } $query = new WP_Query( $query_args ); $post_ids = wp_list_pluck( $query->posts, 'ID' ); set_transient( $cache_key, $post_ids, 5 * MINUTE_IN_SECONDS ); } if ( $post_ids ) { awp_is_rendering( true ); echo "