fix(comments): add Customizer toggle for comment meta position#2691
fix(comments): add Customizer toggle for comment meta position#2691faisalahammad wants to merge 2 commits into
Conversation
dkoo
left a comment
There was a problem hiding this comment.
@faisalahammad Thanks for the new comment meta position option! The new option works as described and passes in-browser testing. Before we can merge, please address feedback in the inline comments below:
| 'comment_meta_position', | ||
| array( | ||
| 'default' => 'above', | ||
| 'sanitize_callback' => 'sanitize_text_field', |
There was a problem hiding this comment.
🛑 Blocker: Sanitizer is too permissive for a radio setting
'sanitize_callback' => 'sanitize_text_field' accepts any string. Walker logic at class-newspack-walker-comment.php:105 is 'above' === $value ? … : (below), so any non-above value silently flips to "below" — weakens backward-compat.
Suggested fix: Use the existing newspack_sanitize_radio helper to sanitize values against the choices registered via wp_customize->add_control().
| echo $comment_meta; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped above | ||
| echo $comment_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped above | ||
| } else { | ||
| echo $comment_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped above | ||
| echo $comment_meta; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped above | ||
| } |
There was a problem hiding this comment.
🔴 Blocker: phpcs:ignore is too eager
Since we're now directly echoing the entire buffered $comment_meta and $comment_content, these phpcs:ignore statements will silence the sniff for any future unsafe addition to the buffered region.
Suggested fix: wrap these in another wp_kses_post() to ensure safe output, or at the very least provide a more detailed comment indicating the potential security hole, e.g. ensure all buffered output is escaped above.
|
|
||
| $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; | ||
|
|
||
| ob_start(); |
There was a problem hiding this comment.
🟡 Suggested fix: Exception-safe buffering
Wrap each ob_start/ob_get_clean pair in try { … } finally { … } so a throwing filter (comment_text, get_avatar, etc.) can't leave buffers stuck on the stack.
| 'comment_meta_position', | ||
| array( | ||
| 'type' => 'radio', | ||
| 'label' => esc_html__( 'Comment Meta Position', 'newspack-theme' ), |
There was a problem hiding this comment.
Nit: prefer sentence casing over title casing for option labels.
| 'label' => esc_html__( 'Comment Meta Position', 'newspack-theme' ), | |
| 'label' => esc_html__( 'Comment meta position', 'newspack-theme' ), |
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 Automattic#2310
- 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
d42e620 to
6baa546
Compare
|
Thanks for the thorough review, @dkoo! I've addressed all four points:
|
dkoo
left a comment
There was a problem hiding this comment.
Thanks for the changes, @faisalahammad! This is looking good.
Summary
Adds a Customizer radio control so site editors can choose whether comment author meta (avatar, name, date) appears above or below the comment content. Defaults to above for backward compatibility.
Fixes #2310
Changes
classes/class-newspack-walker-comment.phpThe walker now buffers the
comment-metafooter andcomment-contentdiv into separate variables via output buffering, then emits them in the order determined by the newcomment_meta_positiontheme mod.inc/customizer.phpNew
comment_meta_positionsetting added to the existing Comments Settings section with a radio control: "Above comment content" / "Below comment content".Testing
Test 1: Default (above)
Test 2: Switch to below
Test 3: Switch back