Jeff Barr's Blog

Things I Like..

WordPress 1.5 Comment Verification (With Source Code)

This weekend I had enough free time to implement an updated version of my comment verification patch to WordPress. The idea is very simple — anyone who leaves a comment must also enter my first name. This little trick effectively blocks all of the automated comment submission scripts.

verification form

Here’s what you need to do. I am assuming that you know a little tiny bit about HTML here. If your name is not Jeff, you’ll need to adjust the code to suit

First, add another input field to your comments.php file. This file is part of your theme, so I can’t give you an exact pointer to its location. If you are using the WordPress theme editor, you won’t even have to enter a path. Important Note: Because this code is part of your theme, you will have to reapply this patch if you change themes!

Here’s what you need to add. The original code is in black and the new code is in green:

” size=”22″ tabindex=”3″ >






Second, check that the new field is present when the comment is posted. This change is made in file wp-comments-post.php . This file is part of the core WordPress code; you cannot get to it from the theme editor.

Again, here’s what you need to add. The original code is in black and the new code is in green:

$comment_content = trim($_POST[‘comment’]);
$comment_validate = trim($_POST[‘validate’]);

if ($comment_validate != “Jeff”)
die(“You forgot Jeff’s first name. If you are forgetful, hit Back and try again. “);

// If the user is logged in
get_currentuserinfo();

Ok, so there you have it. If you have any problems, please double-check your edits before emailing me (but feel free to do so if you are really stuck). My email provider has been offline for the last 48 hours, and I expect to spend at least 1 week catching up from this outage — as I write this on Saturday evening I am still not able to get to my email.

If you make this work (or don’t) please feel free to post a comment.