MDFive is Alive!

Ok, so remember that Cached Spam Blocker I worked on a while ago? Well, I finally moved it away from hacking individual files and ported into a single-file, WordPress plugin.

I present unto you, MDFive Spam Blocker!:

<?php
/*
Plugin Name: MDFive Spam Blocker
Plugin URI: http://prostheticallyhip.com/MDFive
Description: A user-transparent plugin to block comments made by spam-bots from cached versions of your blog.
Author: Will
Version: 0.3
Author URI: http://prostheticallyhip.com/
*/

//edit the line below with your Secret Phrase
$extra = “Edit Secret Phrase here (keep existing double-quotes, and please don’t add more.)”;

// you shouldn’t edit anything below here.

function gen_MDFive() {
  global $extra;
  echo ‘<input type=”hidden” name=”cache” value=”‘.(md5(date(YmdH).$extra)).'” />’;
}

function check_MDFive($approved) {
  global $_POST;
  global $extra;
  if(
    $_POST[‘cache’] == md5(date(YmdH).$extra) ||
    $_POST[‘cache’] == md5(date(‘YmdH’,mktime(date(H)-1, 0, 0, date(m),date(d),date(Y))).$extra)
  ) {
    //good! within the cache window!
  } else {
    $badCount++;
  }
  if($badCount > 0) {
    die(“We don’t allow comment spam here.”);
    return false;
  } else {
    return $approved;
  }
}

add_action(‘comment_form’, ‘gen_MDFive’);
add_action(‘pre_comment_approved’, ‘check_MDFive’);
?>

Leave a comment

Your email address will not be published. Required fields are marked *