Between showing the top commentators on the sidebar and the contest to win a MacBook Air I have had a lot of experience with fighting comment spam. Also from being a moderator at one of the busiest forums on the internet I have seen many methods people use to jackup their post counts. Many times people just post “I agree” or “please pm me” and I find it extremely annoying.
Forcing people to post longer comments will not help you much with automated spam (I will have tips on that in another post) but it will help you a ton with human spam. The true human spammers who were going to just type “yes” will now type “asdf asdf asdf asdf yes” and now their intent to spam is identified and they can be banned properly. The people who did not intend to spam will simply add a bit more content to their sentence. Thats the hope anyway.
So how to do it? Well I started to poke around the WordPress files looking for something that made sense and I on line 89 of the wp-comments-post.php file I found this:
[php]if ( ” == $comment_content )
wp_die( __(‘Error: please type a comment.’) ); [/php]
Aha! That makes sense. Basically that is saying if the comment is empty then invoke the wp_die function and say “Error:please type a comment”.
While their is no documentation on the WordPress function reference for “wp_die”, just by trying a comment with no content you can conclude pretty much that wp_die means show a custom page with the message we are passing and then stop.
So I added this right after that:
if (strlen($comment_content) <25 )
wp_die( __(‘Error: Your Comment Is Too Short. Please try to say something useful.’) );
What does this do? strlen is a php function that gets the “string length” then it checks to see if it is less than 25 chars. If it is it sends them to the custom wp_die page with the error message of Error: Your Comment Is Too Short. Please try to say something useful.
Now hacking on your WordPress files to accomplish a goal is pretty cool and educational BUT the next time you upgrade your WordPress your changes are going to go bye bye…