There has been quite a bit of talk about preventing weblog comment spam lately. Jeremy Zawodny and David Sifry have each come up with similar solutions for automatically turning off comments on older posts. While both of these solutions work perfectly well, I wanted something that was a bit more integrated with MT. I wanted MT to handle the updates to the older entries.
So today it dawned on me that Brad Choate’s MTSQL plugin was exactly what I needed to make this happen. Since the plugin allows the execution of arbitrary SQL statements, I can now make a template that will shut down comments and pings on my older posts.
Once you have MTSQL installed, create an index template with contents similar to the following:
set entry_allow_comments = 2,
entry_allow_pings = 0
where entry_created_on <= date_sub(CURDATE(), interval 7 day)
and entry_blog_id = 2
Be sure to check the box next to “Rebuild this template automatically when rebuilding index templates”. With this option enabled, this query will be executed each time you save an entry.
I prefer this method to the previously mentioned methods because I feel it is more inline with the way MT works. Nothing happens unless it is in response to my actions. The other solutions require a cron job to work automatically. I have no problems with cron—I just prefer this integrated approach.
One problem that remains unsolved by Jeremy’s, David’s, or my solution is that closed entries will still show their comment forms. The presence of the comment form does not allow comments, but it is misleading. A user might type in a long rant only to be disappointed by a mesage stating that comments for the entry are closed once he clicks the Post button.
An entry must be rebuilt before the comment form will be removed from its page. There are a couple of ways to make this happen. One option is to simply rebuild your entire blog from within MT. Another option is to use Timothy Appnel’s mt-rebuild script to rebuild the blog. This script will rebuild individual pages or the entire blog from the command line. If you’re serious about closing down comments, I’d suggest setting up a cron job to run this script. And if anyone knows of a way to avoid the cron job and just execute a rebuild from within an MT template, I’d love to hear about it.