Automatically disable comments after a given timeframe

(Submitted Thu, 2009-07-30 20:37)

Here's a quickie. Automatically disable comments on posts older than a given timeframe. I find that comments on posts older than a few months are generally spam.

Plug this into your site's custom module. As usual, I am using the convention of 'mymodule' for the namespace, and you'll want to replace this with the name of your actual module.

<?php
function mymodule_cron() {
 
$time_ago = strtotime("-4 month");
 
$result = db_query("UPDATE {node} SET comment=1 WHERE created < %d AND type='story' AND comment=2", $time_ago);
}
?>

Exercises for the reader: you could also make a settings page to make the "time ago" configurable (currently I have mine hard-coded to 4 months) and the node types to which it applies configurable (currently I have mine hard-coded to 'story' nodes). Also, this probably doesn't need to run every cron run, so it wouldn't hurt to make that configurable too.

Submitted by Richard (not verified) on Thu, 2009-07-30 23:43.

There's also the Comment Closer module which has the features you describe. Hope that doesn't constitute cheating on the reader exercise!

Submitted by Catherine Ellis (not verified) on Sat, 2009-10-31 23:39.

Thought I'd give the comment closer a go but its locking topics in my forum even though I have "forum" unselected in my comment closer settings. Anyone else get this?

Submitted by drawk on Fri, 2009-07-31 00:23.

That's perfect - thanks for the head's up Richard. I'd done a quick search but hadn't come up with anything. Contrib is becoming unwieldy!

Submitted by Hurtig lån (not verified) on Mon, 2009-08-03 22:26.

I am, in some point, still getting comments from entries posted a few months back. This could be helpful. Thank you for this contribution.

Submitted by Daniela Barillas (not verified) on Tue, 2009-08-18 20:37.

Thanks for the information, the information is really nice and easy to work with, then nice article.

Submitted by eliminar acne (not verified) on Mon, 2009-08-24 17:23.

that's perfect, the information you give on the post it is very useful for me, and i'm sure for many people too. keep working like this, i love your work on this blog!

Submitted by Angeline @ marcus evans scam (not verified) on Tue, 2009-09-08 09:27.

This seems to be a good idea rather than getting huge number of comments for older posts... :)
Angeline @ marcus evans scam

Submitted by Stefan (not verified) on Tue, 2009-09-08 13:30.

My problem just solved after 1 hour of searching for solution. The re-adjustable codes are easy to work with and understandable. Good programming skills, Bravo.

Submitted by Martha (not verified) on Wed, 2009-09-09 07:59.

This is such an informative and useful post for drupal users. Keep updating and thanks for the heads up.

Submitted by ryan on Sat, 2009-09-19 14:49.

Awesome!

Yeah you're probably right that older comments are hard to find and may need to be digged a lot before one can reach it, so they're prone to more spam than legitimate comments. I've also seen such plugins on WordPress blogs although very few ones feature this on it and it's nice to see it on drupal too. And also install a good spam-filter and CAPTCHA system.
Regards

Ryan Mathys (Pacific Beach real estate)

Submitted by Annie (not verified) on Thu, 2009-10-15 00:44.

Agreed. Very insightful post. It saves me having to find out the hard way!

search for magician sites

Submitted by Arturo66 (not verified) on Wed, 2009-10-21 15:21.

I consider myself to be a promoted internet user and can say that your resurce is one of not many I like to come back again and again. I just hope that someone finds my search engine on rapidshare files that useful too

Submitted by Jewelry Wholesalers (not verified) on Sat, 2009-10-31 16:38.

Nifty! and very simple too. Thanks for sharing.

Submitted by interior design seattle (not verified) on Sun, 2009-11-01 19:14.

So cool and simple, gonna give it a try! Thanks!

Submitted by Bamboo wood flooring (not verified) on Sun, 2009-11-15 02:28.

Thank you! Ive been looking for this solution for weeks now and havent been able to find it. Its too difficult to keep track of comments on old posts, so much easier to just turn them off.

Submitted by Check Backlink (not verified) on Mon, 2009-11-16 03:08.

