Wordpress - Disabling Comment Notifications for Post Author
I skimmed through the source of the wp_notify_postauthor()
function and noticed the comment_notification_recipients
filter.
I wonder if you could simplify your plugin to the following code snippet:
<?php
/**
* Plugin Name: Disable comment/trackback/pingback notifications emails
* Plugin URI: http://wordpress.stackexchange.com/a/150141/26350
*/
add_filter( 'comment_notification_recipients', '__return_empty_array', PHP_INT_MAX );
add_filter( 'comment_moderation_recipients', '__return_empty_array', PHP_INT_MAX );
where we use an empty $emails
array to prevent any notification emails from being sent.
The first filter is to stop wp_notify_postauthor()
and the second to stop wp_notify_moderator()
.
If you want only the admin user to receive email notifications, you can use this version:
<?php
/**
* Plugin Name: Disable comment/trackback/pingback notifications emails except for admins.
* Plugin URI: http://wordpress.stackexchange.com/a/150141/26350
*/
add_filter( 'comment_notification_recipients', '__return_empty_array', PHP_INT_MAX );
add_filter( 'comment_moderation_recipients',
function( $emails )
{
// only send notification to the admin:
return array( get_option( 'admin_email' ) );
}
, PHP_INT_MAX );
We could also override these two pluggable functions, but I don't use that here.