# Email Commenters When Their Comment Is Approved

> Lets people know by email when the comment they left has been approved and is live, with a link to it.

- Type: PHP
- Runs: Run everywhere
- Category: [Comments](https://wpide.com/library/category/comments/)
- Tags: comments, email, moderation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-on-comment-approval/

## Code

```php
add_action( 'transition_comment_status', function ( $new_status, $old_status, $comment ) {
    if ( 'approved' !== $new_status || 'unapproved' !== $old_status || ! is_email( $comment->comment_author_email ) ) {
        return;
    }

    if ( ! in_array( $comment->comment_type, array( '', 'comment' ), true ) || (int) $comment->user_id === get_current_user_id() ) {
        return;
    }

    wp_mail(
        $comment->comment_author_email,
        sprintf( 'Your comment on "%s" is live', wp_specialchars_decode( get_the_title( $comment->comment_post_ID ), ENT_QUOTES ) ),
        sprintf( "Hi %s,\n\nThanks for your comment. It has been approved and is now visible:\n%s", $comment->comment_author, get_comment_link( $comment ) )
    );
}, 10, 3 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Email Commenters When Their Comment Is Approved" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
