WordPress Comment HoneyPot

Thanks to Tim Whitlock I’ve been able to modify his code and turn it into a comment honeypot plugin, catching and stopping any comment that includes a url in the comment url field. For this to be effective you will also need to hide the url field so only bots will try and fill it in, otherwise you’ll catch your visitors too if they try and include a web address.

Save this in a folder called comment-honeypot in wp-admin/plugins/ as comment-honeypot.php:

Plugin Name: Comment HoneyPot
Description: Disallows any comments from users who add a url to the invisible webpage form field
Author: Tim Whitlock - Mods by Ed Cooper
Author URI: http://timwhitlock.info/
Version: 0.1
function _tw_intercept_comment( array $data ){
  if( empty($data['comment_author_url']) ){
    return $data;
  } else {
    $message = 'Sorry, we capture spammers who add a web address to the comment form as it\'s hidden. Try writing your comment again without including a web address this time.

If this is an error please let us know at <a href="http://yoursupportsite.com" target="_blank">Your Support Website</a>

<a style="cursor:pointer"><strong>Go Back</strong></a>
    $title = 'Spam Block';
    $args = array('response' => 200);
    wp_die( $message, $title, $args );

Also don’t forget to add your comment form url field hiding css to your themes style.css or if you’re on a WordPress Multisite installation try this plugin http://wordpress.org/extend/plugins/sitewide-admin-headerfooter/ and add it to the header of all of your sites/blogs as a css stylesheet.

I contemplated adding the stylesheet to the plugin but didn’t want to burden my sites with extra calls to files on page download; we serve a custom.css via the above plugin to all users on PrimaryBlogger, depends how optimised you want to be!

#commentform #url, #commentform #url +label, .comment-form-url {

Leave a Reply

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