close
Skip to content

Add sorting and filtering plus additional labelling to Comment Moderation#518

Merged
dkotter merged 18 commits into
WordPress:developfrom
Intenzi:feature/sort-filter-label-comment-moderation
May 11, 2026
Merged

Add sorting and filtering plus additional labelling to Comment Moderation#518
dkotter merged 18 commits into
WordPress:developfrom
Intenzi:feature/sort-filter-label-comment-moderation

Conversation

@Intenzi
Copy link
Copy Markdown
Contributor

@Intenzi Intenzi commented May 7, 2026

What?

Closes #509

  • Added Sorting, Filtering in Comments screen for Sentiment, Toxicity.
  • Updated Activity Widget -> Recent Comments section to include Sentiment, Toxicity pills for each comment.
  • Added tests to validate the same.

Why?

Presently there is no UX to sort and filter in Comments screen for the new Comment Moderation Experiment 's Sentiment and Toxicity Analysis. This acts as a UX enhancement.
By displaying the pills in the Admin dashboard as well for the Activity widget's Recent Comments section, we maintain consistency in our User Experience.

How?

  • Sorting and Filtering Logic:

    • Adds wpai_sentiment and wpai_toxicity to the sortable columns via the manage_edit-comments_sortable_columns filter.
    • Hooks into restrict_manage_comments to inject custom dropdowns for Sentiment and Toxicity filtering.
    • Updates the pre_get_comments logic (via handle_sorting_and_filtering) to intercept list table queries and adds relevant meta query for filtering.
  • Dashboard Integration & Scoping of Pills:

    • Hooks into get_comment_excerpt to inject AI sentiment and toxicity "pills" into the Dashboard's Activity widget.
    • Uses get_current_screen() to scope UI injection to the dashboard only.
    • Introduces the wpai_comment_moderation_show_dashboard_pills filter, allowing third-party developers to opt-out of dashboard pill rendering if needed.
    • Optimises add_inline_styles hooked to admin_head-edit-comments.php and admin_head-index.php for conditional rendering to ensures that the styling is only rendered on the exact required screens.
  • Automated Testing:

    • Adds new integration tests in Comment_ModerationTest.php that validate the meta_query logic for sentiment and medium toxicity ranges.
    • Includes visibility tests for the dashboard pills to ensure they only appear on the correct screens and respect the opt-out filter.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini 3.1 Pro, Gemini 3 Flash
Used for: Gemini built an initial solution, test cases were written via the same. I have manually reviewed, refactored the code and decided on the approach to be taken.

Testing Instructions

  1. Pull down this PR
  2. Turn on the Comment Moderation experiment
  3. Ensure you have an AI Connector in place
  4. Ensure comments are allowed on your site
  5. As a logged-in user (Admin/Editor), go to the front-end and leave a comment. Ensure this comment is saved.
  6. Go to the Comments screen in the admin and ensure you see this comment and you see Sentiment and Toxicity values
  7. Make multiple comments/atleast one of each sentiment and toxicity.
  8. Check Admin Dashboard -> Activity Widget to observe the Recent Comments showing relevant pills.
  9. Check Comments Screen for sorting toggles present on Sentiment and Toxicity columns.
  10. Click on them to test the same.
  11. Check the Comments Screen for Filter Dropdowns for Sentiment and Toxicity.
  12. Select any and press the Filter button to observe the filtered out comments.

You may also run the added tests to validate the functioning.

Screenshots or screencast

Before After
image image
Before After
image image

Screenshot showcasing filtering by Sentiment:
image

Changelog Entry

Added - Sorting, Filtering in Comments screen by Toxicity, Sentiment with labelling in Admin Dashboard for Comments to include relevant pills of Toxicity and Sentiment.

Open WordPress Playground Preview

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 70.52023% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.75%. Comparing base (3f8aec5) to head (8752392).
⚠️ Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
...eriments/Comment_Moderation/Comment_Moderation.php 70.58% 50 Missing ⚠️
.../Abilities/Comment_Moderation/Comment_Analysis.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #518      +/-   ##
=============================================
+ Coverage      70.07%   70.75%   +0.67%     
- Complexity      1107     1144      +37     
=============================================
  Files             67       67              
  Lines           5367     5508     +141     
