WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

The two actions in the Codex are:


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

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


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?

share|improve this question
up vote 9 down vote accepted

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?

share|improve this answer
Wouldn't the tag be comment_(old status)_to_(new status), also found in the Codex? – AlxVallejo Jul 27 '12 at 14:30
Could be, too, but it implies that you know the old status. You could approve a comment marked as spam, or approve an unapproved comment, so you'd have to use two hooks in order to trigger your function. I'd say go with the transition, because it makes your code easier to maintain. – Tomas Buteler Jul 27 '12 at 14:52
excellent job - thanks! – Q Studio Nov 25 '12 at 19:06
tested with a simple wp_mail(); function, but didin't get the test message. it is working for you? I use wp 3.5.1 – user9909 Apr 4 '13 at 7:13
@user9909 just tested it running 3.5.1 and it works. Start with simpler code (error_log() in my case) and debug from there, perhaps? Using wp_mail() means additional places where things can go wrong, including many which have nothing to do with WP. – Tomas Buteler Apr 4 '13 at 11:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.