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_id int — The new comment's ID.
  • $comment_approved int|string — 1 (approved), 0 (pending), or 'spam'.
  • $comment_data array — 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

Group wizard

One session: this hook, then each related_hooks entry. Walk it and tell us what to change.

comment_post → comment_text

functions.php — comment_post
functions.php
PHP comment_post · Hook 1 of 2 · Step 1 of 7

Practice the comment_post WordPress action hook in our interactive sandbox — a VS Code-style editor with a step-by-step comment_post tutorial, add_action exercises, and instant feedback. No local WordPress install required.