继@birgire的漂亮回答之后,以下是一些其他变体:
1) 从发送列表中删除特定电子邮件
<?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(
\'[email protected]\',
\'[email protected]\',
);
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)停止向特定角色内的所有用户发送评论通知
<?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 );