Disable Admin account being emailed for comment notification

I am using the code below to send Comment notification and moderation emails to multiple email addresses for a client site.

I have a custom admin panel for this particular site. In my admin panel I have a field that holds a comma separated list of emails that should be notified anytime a comment is posted and needs approval or notified.

Read More

It works great however my client has 1 issue. As my client is also the Admin of the site, they are receiving a comment notification email to the email address that is under there account settings. So in addition to emailing my comma separated list of emails, it also em,ails the Admin account email.

I am looking for help on how I can disable it emailing the Admin account and ONLY sending an email to the emails in my custom setting which this code below is doing already.

Any ideas on how to do this please?

/**
 * 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 = 'jason.davis@gmail.com,David@email.com,Tracey@custom.com';
    //$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 ) . "rn";
        $notify_message .= get_permalink($comment->comment_post_ID) . "rnrn";
        $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "rn";
        $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "rn";
        //$notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "rn";
        $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "rn";
        $notify_message .= __('Comment: ') . "rn" . $comment->comment_content . "rnrn";
        $notify_message .= sprintf( __('Approve it: %s'),  $blogurl."/wp-admin/comment.php?action=mac&c=$comment_id" ) . "rn";
        $notify_message .= sprintf( __('Delete it: %s'), $blogurl."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "rn";
        $notify_message .= sprintf( __('Spam it: %s'), $blogurl."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "rn";
        $notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "rn";
        $notify_message .= get_option('siteurl') . "/wp-admin/moderation.phprn";
        $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 ) . "rn";
            $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "rn";
            $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "rn";
            $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "rn";
            $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "rn";
            $notify_message .= __('Comment: ') . "rn" . $comment->comment_content . "rnrn";
            $notify_message .= __('You can see all comments on this post here: ') . "rn";
            $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
            $notify_message .= get_permalink($comment->comment_post_ID) . "#commentsrnrn";
            $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "rn";
            $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "rn";
            $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.0n"
                . "$fromn"
                . "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;
}

Related posts

1 comment

  1. In the WordPress backend at Settings->Discussion there is a setting near the middle labeled “Email me Whenever”.

    enter image description here

    Uncheck those two boxes. I believe that will prevent the system from sending those email, leaving only the emails that you send.

Comments are closed.