Now that's a really neat idea. I know this is a stupid question but is there a similar script for wordpress? Thanks

Submitted by Sydney Interior Design Firm (not verified) on Sun, 2009-11-22 09:21.

I think you can use Extended Comment Options plugin of Wordpress. But I also like to see comments even on my older posts.

Get a free quote from us for Fitouts

Submitted by Kroatien Urlaub (not verified) on Thu, 2009-11-26 22:30.

Thanks for the helpful information

Submitted by Makarska (not verified) on Fri, 2009-11-27 16:26.

I like that in Drupal, for example, the user can create their own weblogs and exchange ideas in forums.

Submitted by Urlaubstips (not verified) on Thu, 2009-12-03 13:43.

what would drupal do...never heard, but i like that! drupal is a pretty good system, ay. just kind of sad, its not used that often..

Submitted by wholesale cat supplies (not verified) on Sat, 2009-11-28 20:21.

Thanks for the helpful information

Submitted by Desi Masala (not verified) on Wed, 2009-12-02 11:03.
Submitted by sell my gold (not verified) on Fri, 2009-12-04 21:35.

very useful, does get annoyin whe older blogs just collect pages and pages of comments

Submitted by vancouver bootcamp (not verified) on Sat, 2009-12-05 09:48.

i thought that this information was useful, but maybe its just me, but i have a hard time trying to understand, nevertheless, i thank you for the information...boot camp vancouver

Submitted by Boot Camp Vancouver (not verified) on Thu, 2009-12-10 15:27.

I think that this is a great idea, i always have problems on my site and i think that this really helps because this gives me more control over my content.

Submitted by Application Performance Management Software (not verified) on Mon, 2009-12-14 19:36.

Excellent article, thanks for sharing the information.

Submitted by Anonymous (not verified) on Mon, 2009-12-14 23:05.

very useful!

Submitted by Pam (not verified) on Wed, 2009-12-16 22:39.

I found this module very useful and very easy to install. I checked out the comment closer to recommended by Richard, I dont have a forum on my site so I haven't ran into any problems at all using them.
Thanks for this :)

Submitted by investment policy statement (not verified) on Sat, 2009-12-19 17:26.

This module is indeed helpful and user-friendly! I hope to have the same software available.

Submitted by Trogir (not verified) on Sun, 2009-12-20 17:22.

Thanks for the helpful information

Submitted by Anonymous (not verified) on Thu, 2009-12-24 08:32.

That's nice it would be helpful to everyone.Thanks for your contribution

Submitted by hdmi (not verified) on Thu, 2009-12-24 14:29.

No more post?

Submitted by doguhaber (not verified) on Sat, 2009-12-26 18:43.

good article... Thanks, :)

Submitted by Paul Jacobs (not verified) on Mon, 2009-12-28 00:57.

I found this module very easy to install, thanks for sharing!

Submitted by Macken (not verified) on Mon, 2009-12-28 08:50.

That's a good coding,but please reply about my query.If I want to make changes of time period for weeks or days instead of months,then can I replace "$time_ago = strtotime("-4 month");" by "$time_ago = strtotime("-2 weeks");".Thanks in advance.

Macken,
stair climbing hand trucks

Submitted by Anonymous (not verified) on Mon, 2009-12-28 09:12.

A very useful information for keeping the blog pages up to date.

Submitted by Croatia Holiday (not verified) on Tue, 2009-12-29 12:20.

I wish a Happy New Year 2010

Submitted by whatdoesitwant (not verified) on Tue, 2009-12-29 21:39.

I found your site through the bookmarklet article (which is filled with spam in the comment section). With regard to that I want to mention a trick to discourage spammers and robots even further:
I create a copy of an inputformat with the same configuration as my default input format, but instead at the html-configuration under filter configuration for the new input format i activate the spam deterrent which adds nofollow tags to links. I use the better formats module to add this new input format to my comments only for the relevant content types. This way links will not activate counters. Doing this may hurt your own rankings though, if you depend on comment links for your own ranking so check your analyzers.

Cheers, Willem

Hosted By Dreamhost.com