Hack: Force Comment Notification Emails To Admin Only

What if you don’t want authors or contributors to get notifications when a new comment is posted? After all, those notification emails contain a lot of information, like IP addresses and such. A simple fix is to use the comment_notification_recipients hook to force only the admin to get these messages.

You can add this to your functions.php file, or to your custom plugin.

add_filter('comment_moderation_recipients', 'wpfilter_comment_moderation_recipients');
add_filter('comment_notification_recipients', 'wpfilter_comment_moderation_recipients');
function wpfilter_comment_moderation_recipients($emails) {
	return array(get_option('admin_email'));
}

Notice I also added the hook comment_moderation_recipients so this works both for comments that are posted, and those held for moderation. You could change the returned array to a specific email address too, in quotes, which could be handy if you have a different email address you want to use for these notifications.

Another way to go here is to use the comment_notification_text filter to change the information in these messages. I’ll look at that in a future post.

Leave a Reply

Your email address will not be published. Required fields are marked *