我正在使用下面的代码向客户端站点的多个电子邮件地址发送评论通知和审核电子邮件。
我有一个为这个特定网站定制的管理面板。在我的管理面板中,我有一个字段,其中包含一个逗号分隔的电子邮件列表,在任何时候发布评论并需要批准或通知时,都应该通知这些电子邮件。
它工作得很好,但我的客户有一个问题。由于我的客户也是该网站的管理员,他们将收到一封评论通知电子邮件,电子邮件地址位于帐户设置下。因此,除了通过电子邮件发送逗号分隔的电子邮件列表外,它还可以发送管理帐户电子邮件。
我正在寻求有关如何禁用它的帮助,我可以通过电子邮件向管理员帐户发送电子邮件,并且只向我的自定义设置中的电子邮件发送电子邮件,下面的代码已经在这样做了。
有什么办法吗?
/**
* Email Multiple people when a Comment is Posted
*/
add_action(\'comment_post\', \'wp_notify_allmods\');
function wp_notify_allmods($comment_id) {
global $wpdb;
$cn_recipients = get_option(\'custom_comment_emails\');
//$cn_recipients = \'[email protected],[email protected],[email protected]\';
//$moderated_only_option = get_option("cn_moderated_only");
//
$comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID=\'$comment_id\' LIMIT 1");
$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID=\'$comment->comment_post_ID\' LIMIT 1");
$blogname = get_option(\'blogname\');
$blogurl = get_option(\'siteurl\');
$comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
if (get_option(\'comment_moderation\') == 1) { //if we need to send comment moderation email
$comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = \'0\'");
$notify_message = sprintf( __(\'A new comment on the post #%1$s "%2$s" is waiting for your approval\'), $post->ID, $post->post_title ) . "\\r\\n";
$notify_message .= get_permalink($comment->comment_post_ID) . "\\r\\n\\r\\n";
$notify_message .= sprintf( __(\'Author : %1$s (IP: %2$s , %3$s)\'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\\r\\n";
$notify_message .= sprintf( __(\'E-mail : %s\'), $comment->comment_author_email ) . "\\r\\n";
//$notify_message .= sprintf( __(\'URL : %s\'), $comment->comment_author_url ) . "\\r\\n";
$notify_message .= sprintf( __(\'Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s\'), $comment->comment_author_IP ) . "\\r\\n";
$notify_message .= __(\'Comment: \') . "\\r\\n" . $comment->comment_content . "\\r\\n\\r\\n";
$notify_message .= sprintf( __(\'Approve it: %s\'), $blogurl."/wp-admin/comment.php?action=mac&c=$comment_id" ) . "\\r\\n";
$notify_message .= sprintf( __(\'Delete it: %s\'), $blogurl."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\\r\\n";
$notify_message .= sprintf( __(\'Spam it: %s\'), $blogurl."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\\r\\n";
$notify_message .= sprintf( __(\'Currently %s comments are waiting for approval. Please visit the moderation panel:\'), $comments_waiting ) . "\\r\\n";
$notify_message .= get_option(\'siteurl\') . "/wp-admin/moderation.php\\r\\n";
$subject = sprintf( __(\'[%1$s] Please moderate: "%2$s"\'), $blogname, $post->post_title );
$notify_message = apply_filters(\'comment_moderation_text\', $notify_message, $comment_id);
$subject = apply_filters(\'comment_moderation_subject\', $subject, $comment_id);
$message_headers = "";
$cn_recipients_array = explode(",", $cn_recipients);
foreach ($cn_recipients_array as $email) {
@wp_mail($email, $subject, $notify_message, $message_headers);
}
} else { //or just a regular "you\'ve got a new comment" email
if ($moderated_only_option != 1) { //if comments are not modded but update notifications are set to moderated only don\'t send
$notify_message = sprintf( __(\'New comment on your post #%1$s "%2$s"\'), $comment->comment_post_ID, $post->post_title ) . "\\r\\n";
$notify_message .= sprintf( __(\'Author : %1$s (IP: %2$s , %3$s)\'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\\r\\n";
$notify_message .= sprintf( __(\'E-mail : %s\'), $comment->comment_author_email ) . "\\r\\n";
$notify_message .= sprintf( __(\'URL : %s\'), $comment->comment_author_url ) . "\\r\\n";
$notify_message .= sprintf( __(\'Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s\'), $comment->comment_author_IP ) . "\\r\\n";
$notify_message .= __(\'Comment: \') . "\\r\\n" . $comment->comment_content . "\\r\\n\\r\\n";
$notify_message .= __(\'You can see all comments on this post here: \') . "\\r\\n";
$subject = sprintf( __(\'[%1$s] Comment: "%2$s"\'), $blogname, $post->post_title );
$notify_message .= get_permalink($comment->comment_post_ID) . "#comments\\r\\n\\r\\n";
$notify_message .= sprintf( __(\'Delete it: %s\'), get_option(\'siteurl\')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\\r\\n";
$notify_message .= sprintf( __(\'Spam it: %s\'), get_option(\'siteurl\')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\\r\\n";
$notify_message = apply_filters(\'comment_notification_text\', $notify_message, $comment_id);
$subject = apply_filters(\'comment_notification_subject\', $subject, $comment_id);
$message_headers = "MIME-Version: 1.0\\n"
. "$from\\n"
. "Content-Type: text/plain; charset=\\"" . get_option(\'blog_charset\') . "\\"\\n";
$message_headers = apply_filters(\'comment_notification_headers\', $message_headers, $comment_id);
$cn_recipients_array = explode(",", $cn_recipients);
foreach ($cn_recipients_array as $email) {
@wp_mail($email, $subject, $notify_message, $message_headers);
}
}
}
return true;
}