Cutting down on spam (part XXXVII)

It occurs to me that I very rarely get useful comments on older posts, but I do occasionally (so just turning off comments isn’t the answer). On the other hand, I don’t want to put any road blocks in the way of most commenters. So what I decided to do was add a little bit of extra spam-avoidance to older posts. The Math s Comment Spam Protection plugin for Wordpress is ideal for this, but it adds the question (a simple one, like “Add 3 and 4”) to every post. I didn’t want that, so a tiny bit of hacking. After installing the plugin into WP, I edited my comments.php file in my theme and added this below the existing comment entry boxes:

<?php

# For old posts, display math-comment-spam-protection's "add these
# numbers" question.

if (function_exists('math_comment_spam_protection')) {
    $mcsp_info = math_comment_spam_protection();
  if ((date('U') - get_the_time('U')) > 2592000) { # 30 days ?>
<p><input type="text" name="mcspvalue" id="mcspvalue" value=""
size="22">
<label for="mcspvalue"><small>Spam protection for older posts: Add
together
<?php echo $mcsp_info['operand1'].' and '.$mcsp_info['operand2'].'' ?>
</small></label> <?php
  } else {
    # it's not an old comment, so write the answer ourselves!
    $vv = $mcsp_info['operand1']+$mcsp_info['operand2'];
    echo '<input type="hidden" name="mcspvalue" value="' . $vv . '">';
  } ?>
<input type="hidden" name="mcspinfo"
value="<?php echo $mcsp_info['result']; ?>" />
</p>
<?php
}
?>

Basically, what this does is work out whether a post is over 30 days old, and then if it is display the maths question. Since the plugin assumes it’s on every post, it checks for the answer being correct on every post. So on posts that *aren’t* more than 30 days old, we calculate the answer ourselves and fill it in! Seems to work so far. If I’ve got something wrong and it’s stopping you commenting, please let me know through some non-commenty means :)

More in the discussion (powered by webmentions)

  • (no mentions, yet.)