Following up on @birgire's nice answer, here are some other variations:
1) Eliminate specific emails from the sending list
<?php
/**
* Plugin Name: Disable comment/trackback/pingback notifications for specific users.
*/
function squarecandy_eliminate_admin_comment_emails( $emails ) {
// do not send to these specific emails
$donotsend = array(
'userone@example.com',
'usertwo@example.com',
);
foreach ( $emails as $key => $email ) {
if ( in_array( $email, $donotsend ) ) {
unset( $emails[$key] );
}
}
return $emails;
}
add_filter( 'comment_notification_recipients', 'squarecandy_eliminate_admin_comment_emails', PHP_INT_MAX );
add_filter( 'comment_moderation_recipients', 'squarecandy_eliminate_admin_comment_emails', PHP_INT_MAX );
2) Stop sending comment notifications to all users within certain roles
<?php
/**
* Plugin Name: Disable comment/trackback/pingback notifications emails except for certain roles.
*/
function squarecandy_eliminate_admin_comment_emails( $emails ) {
// get all the users of the roles you want to restrict
$users = get_users(
array(
'role__in' => array(
// this is the list of roles to repress comment notifications for
'editor',
'author',
),
'fields' => array(
'user_email',
),
),
);
// make an array of the emails not to send to
$donotsend = array();
foreach ( $users as $user ) {
$donotsend[] = $user->user_email;
}
foreach ( $emails as $key => $email ) {
if ( in_array( $email, $donotsend ) ) {
unset( $emails[$key] );
}
}
return $emails;
}
add_filter( 'comment_notification_recipients', 'squarecandy_eliminate_admin_comment_emails', PHP_INT_MAX );
add_filter( 'comment_moderation_recipients', 'squarecandy_eliminate_admin_comment_emails', PHP_INT_MAX );