=============================================
+ Hits            3761     3897     +136     
- Misses          1606     1611       +5     
Flag Coverage Δ
unit 70.75% <70.52%> (+0.67%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Intenzi added 5 commits May 7, 2026 15:29
- validate for positive sentiment
- validate for medium toxicity
- validate appearance on dashboard
- validate visibility opt-out filter
@Intenzi Intenzi marked this pull request as ready for review May 7, 2026 13:25
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

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: Intenzi <intenzi@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>

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

@jeffpaul jeffpaul requested review from dkotter and jeffpaul May 7, 2026 14:39
@jeffpaul jeffpaul added this to the 1.0.0 milestone May 7, 2026
jeffpaul
jeffpaul previously approved these changes May 7, 2026
Copy link
Copy Markdown
Member

@jeffpaul jeffpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests well, thanks!

Will wait on @dkotter code review before getting this merged in.

Copy link
Copy Markdown
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good, nice work here. Left a few comments but also seeing a couple issues when testing.

If I have a comment without a sentiment or toxicity score and I filter by Positive sentiment or Low toxicity, that comment shows. Seems like this should be excluded?

Image

If I end up combining filters to where no results are found, I end up on a screen where all the filters disappear:

Image

Comment thread includes/Experiments/Comment_Moderation/Comment_Moderation.php Outdated
Comment thread includes/Experiments/Comment_Moderation/Comment_Moderation.php Outdated
Comment thread includes/Experiments/Comment_Moderation/Comment_Moderation.php Outdated
Comment thread includes/Experiments/Comment_Moderation/Comment_Moderation.php Outdated
Comment thread includes/Experiments/Comment_Moderation/Comment_Moderation.php Outdated
Comment thread includes/Experiments/Comment_Moderation/Comment_Moderation.php
Comment thread includes/Experiments/Comment_Moderation/Comment_Moderation.php
Copy link
Copy Markdown
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have good unit tests here but would be great to update our E2E tests to have them verify the filters and sorts work

@Intenzi
Copy link
Copy Markdown
Contributor Author

Intenzi commented May 7, 2026

Thankyou for the PR review, testing! @dkotter

If I have a comment without a sentiment or toxicity score and I filter by Positive sentiment or Low toxicity, that comment shows. Seems like this should be excluded?

I am unable to reproduce this issue. Can you check if the comment has metadata present in the database?

If I end up combining filters to where no results are found, I end up on a screen where all the filters disappear:

I did notice this. I've implemented the filters via restrict_manage_comments and explored making the filters persistent when results are empty, but since WP_List_Table bails out on empty states, I opted to stick with the native WordPress behavior to keep the UI consistent with Core's UX. I could not find a clean alternative to this approach and would like to know how we should proceed for this.

@dkotter
Copy link
Copy Markdown
Collaborator

dkotter commented May 8, 2026

I am unable to reproduce this issue. Can you check if the comment has metadata present in the database?

Ah, yep, seems that was it. Which does bring up a question on why those values weren't showing in the columns but not related to the filtering.

but since WP_List_Table bails out on empty states, I opted to stick with the native WordPress behavior to keep the UI consistent with Core's UX

Hmm.. I guess if this is core behavior (to have all filters hide if nothing matches) then I'm fine with sticking with it. Seems odd that's the approach though.

Intenzi added 3 commits May 11, 2026 18:37
- Added neutral comment verification and filtering to sort/filter test
- Removed bulk analysis step to rely on automatic background analysis
@Intenzi
Copy link
Copy Markdown
Contributor Author

Intenzi commented May 11, 2026

@dkotter I have implemented the feedback changes and added e2e test for filtering and sorting of comments. PR is ready for re-review 😄

Ah, yep, seems that was it. Which does bring up a question on why those values weren't showing in the columns but not related to the filtering.

I have noticed it occurs when a comment fails to be analyzed and then it ends up still containing the metadata (as an empty string value) instead of having no metadata.

@Intenzi Intenzi requested a review from dkotter May 11, 2026 15:08
@dkotter dkotter merged commit a06e8a4 into WordPress:develop May 11, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add sorting and filtering plus additional labeling to Comment Moderation

3 participants