Fixing Math Comment Spam Protection Plugin in WordPress 3.0

Filed in Web DevelopmentTags: Math Comment Spam Protection, Plugins, WordPress

Otto has an even better suggestion: use is_user_logged_in(). I have updated the recommended fix accordingly. Thanks, Otto!

As many people have noticed, the Math Comment Spam Protection plugin no longer works in WordPress 3.0. Unfortunately, the plugin appears to be no longer supported by its author, so some people are searching for an alternative plugin.

However, I have some good news: after a bit of trial-and-error, I found the problem with Math Comment Spam Protection. Even better news: the fix is incredibly simple.

Find Line 211 of math-comment-spam-protection.php:

if (  ( !isset($user_ID) ) && ( $comment_data['comment_type'] == '' ) ) { // Do not check if the user is registered & do not check trackbacks/pingbacks

The offending code is this:

( !isset($user_ID ))

Simply change the above to this (note: see update, above):

( ! $user_ID )

( ! is_user_logged_in() )

So that Line 211 looks like the following:

if (  ( ! $user_ID ) && ( $comment_data['comment_type'] == '' ) ) { // Do not check if the user is registered & do not check trackbacks/pingbacks

Voila! The Math Comment Spam Protection plugin will now work again!

This fix is so simple, I don't see any need to fork the code. I'll try to contact the developer, and see if he will patch the original.

Feedback

Comments (Comments are closed)

8 Responses to “Fixing Math Comment Spam Protection Plugin in WordPress 3.0”
  1. chip_bennett says:

    Fixing Math Comment Spam Protection Plugin in WordPress 3.0 – http://www.chipbennett.net/2010/06/fixin… #wordpress

  2. Anonymous says:

    thx for ur share 🙂

  3. Thank you — very helpful!

  4. uwalter says:

    Hi together,

    thank you very much for the $user_ID fix. I found another issue for fresh wp3.0 installs and have a fix for it to share.

    The new version doesn’t use Kubrick as standard template anymore, the new one is TwentyTen. And there is a new function comment_form() that renders the comment form, found in ~/wp-includes/comment-template.php – line 1484.

    Search for the end of the $fields array definition and add the following lines, which formerly were added to the theme’s file comment.php.


    /**
    * uwalter: v3.0 fix for the Math Comment Spam Protection plugin.
    */
    if (function_exists('math_comment_spam_protection'))
    {
    $mcsp_info = math_comment_spam_protection();
    $fields['mcspvalue'] =
    'Spam Schutz: Berechne die Summe aus '.$mcsp_info['operand1'].' + '.$mcsp_info['operand2'].'.'.
    ''.
    '';
    } # END v3.0 fix

    Have a Lot of Fun

    Best Regards
    Uwe Walter

  5. Chip Bennett says:

    @uwalter:

    I recommend strongly against modifying core files. Instead, hook in the Math Comment Spam Protection content. I recommend using the comment_form_after_fields filter. Something like this:

    // Add Math Comment Spam Protection to the comment form, using the comment_form_after_fields hook.
    // http://ottopress.com/2010/wordpress-3-0-theme-tip-the-comment-form/
    function cbnet_math_comment_spam_protection() {
    if ( function_exists(‘math_comment_spam_protection’) ) {
    $mcsp_info = math_comment_spam_protection(); ?>
    <p class=”comment-form-captcha”>
    <label for=”mcspvalue”>
    Add <?php echo $mcsp_info[‘operand1’] . ‘<span style=”font-weight:bold;font-size:9pt;”>+</span>’ . $mcsp_info[‘operand2’] . ‘?’; ?>
    </label>
    <input type=”text” name=”mcspvalue” id=”mcspvalue” value=”” size=”5″ tabindex=”4″ />
    <input type=”hidden” name=”mcspinfo” value=”<?php echo $mcsp_info[‘result’]; ?>” />
    </p>
    <?php }
    }
    add_action( ‘comment_form_after_fields’ , ‘cbnet_math_comment_spam_protection’ );

  6. uwalter says:

    Hi Chip,

    I am no friend of modifying core files too. Thank you very much for the new tip! Will directly check that.

    My first wordpress blog btw. 🙂

    Best Regards
    Uwe Walter

  7. Bob Peers says:

    Thanks for that, I was confused by the sudden flood of spam!

  8. Bob Peers says:

    Thanks for that, saved me from a flood of spam!