Approve comment hook?

I’m looking to send out emails to subscribers when a comment has been approved.

The two actions in the Codex are:

Read More

1.

add_action('comment_post', 'callback', $priority, $accepted_args);

Where the arguments are comment_ID and approval status (0 or 1).

2.

add_action('edit_comment', 'callback', $priority, $accepted_args);

With argument comment_ID

By default comments are not approved when they are posted so I think I would be editing them when I approve them but it’s unclear in the Codex. Which option should I use when I approve a comment?

Related posts

Leave a Reply

1 comment

  1. Just like posts, a comment can have an array of different statuses, so instead of naming a hook with each status, they have transition hooks, which tell you what status it had before and what’s the new status. In your case, this might do the trick:

    add_action('transition_comment_status', 'my_approve_comment_callback', 10, 3);
    function my_approve_comment_callback($new_status, $old_status, $comment) {
        if($old_status != $new_status) {
            if($new_status == 'approved') {
                // Your code here
            }
        }
    }
    

    Let us know how it goes?