defaults = array( 'title' => __( 'Popular Posts', 'advance-widget-pack' ), 'post_count' => '5', 'sort_radio' => 'views', 'featured-image' => '0', 'post-date' => '0', 'post-author' => '0', 'post-category' => '0', 'comments' => '0', 'views' => '0', 'post-excerpt' => '0', ); $widget_ops = array( 'classname' => 'awp_popular_post awp_widget', 'description' => __( 'Widget to display popular posts', 'advance-widget-pack' ), ); $control_ops = array( 'id_base' => 'awp_popular_post', 'width' => 200, 'height' => 250, ); parent::__construct( 'awp_popular_post', __( 'AWP Popular Posts', 'advance-widget-pack' ), $widget_ops, $control_ops ); } public function widget( $awp_args, $instance ) { $instance = wp_parse_args( (array) $instance, $this->defaults ); $title = apply_filters( 'widget_title', $instance['title'] ); $post_count = absint( $instance['post_count'] ); $sort_by = 'comments' === $instance['sort_radio'] ? 'comments' : 'views'; echo $awp_args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- sidebar-provided wrapper markup, trusted per WP core convention. if ( ! empty( $title ) ) { echo $awp_args['before_title'] . esc_html( $title ) . $awp_args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- title text is esc_html()'d; before/after_title are sidebar-provided wrapper markup. } $post_ids = self::get_post_ids( $post_count, $sort_by ); if ( $post_ids ) { awp_is_rendering( true ); echo '
value="views">
value="comments">
id="get_field_id( 'featured-image' ) ); ?>" name="get_field_name( 'featured-image' ) ); ?>" />
id="get_field_id( 'post-date' ) ); ?>" name="get_field_name( 'post-date' ) ); ?>" />
id="get_field_id( 'post-author' ) ); ?>" name="get_field_name( 'post-author' ) ); ?>" />
id="get_field_id( 'post-category' ) ); ?>" name="get_field_name( 'post-category' ) ); ?>" />
id="get_field_id( 'comments' ) ); ?>" name="get_field_name( 'comments' ) ); ?>" />
id="get_field_id( 'views' ) ); ?>" name="get_field_name( 'views' ) ); ?>" />
id="get_field_id( 'post-excerpt' ) ); ?>" name="get_field_name( 'post-excerpt' ) ); ?>" />