4

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?

  • Did either answer help you? If so then please consider accepting one. – Andy Macaulay-Brook Sep 20 '16 at 12:42
4

There's a great article explaining how to hook into 2 filters for this at 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 );
| improve this answer | |
2

I'm not aware of any hook that could change only the comment notification recipient... You would probably need to overwrite some kind of core function, but here's a small workaround you could use:

1. Disable the email feature from WordPress comments settings (unless you want to get notified too)

2. Send it manually using the comment_post action hook. Just add this function to functions.php

    add_filter( 'comment_post', 'comment_notification' );

    function comment_notification( $comment_ID, $comment_approved ) {

        // Send email only when it's not approved
        if( $comment_approved == 0 ) {

            $subject = 'subject here';
            $message = 'message here';

            wp_mail( 'editor.email@here.com' , $subject, $message );
        }
    }

    // Remove if statement if you want to recive email even if it doesn't require moderation

`comment_post` is an action triggered immediately after a comment is inserted into the database.
| improve this answer | |
1

There is a filter for changing the text of the comment moderation email:

function change_comment_email( $body, $comment_id ) {
    $body = preg_replace( "/(A new )comment/s",  "$1review", $body );
    $body = preg_replace( "/(Currently \d+ )comment/s",  "$1review", $body );
    $body = preg_replace( "/Comment:/",  "Review:", $body );
    return $body;
}

add_filter( 'comment_moderation_text', 'change_comment_email', 20, 2 );
add_filter( 'comment_notification_text', 'change_comment_email', 20, 2 );
| improve this answer | |
0

An alternative and more flexible way to the code hacking in the other answers is:

Create an email address for the admin account of the blog. For example, site@your-blog.tld that is different from editor@your-blog.tld and technical@your-blog.tld.

Option A: Forward site@ email to both the editor and the technical admin. I create site@ as an alias. This works if your editor is okay with receiving a copy of all the automatic email generated by the site. They just filter irrelevant email out or learn what actually happens with a site. This is good for small clients.

Option B: Set up a mail filter for site@ to automatically forward emails about comment alerts to the editor and all email to the technical admin. The technical admin can then filter to archive/delete all comment alerts so they never appear in their inbox. This initial forward to editor@ can be done on the mail server using something like procmail. Alternatively you can do it on your email client if it's up 24/7 or you can even use Gmail, Hotmail, etc. and manually build the filter.

| improve this answer | |

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