[wp-hackers] Addition to check_comment(): return false if the post is older than 21 days

David House dave at xmouse.ithium.net
Fri Oct 1 18:03:38 UTC 2004


I have implemented on my weblog a really simple check to block comments on old
posts -- one of the best anti-spam methods. It lives in wp-comments.php and
sets a variable which I check before echoing the comment form. It looks like
this:

$commentsblocked = (floor((time() - strtotime($post->post_date)) / (60*60*24)) >
 21);

...which means 'set $commentsblocked to the result of the following test: is the
current time in seconds minus the time the entry was posted (the time since the
entry was posted) divided by the number of seconds in a day, all rounded down,
greater than 21?'. In other words, 'have there been 21 days since this entry
was posted?'.

Adding this to check_comment() (possibly under a statement like
if(get_settings('use_auto_comment_shutoff'))) would cut out a lot of spam. For
maximum effects I suggest we check it before outputting the comment form.

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




More information about the hackers mailing list