From 36af006a9316fa12504ba2355855f8c53083c8b3 Mon Sep 17 00:00:00 2001 From: Faisal Ahammad Date: Wed, 6 May 2026 12:50:30 +0600 Subject: [PATCH 1/2] fix(comments): add Customizer toggle for comment meta position Allows site editors to choose whether comment author info (avatar, name, date) appears above or below the comment content. Uses a radio control in the existing Comments Settings panel. The walker now buffers comment-meta and comment-content into separate variables and outputs them in the configured order. Fixes #2310 --- .../classes/class-newspack-walker-comment.php | 133 ++++++++++-------- newspack-theme/inc/customizer.php | 21 +++ 2 files changed, 97 insertions(+), 57 deletions(-) diff --git a/newspack-theme/classes/class-newspack-walker-comment.php b/newspack-theme/classes/class-newspack-walker-comment.php index 67d563c40..a224014ed 100755 --- a/newspack-theme/classes/class-newspack-walker-comment.php +++ b/newspack-theme/classes/class-newspack-walker-comment.php @@ -25,72 +25,91 @@ protected function html5_comment( $comment, $depth, $args ) { $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; + ob_start(); ?> - < id="comment-" has_children ? 'parent' : '', $comment ); ?>> -
-
-
- ', esc_url( $comment_author_url ) ); - echo wp_kses_post( $avatar ); - } - } +
+
+ ', esc_url( $comment_author_url ) ); + echo wp_kses_post( $avatar ); + } + } - printf( - wp_kses( - /* translators: %s: comment author link */ - __( '%s says:', 'newspack-theme' ), - array( - 'span' => array( - 'class' => array(), - ), - ) + printf( + wp_kses( + /* translators: %s: comment author link */ + __( '%s says:', 'newspack-theme' ), + array( + 'span' => array( + 'class' => array(), ), - '' . get_comment_author_link( $comment ) . '' - ); + ) + ), + '' . get_comment_author_link( $comment ) . '' + ); - /* Display icon if the commenter is the current post's author. */ - if ( newspack_is_comment_by_post_author( $comment ) ) { - printf( '', wp_kses( newspack_get_icon_svg( 'person', 24, esc_html__( 'Article author', 'newspack-theme' ) ), newspack_sanitize_svgs() ) ); - } + /* Display icon if the commenter is the current post's author. */ + if ( newspack_is_comment_by_post_author( $comment ) ) { + printf( '', wp_kses( newspack_get_icon_svg( 'person', 24, esc_html__( 'Article author', 'newspack-theme' ) ), newspack_sanitize_svgs() ) ); + } - if ( ! empty( $comment_author_url ) ) { - echo ''; - } - ?> -
+ if ( ! empty( $comment_author_url ) ) { + echo ''; + } + ?> +
- + - comment_approved ) : ?> -

- -
+ comment_approved ) : ?> +

+ + + - - + ob_start(); + ?> +
+ +
+ + < id="comment-" has_children ? 'parent' : '', $comment ); ?>> +
+
add_setting( + 'comment_meta_position', + array( + 'default' => 'above', + 'sanitize_callback' => 'sanitize_text_field', + ) + ); + $wp_customize->add_control( + 'comment_meta_position', + array( + 'type' => 'radio', + 'label' => esc_html__( 'Comment Meta Position', 'newspack-theme' ), + 'section' => 'comments_options', + 'choices' => array( + 'above' => esc_html__( 'Above comment content', 'newspack-theme' ), + 'below' => esc_html__( 'Below comment content', 'newspack-theme' ), + ), + ) + ); + /** * Footer settings */ From 6baa54616f95a155e81291dfcb3ef11a98976ad5 Mon Sep 17 00:00:00 2001 From: Faisal Ahammad Date: Fri, 15 May 2026 21:17:44 +0600 Subject: [PATCH 2/2] fix(comments): address review feedback for comment meta position - Replace sanitize_text_field with newspack_sanitize_radio for choices validation - Wrap buffered output in wp_kses_post() instead of phpcs:ignore - Add try/finally with level tracking for ob_start/ob_get_clean cleanup - Use sentence casing for control label --- .../classes/class-newspack-walker-comment.php | 36 +++++++++++++------ newspack-theme/inc/customizer.php | 6 ++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/newspack-theme/classes/class-newspack-walker-comment.php b/newspack-theme/classes/class-newspack-walker-comment.php index a224014ed..56beb16ee 100755 --- a/newspack-theme/classes/class-newspack-walker-comment.php +++ b/newspack-theme/classes/class-newspack-walker-comment.php @@ -25,8 +25,11 @@ protected function html5_comment( $comment, $depth, $args ) { $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; - ob_start(); - ?> + $comment_meta = ''; + $_meta_level = ob_get_level(); + try { + ob_start(); + ?>
$_meta_level ) { + ob_end_clean(); + } + } - ob_start(); - ?> + $comment_content = ''; + $_content_level = ob_get_level(); + try { + ob_start(); + ?>
$_content_level ) { + ob_end_clean(); + } + } $comment_meta_position = get_theme_mod( 'comment_meta_position', 'above' ); @@ -103,11 +119,11 @@ protected function html5_comment( $comment, $depth, $args ) {
diff --git a/newspack-theme/inc/customizer.php b/newspack-theme/inc/customizer.php index 734cd3d3d..9c112439f 100755 --- a/newspack-theme/inc/customizer.php +++ b/newspack-theme/inc/customizer.php @@ -164,7 +164,7 @@ function newspack_customize_register( $wp_customize ) { 'slideout_label', array( 'default' => esc_html__( 'Menu', 'newspack-theme' ), - 'sanitize_callback' => 'sanitize_text_field', + 'sanitize_callback' => 'newspack_sanitize_radio', ) ); $wp_customize->add_control( @@ -1259,14 +1259,14 @@ function newspack_customize_register( $wp_customize ) { 'comment_meta_position', array( 'default' => 'above', - 'sanitize_callback' => 'sanitize_text_field', + 'sanitize_callback' => 'newspack_sanitize_radio', ) ); $wp_customize->add_control( 'comment_meta_position', array( 'type' => 'radio', - 'label' => esc_html__( 'Comment Meta Position', 'newspack-theme' ), + 'label' => esc_html__( 'Comment meta position', 'newspack-theme' ), 'section' => 'comments_options', 'choices' => array( 'above' => esc_html__( 'Above comment content', 'newspack-theme' ),