Add a new public method to the Comment_Analysis class that is used to analyze a comment#516
Conversation
… Ability class that is a shared helper to run comment analysis. The Ability itself invokes this but others can directly invoke this and bypass the permission checking the Ability API does
|
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 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. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #516 +/- ##
=============================================
+ Coverage 67.23% 68.01% +0.77%
- Complexity 1054 1058 +4
=============================================
Files 65 65
Lines 5024 5037 +13
=============================================
+ Hits 3378 3426 +48
+ Misses 1646 1611 -35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@dkotter I have tested this PR locally and it works perfectly! Posting a comment no longer errors out for Subscribers and the comment is correctly flagged and dropped into the moderation queue. I was able to verify that anonymous comments are also functional with this. I also really like this approach, keeping it scoped to the specific class instead of altering One quick thought that crossed my mind while testing this: Since this allows the background AI to run on front-end submissions, should we be worried about anonymous comment spam causing API token exhaustion (essentially a Denial of Wallet)? I don't want to distract from this PR since it perfectly fixes the immediate bug. At a minimum, if a standard spam filter (like Akismet) intercepts the comment first and flags it, such that Would you like me to open a new PR to patch that early exit check as it is a simple fix, or should I open an Issue to track this as a broader discussion about mitigating anonymous comment spam? Either way, I'm going to start working on #509 in the morning! 🌞 |
|
Thanks for the review @Intenzi!
It's a good question and open to thoughts on ways to mitigate this. It's essentially the reason we have the permission check in the first place, to limit the scope of who can initiate an AI request. But in wanting to support non-logged in comments (which I imagine are a good percentage of comments) not sure there's a great way to allow those to be scanned but not allow non-legitimate comments (other than maybe some sort of built-in rate limiting).
Yeah, I like this thought, if a comment has already been marked as spam or marked for moderation, likely no reason for us to analyze that comment.
We've so far taken the approach of limiting the amount of settings we have but this is likely a decent middle ground approach for the first problem. Maybe have this default to being on but a site can toggle it off if they don't want to analyze guest comments (or they start getting bombarded by spam and it's using too many tokens).
Always open to review PRs so I think that's a good next step here for any of the points you've raised if you have interest |
jeffpaul
left a comment
There was a problem hiding this comment.
Works well in testing, thanks!
|
I'm going to go ahead and merge this as it at least makes this comment moderation experiment work as expected. I think we have some good feedback we can follow up on though for the next release. |

What?
Closes #515
Add a new
analyze_comment_by_idmethod to theComment_Analysisclass and use that whenever we want to analyze a comment.Why?
If we directly use the
Comment_AnalysisAbility to analyze a comment, it will require thepermission_callbackto pass which requires a user to be logged in and have themoderate_commentscapability. While this is great and we want that in place, this means we can't use this class to analyze a newly added comment from a non-logged in user or a non-admin/editor user.How?
analyze_comment_by_idmethod to theComment_AnalysisclassComment_AnalysisAbility is called, the execution callback will now use this method (after passing the permission check)analyze_comment_by_idmethod. Since we hook this towp_insert_comment, WordPress has already run it's own checks so no need for us to have a permission check hereUse of AI Tools
AI assistance: Yes
Tool(s): Cursor
Model(s): GPT-5.5
Used for: Analyzing the problem and suggesting some approaches. I considered the approaches and settled on what I felt was right and AI executed on that plan. Final review and testing by me
Testing Instructions
Commentsscreen in the admin and ensure you see this comment and you see Sentiment and Toxicity valuesCommentsscreen and ensure you see this comment and you see Sentiment and Toxicity valuesChangelog Entry