Contensio logo

Comments lifecycle hooks

Action and filter hooks fired when comments are submitted, approved, or deleted.

Since 1.5.0

These hooks fire at key points in the comment lifecycle, across both the frontend submission form and the admin moderation panel.


contensio/comment/body

Type: Filter
Since: 1.5.0
Source: CommentSubmitController::store

Filter the comment body text before it is saved to the database. Use this to sanitise input, transform markup, or apply profanity filters.

Arguments

# Name Type Description
1 $body string The raw comment text submitted by the user.

Example — strip disallowed HTML tags

add_filter('contensio/comment/body', function (string $body) {
    return strip_tags($body, '<b><i><em><strong>');
});

Example — external spam/profanity filter

add_filter('contensio/comment/body', function (string $body) {
    return SpamFilter::clean($body);
});

Notes

  • You must return the $body string.
  • Applied only to self-service submissions. Admin-created or imported comments bypass this filter.

contensio/comment/submitted

Type: Action
Since: 1.5.0
Source: CommentSubmitController::store

Fired after a new comment has been saved. The comment may be in pending or approved status depending on the site's moderation settings — check $comment->status if your callback should only run for approved comments.

Arguments

# Name Type Description
1 $comment Comment The newly created comment model.

Example — notify a Slack channel

use Contensio\Models\Comment;

add_action('contensio/comment/submitted', function (Comment $comment) {
    $author = $comment->author?->name ?? $comment->author_name ?? 'Guest';
    $status = $comment->status === 'pending' ? ' (awaiting moderation)' : '';

    Slack::notify("New comment from {$author}{$status}: " . Str::limit($comment->body, 80));
});

Notes

  • Fires after the admin notification email has been queued (for pending comments).
  • $comment->content relation is not eager-loaded — call $comment->load('content') if needed.

contensio/comment/approved

Type: Action
Since: 1.5.0
Source: CommentController::approve, CommentController::bulk (approve action)

Fired when a comment's status is changed to approved via the admin panel. Does not fire for comments that are automatically approved on submission (those fire only contensio/comment/submitted).

Arguments

# Name Type Description
1 $comment Comment The comment model with status already set to approved.

Example — notify the comment author

use Contensio\Models\Comment;

add_action('contensio/comment/approved', function (Comment $comment) {
    $email = $comment->author?->email ?? $comment->author_email;
    if ($email) {
        Mail::to($email)->queue(new CommentApprovedNotification($comment));
    }
});

Notes

  • Fires after the database update — $comment->status is approved when your callback receives it.
  • Fires for both single-approve and bulk-approve actions.

contensio/comment/deleted

Type: Action
Since: 1.5.0
Source: CommentController::destroy, CommentController::bulk (delete action)

Fired after a comment has been permanently deleted. Only the ID is available — the row no longer exists.

Arguments

# Name Type Description
1 $id int The ID of the deleted comment.

Example

add_action('contensio/comment/deleted', function (int $id) {
    DB::table('plugin_comment_votes')->where('comment_id', $id)->delete();
});

Notes

  • Only fires on permanent deletion — not when a comment is trashed or marked as spam.
  • Fires for both single-delete and bulk-delete actions.