Skip to content

Feat 514: add comment value score#681

Open
priyanshuhaldar007 wants to merge 5 commits into
WordPress:developfrom
priyanshuhaldar007:feat-514/add-comment-value-score
Open

Feat 514: add comment value score#681
priyanshuhaldar007 wants to merge 5 commits into
WordPress:developfrom
priyanshuhaldar007:feat-514/add-comment-value-score

Conversation

@priyanshuhaldar007

@priyanshuhaldar007 priyanshuhaldar007 commented Jun 8, 2026

Copy link
Copy Markdown

What?

Closes #514

Adds a Value Score column to the comment moderation list table. Comments are now analyzed for how relevant and valuable they are to the article they're posted on, in addition to the existing toxicity and sentiment signals.

Why?

Toxicity and sentiment alone don't tell the full story of a comment's quality. A comment can be perfectly polite but still be spam, a generic "+1", or completely off-topic. This PR introduces a value score (0–1) so moderators can quickly identify substantive, on-topic contributions versus low-effort noise — making triage faster and more informed.

How?

The implementation follows the exact same pattern as the existing toxicity_score field end-to-end:

AI / Prompt layer

  • Updated system-instruction.php to instruct the model to return a third field, value_score, scored 0–1 with clear band definitions (low/medium/high). The prompt now also passes post context (excerpt → AI summary → trimmed content fallback) so the model can actually assess relevance against the article.
  • Added get_post_context() to Comment_Analysis.php to fetch and prepare that context, with a graceful 650-char truncation fallback on raw content.
  • analyze_comment() now accepts and passes $post_id through to the prompt builder.

Schema & storage

  • output_schema() and response_schema() both declare value_score as a nullable float (0–1). It's nullable for cases where the post content is unavailable or too sparse to judge relevance.
  • sanitize_analysis_result() clamps the value to [0, 1] and preserves null.
  • Results are stored in a new comment meta key META_VALUE_SCORE (_wpai_value_score) and returned in the ability response payload.

Comment Moderation UI (PHP)

  • Added VALUE_SCORE_LOW / MEDIUM / HIGH constants and get_value_score_config() with the same range-bucket shape used by toxicity, so the frontend JS can resolve badges identically.
  • New wpai_value_score column registered in add_columns() and add_sortable_columns().
  • render_value_score_column() and render_value_score_badge() added, mirroring the toxicity equivalents.
  • Filter dropdown added for value score levels.
  • handle_sorting_and_filtering() extended to support wpai_value_score ordering via a meta query, same pattern as toxicity sorting.
  • enqueue_assets() now passes value_score label config into window.aiCommentModerationData.labels.
  • CSS: reused existing green/yellow/red badge classes by appending ai-badge--high-value, ai-badge--medium-value, and ai-badge--low-value to the existing selectors — no new colour definitions needed.

Frontend JS / TSX

  • AnalysisResult type extended with value_score: number.
  • Window declaration extended with the value_score labels shape.
  • PendingComment type extended with valueScoreBadge: HTMLElement.
  • getValueScoreDisplay() helper added alongside getToxicityDisplay(), using the same range-bucket lookup.
  • updateBadges(), findPendingComments(), analyzeComment() all updated to handle the third badge — detection, processing state, result rendering, and failure state.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Claude Sonnet 4.6
Used for: Drafting this PR description from the git diff. All code was written and reviewed by me, with some contributions from the copilot for updating and generating doc blocks

Testing Instructions

  1. Install and activate the plugin with the AI experiment enabled.
  2. Create a post with meaningful content and leave a few comments — mix of on-topic, generic ("great post!"), and spam.
  3. Navigate to Comments in wp-admin.
  4. Confirm a Value column appears alongside Sentiment and Toxicity.
  5. Trigger analysis (or wait for lazy analysis on page load). Verify badges appear with appropriate levels — high-value comments should show 🌟 High, spam/generic should show ✓ Low.
  6. Test the Value Score filter dropdown — filtering by Low, Medium, or High should correctly narrow the list.
  7. Test sorting by clicking the Value column header — ascending and descending should order comments by their score.
  8. Confirm the dashboard comment excerpt pills also show the value score badge.

Screenshots or screencast

Before After
Screenshot 2026-06-08 at 2 06 34 PM Screenshot 2026-06-08 at 2 05 47 PM

Changelog Entry

Added - Value Score column to the comment moderation table, providing a relevance signal (0–1) for each comment based on how substantive and on-topic it is relative to the post it was left on.

Open WordPress Playground Preview

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @priyanshuhaldar007.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Unlinked contributors: priyanshuhaldar007.


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

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 comment value / relevance to Comment Moderation experiment

1 participant