Action Hook since 1.2.0
comment_post
Fires immediately after a comment is inserted
Description
comment_post fires right after a new comment saves — the standard place to trigger notifications or moderation logic.
When it runs
Front-end, after wp_new_comment() validates and inserts the comment via wp_insert_comment(). Fires for both approved and held-for-moderation comments.
Signature
do_action( 'comment_post', int $comment_id, int|string $comment_approved, array $comment_data );Parameters
$comment_idint — The new comment's ID.$comment_approvedint|string — 1 (approved), 0 (pending), or 'spam'.$comment_dataarray — Raw comment data that was inserted.
Examples
Basic
add_action( 'comment_post', function( $comment_id, $approved ) {
if ( 1 === $approved ) {
wp_mail( get_option( 'admin_email' ), 'New comment', 'A comment was just approved.' );
}
}, 10, 2 );Notify the admin only when a comment is auto-approved.
Real case
add_action( 'comment_post', function( $comment_id, $approved, $data ) {
if ( preg_match( '/https?:\/\//', $data['comment_content'] ) ) {
wp_set_comment_status( $comment_id, 'hold' );
}
}, 10, 3 );Auto-hold any comment containing a link for manual review.
Common Use Cases
- Send custom notification emails
- Auto-flag suspicious comments for review
- Sync comments to an external system
- Award points/badges for commenting
Common mistakes
- Assuming $comment_approved is always 1 — it can also be 0 (held for moderation) or the string 'spam'
Related hooks
FAQ
What does $comment_approved actually contain?
1 for approved, 0 for pending moderation, or the string 'spam' — check it before triggering notifications so you don't email admins about spam.
Source: wp-includes/comment.php