Skip to content

Conversation

@sidharthpandita1
Copy link
Contributor

What?

Closes #72845

Adds an "Exclude post author" option to the Latest Comments block, allowing users to filter out comments made by the post author from the displayed list.

Why?

Currently, the Latest Comments block displays all comments including replies from the blog author. For blogs where authors actively reply to comments, this can clutter the "Latest Comments" list with the author's own responses instead of highlighting community engagement and reader feedback. This feature gives users control over whether to show or hide the post author's comments in the Latest Comments block.

How?

  • Added excludePostAuthor boolean attribute to block.json (default: false)
  • Added a ToggleControl in edit.js settings panel to control the filtering option
  • Implemented filtering logic in index.php using array_filter() to exclude comments where comment.user_id matches post.post_author
  • Filtering only applies when excludePostAuthor is set to true
  • Comments from non-registered users (user_id = 0) are always preserved regardless of the setting
  • No database queries are modified; filtering is performed in memory after retrieving comments

Testing Instructions

Basic Functionality:

  1. Create or open a post with comments
  2. As the post author, add some replies to existing comments (you must be logged in as the post author)
  3. Insert a Latest Comments block
  4. Open the block settings panel on the right sidebar
  5. Verify you see a new toggle labeled "Exclude post author" with help text "Hide comments from the post author."
  6. By default (unchecked), all comments should be visible including the post author's replies
  7. Check the "Exclude post author" toggle
  8. The post author's replies should disappear from the preview, showing only visitor comments
  9. Uncheck the toggle
  10. The post author's replies should reappear
  11. Save the post and view it on the frontend
  12. Verify the filtering works correctly on the frontend as well

Edge Cases:

  1. Non-registered users: Add comments without being logged in - these should always display regardless of the toggle setting
  2. Multiple posts with different authors: Create posts by different authors and verify each post correctly filters only that specific post author's comments
  3. All comments from author: Create a scenario where all comments are from the post author, enable the filter, and verify the "No comments to show." message appears
  4. Backward compatibility: Open an existing Latest Comments block (one created before this change) and verify it still works with all comments shown by default

Testing Instructions for Keyboard

  1. Insert a Latest Comments block
  2. Press Tab to navigate through the block toolbar to the settings panel
  3. Continue pressing Tab until you reach the "Exclude post author" toggle
  4. Press Space or Enter to toggle the checkbox on/off
  5. Verify the block preview updates accordingly when toggled
  6. Verify focus remains on or near the toggle after activation
  7. Use a screen reader to verify the toggle label, state, and help text are properly announced
  8. Ensure all other keyboard navigation (Display avatar, Display date, Display content, Number of comments) continues to work correctly

Screenshots or screencast

Screenshot 2025-10-31 at 2 20 50 AM

Settings Panel View:

  • Display avatar: [Toggle]
  • Display date: [Toggle]
  • Display content: [Dropdown]
  • Exclude post author: [Toggle] ← New
  • Number of comments: [Slider]

Additional Notes

  • This is a new feature; no deprecation logic is needed
  • Default value is false to maintain existing behavior (show all comments)
  • No performance impact - filtering is done in memory on already-fetched comments
  • Works seamlessly with existing Latest Comments block features (display content options, avatar, date, etc.)

@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: sidharthpandita1 <sidharthpandita@git.wordpress.org>
Co-authored-by: jartes <jartes@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@sidharthpandita1
Copy link
Contributor Author

any suggestions @t-hamano

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Block] Latest Comments Affects the Latest Comments Block labels Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Latest Comments Affects the Latest Comments Block [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Latest Comments Block: add option to filter out comments from blog author

2 participants