• Comment moderation of common spam words can get tedious at times. Basically I want WordPress to ignore comments with a spam word in, but allow others through. I can do this by modifying wp-comments-post.php by adding
    if ($approved) {
    before
    $wpdb->query("INSERT INTO $tablecomments
    and adding
    }
    after
    $comment_ID = $wpdb->get_var('SELECT last_insert_id()');
    and finally commenting out the lines
    if (!$approved) {
    wp_notify_moderator($comment_ID);
    }

    But I feel this would be better done by using a plugin. But I can’t see how to do that to prevent a comment being inserted into the database. Any ideas?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Basically, any plugin that automatically deletes or puts in moderation a comment does so by changing the comment that has already been in the data base (for a split second).
    Unfortunately with WordPress 1.2, you cannot prevent the “Comment posted” e-mail from going out just by using a plugin. This has been remedied in WordPress 1.3
    Using WordPress 1.3, it would be trivial to make a plugin that deletes comments that are hit by the blacklist. I’m not sure it’s a great idea, unless you really really trust your blacklist, but it could be done.

    Yesterday I got hit with a lot of comment spam and got tired of having to delete each one of them, so I came up with this patch.
    In wp-comments-post.php, add the following code
    $words = array (
    "golimar.com",
    "levitra",
    "tramadol",
    "cialis",
    "fioricet",
    "phentermine",
    "viagra",
    );
    foreach ($words as $word) {
    $word = trim($word);
    $pattern = "#$word#i";
    if (preg_match($pattern,$comment) || preg_match($pattern,$url)) {
    die ("You are not allowed to post comments, spammer.");
    }

    Before the line:
    $wpdb->query("INSERT INTO $tablecomments
    (comment_post_ID, comment_author, comment_author_email, comment_author_url,

    How can I convert this to a plugin?

    P.S. you can change that array as necessary to list any words that only appear in spam, such as domain names.

    you can probably model your plugin after laughinglizard’s three strikes plugin. it’s the only comment spam plugin that i’ve seen to prevent spam comments from hitting the database.

    Thread Starter stevem

    (@stevem)

    Great! Three strikes looks like just the sort of thing I am after. The URL decode function in it is an excellent idea. Will give it a go.

    Three strikes did not work for me. For some reason it changed my comment submit button link to go to fbi.gov. I had to deactivate the plugin. I like the code that was provided above by Mike3k.
    That might be something that I might just go ahead and add.
    Comment spam sucks!

    Thread Starter stevem

    (@stevem)

    It works well for me. The fbi.gov (which you can change in the threestrikes file) should only be triggered when it thinks the comment is spam

    I’ve converted it to a plugin, which can be downloaded here.

    Cool plugin!
    Just a suggestion, would it be possible to integrate the plugin with WP Blacklist such that $spamwords automatically uses the ones already in WP Blacklist (or the ones already specified in WP’s built-in spamword list?) This would save the effort of having to maintain 2-3 spamword blacklists.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Avoiding Comment Moderation’ is closed to new replies.