Stop wordpress from sending out moderation emails

This question was originally posted at stackoverflow: https://stackoverflow.com/questions/11435952/stop-wordpress-from-sending-out-moderation-emails but after a tip from @MaxGherkins I’m posting a modified version here also for help.

I’m having trouble with my wordpress installation sending out emails to the site admin
every time a comment is up for moderation.
This also goes for spam comments which results in the site admin getting alot of junk emails in his inbox.

Every time I google this problem I end up with the answer “Just go to Settings -> Discussion and unclick ‘A comment is held for moderation'” but unfortunately this is not helping me.

So, here are my settings (some of these may be irrelevant):

  1. I’m using wordpress’ built in comment-system. No disqus or facebook comments.
  2. I’ve installed the Akismet-plugin. I did try to disable the plugin, but I still get the emails.
  3. Both “Anyone posts a comment” and “A comment is held for moderation” is NOT checked under “Settings” -> “Discussion” -> “E-mail me whenever” on the sites.
  4. You do not have to be logged in to write a comment
  5. The WP installation is originally a WordPress MU installation, but I’ve upgraded to 3.x so it’s now build into the regular wordpress installation. The installation run many blogs with different domain names and the problem occurs on all blogs AFAIK.
  6. Most of the blogs are using the “Yashfa BRANDED!” theme
  7. Some information from the database:

    All blogs are in the same database, prefixed with wp_X_

    Here are some output from some random blogs:

    mysql> SELECT * FROM wp_1_options WHERE option_name LIKE "%notify";
    +-----------+---------+-------------------+--------------+----------+
    | option_id | blog_id | option_name       | option_value | autoload |
    +-----------+---------+-------------------+--------------+----------+
    |        10 |       0 | comments_notify   |              | yes      | 
    |        32 |       0 | moderation_notify |              | yes      | 
    +-----------+---------+-------------------+--------------+----------+
    2 rows in set (0.01 sec)
    
    mysql> SELECT * FROM wp_50_options WHERE option_name LIKE "%notify";
    +-----------+---------+-------------------+--------------+----------+
    | option_id | blog_id | option_name       | option_value | autoload |
    +-----------+---------+-------------------+--------------+----------+
    |        11 |       0 | comments_notify   |              | yes      | 
    |        31 |       0 | moderation_notify |              | yes      | 
    +-----------+---------+-------------------+--------------+----------+
    2 rows in set (0.00 sec)
    
    mysql> SELECT * FROM wp_100_options WHERE option_name LIKE "%notify";
    +-----------+---------+-------------------+--------------+----------+
    | option_id | blog_id | option_name       | option_value | autoload |
    +-----------+---------+-------------------+--------------+----------+
    |        10 |       0 | comments_notify   |              | yes      | 
    |        30 |       0 | moderation_notify |              | yes      | 
    +-----------+---------+-------------------+--------------+----------+
    2 rows in set (0.00 sec)
    

The moderation email looks like this:


Subject: [SITENAME] Please moderate: “Test spam comments”


Body:

A new comment on the post 78 "Test spam comments" is waiting for your approval

http://url/test-spam-comments/

Author : djqw21208ryfg23 (IP: XXX.XXX.XXX.XXX , XXX.XXX.XXX.XXX)  
E-mail :     [email protected]  
URL    : http://feg239r239f9fg7329rfg322379fg23f3  
Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=XXX.XXX.XXX.XXX


Comment:  
ugly spam comment goes here...


Approve it: http://url/wp-admin/comment.php?action=mac&c=XXXXX  
Delete it: http://url/wp-admin/comment.php?action=cdc&c=XXXXX  
Spam it: http://url/wp-admin/comment.php?action=cdc&dt=spam&c=XXXXX  
Currently 0 comments are waiting for approval.   

Please visit the moderation panel:
http://url/wp-admin/moderation.php

Why do I keep on getting these emails even though I’ve turned off the email-settings under “Settings” -> “Discussion” and it looks right in the database?

I’ve been testing with the blog that belongs to the wp_1_* tables.

1 Answer
1

I can’t offer an explanation as to why this is happening, but I can give you a quick fix to silence it.

The function responsible is wp_notify_moderator, which is a pluggable function. You can copy the contents of the function into your own plugin and modify it to return true in the case of a comment moderation email.

after the line:

$comment = get_comment($comment_id);

add:

if( empty( $comment->comment_type ) ) return true;

This may not be a long-term solution, but it’ll give inboxes a rest until it’s otherwise sorted.

Leave a Comment