'awp_recent_comments awp_widget', 'description' => __( 'Widget to display recent comments.', 'advance-widget-pack' ), ); $control_ops = array( 'width' => 200, 'height' => 250, ); parent::__construct( false, __( 'AWP Recent Comments', 'advance-widget-pack' ), $widget_ops, $control_ops ); } function widget( $args, $instance ) { $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments', 'advance-widget-pack' ); $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; if ( ! $number ) { $number = 5; } $comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', ) ) ); 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. } if ( $comments ) { $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false ); echo ''; } echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- sidebar-provided wrapper markup, trusted per WP core convention. } /** * Renders a single comment row inside the widget's