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.
Opens WPIDE on
Code
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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.