Feat 514: add comment value score#681
Open
priyanshuhaldar007 wants to merge 5 commits into
Open
Conversation
…in admin dashboard
…y logic on JS to update te status
|
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 Unlinked AccountsThe 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. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_scorefield end-to-end:AI / Prompt layer
system-instruction.phpto 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.get_post_context()toComment_Analysis.phpto fetch and prepare that context, with a graceful 650-char truncation fallback on raw content.analyze_comment()now accepts and passes$post_idthrough to the prompt builder.Schema & storage
output_schema()andresponse_schema()both declarevalue_scoreas 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 preservesnull.META_VALUE_SCORE(_wpai_value_score) and returned in the ability response payload.Comment Moderation UI (PHP)
VALUE_SCORE_LOW / MEDIUM / HIGHconstants andget_value_score_config()with the same range-bucket shape used by toxicity, so the frontend JS can resolve badges identically.wpai_value_scorecolumn registered inadd_columns()andadd_sortable_columns().render_value_score_column()andrender_value_score_badge()added, mirroring the toxicity equivalents.handle_sorting_and_filtering()extended to supportwpai_value_scoreordering via a meta query, same pattern as toxicity sorting.enqueue_assets()now passesvalue_scorelabel config intowindow.aiCommentModerationData.labels.ai-badge--high-value,ai-badge--medium-value, andai-badge--low-valueto the existing selectors — no new colour definitions needed.Frontend JS / TSX
AnalysisResulttype extended withvalue_score: number.Windowdeclaration extended with thevalue_scorelabels shape.PendingCommenttype extended withvalueScoreBadge: HTMLElement.getValueScoreDisplay()helper added alongsidegetToxicityDisplay(), 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
Screenshots or screencast
Changelog Entry