Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0a7405d
Add Comment Moderation experiment
Jameswlepage Dec 19, 2025
a27bb86
Merge branch 'develop' into feature/comment-moderation
jeffpaul Dec 19, 2025
03966de
Update readme with comment moderation feature
jeffpaul Dec 20, 2025
0ee4cd8
Create screenshot-#.png
jeffpaul Dec 20, 2025
9eae9fd
Merge branch 'develop' into feature/comment-moderation
dkotter Feb 3, 2026
5443ec1
Ensure we use the proper function to avoid errors
dkotter Feb 3, 2026
2729f85
Merge branch 'develop' into feature/comment-moderation
dkotter Apr 14, 2026
c066377
Migrate experiment over to being a feature and ensure it's loaded pro…
dkotter Apr 14, 2026
f3662fa
Clean up the Comment_Analysis Ability
dkotter Apr 14, 2026
c4872e9
Set a json schema instead of asking the LLM to return in json. Fix a …
dkotter Apr 14, 2026
ffcd9a6
Fix wrong string
dkotter Apr 15, 2026
2db6ad1
Merge branch 'develop' into feature/comment-moderation
dkotter Apr 22, 2026
83e5ae4
Remove the comment reply Ability for now
dkotter Apr 22, 2026
3c3f72b
Remove more code around comment replies. Code cleanup
dkotter Apr 22, 2026
3bf92ee
Fix lint errors; remove more comment reply code; move our columns aft…
dkotter Apr 22, 2026
570f76e
Remove our query arg after processing
dkotter Apr 22, 2026
d85a89c
When a new comment is created, send it through our comment analysis a…
dkotter Apr 22, 2026
4d7b5e1
Update docs
dkotter Apr 22, 2026
fb99112
Add unit tests
dkotter Apr 22, 2026
e3587c6
Add E2E tests
dkotter Apr 22, 2026
de8395a
Change category to admin
dkotter Apr 22, 2026
8cde2b5
Fix lint and test errors
dkotter Apr 22, 2026
b7ee30f
Fix an infinite retry loop on failed analysis. Fix plugin check error
dkotter Apr 22, 2026
922bbb2
Add an inline link to trigger analysis. Fix a potential issue with re…
dkotter Apr 22, 2026
61e8a4e
Merge branch 'develop' into feature/comment-moderation
dkotter Apr 23, 2026
317a954
Run format
dkotter Apr 23, 2026
63a07a7
Merge branch 'develop' into feature/comment-moderation
dkotter May 6, 2026
df9f427
Update text used for the comment analysis action. Add a filter around…
dkotter May 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
When a new comment is created, send it through our comment analysis a…
…bility and if it is above our threshold and is negative sentiment, automatically moderate it
  • Loading branch information
dkotter committed Apr 22, 2026
commit d85a89ca2ecaaffeea0c2dec7462e1a9f45fd33e
49 changes: 46 additions & 3 deletions includes/Experiments/Comment_Moderation/Comment_Moderation.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public function register(): void {
// Register abilities.
add_action( 'wp_abilities_api_init', array( $this, 'register_abilities' ) );

// Moderate new comments.
add_action( 'wp_insert_comment', array( $this, 'moderate_comment' ), 10, 2 );

// Add columns to comments list table.
add_filter( 'manage_edit-comments_columns', array( $this, 'add_columns' ) );
add_action( 'manage_comments_custom_column', array( $this, 'render_column' ), 10, 2 );
Expand Down Expand Up @@ -143,6 +146,49 @@ public function register_abilities(): void {
);
}

/**
* Moderate newly added comments.
*
* @since x.x.x
*
* @param int $comment_id Comment ID.
*/
public function moderate_comment( $comment_id ) {
$comment = get_comment( (int) $comment_id );
if ( ! $comment || ! is_a( $comment, '\WP_Comment' ) ) {
return;
}

// Analyze the comment using the comment-analysis ability.
$ability = wp_get_ability( 'ai/comment-analysis' );
if ( ! $ability ) {
return;
}

$analysis = $ability->execute( array( 'comment_id' => $comment_id ) );
if ( is_wp_error( $analysis ) ) {
return;
}

// Moderate the comment if it is above the toxicity threshold and has a negative sentiment.
$should_moderate = $analysis['toxicity_score'] >= 0.7 && 'negative' === $analysis['sentiment'];

/**
* Filters whether the comment should be moderated.
*
* @since x.x.x
*
* @param bool $should_moderate Whether the comment should be moderated.
* @param array $analysis The analysis results.
* @param int $comment_id The comment ID.
*/
$should_moderate = apply_filters( 'wpai_comment_moderation_should_moderate', $should_moderate, $analysis, $comment_id );

if ( $should_moderate ) {
wp_update_comment( array( 'comment_ID' => $comment_id, 'comment_approved' => '0' ) );
}
}

/**
* Adds custom columns to the comments list table.
*
Expand Down Expand Up @@ -432,9 +478,6 @@ public function enqueue_assets( $hook_suffix ): void {
'enabled' => $this->is_enabled(),
)
);

// Enqueue WordPress components styles.
wp_enqueue_style( 'wp-components' );
}

/**
Expand Down