How to change the email notification recipient (user) for new comments?

How do you change the user that gets the notification email announcement for new comments and comment moderation?

WordPress sends the notices to the admin user. My client is the editor of the site. I want the comment notices to get mailed to the editor user and not the admin user.

How do you do that?

5 s
5

There’s a great article explaining how to hook into 2 filters for this at https://web.archive.org/web/20200216075253/http://www.sourcexpress.com/customize-wordpress-comment-notification-emails/

To send your notifications to a particular user and not the site admin, try this for a user with ID 123:

function se_comment_moderation_recipients( $emails, $comment_id ) {
    $comment = get_comment( $comment_id );
    $post = get_post( $comment->comment_post_ID );
    $user = get_user_by( 'id', '123' );

    // Return only the post author if the author can modify.
    if ( user_can( $user->ID, 'edit_published_posts' ) && ! empty( $user->user_email ) ) {
        $emails = array( $user->user_email );
    }

    return $emails;
}
add_filter( 'comment_moderation_recipients', 'se_comment_moderation_recipients', 11, 2 );
add_filter( 'comment_notification_recipients', 'se_comment_moderation_recipients', 11, 2 );

Leave a Comment