[wp-hackers] Auto shutoff comments to be shut off?

Owen Winkler ringmaster at midnightcircus.com
Mon Mar 7 18:01:30 GMT 2005


Carthik Sharma wrote:
> I beleive the auto shutoff comments plugin is evil - no less.
> 
> To quote:
> It's pretty easy to put this into a plugin that runs every time the
> database is changed, so that we don't need a cronjob.

There is no reason that the database needs to change to implement this 
functionality.

My OSA plugin has been turning off commenting on old posts without 
modifying the database at all.  Slightly altered from OSA code:

add_filter('the_posts', 'close_posts');
function close_posts($posts) {
	foreach($posts as $post)
	{
		$recent = 14; //14 days

		$post_time = (int)mysql2date('U', $post->post_date_gmt);
		$time_now = (int)mysql2date('U', current_time('mysql'));
		$time_diff = $time_now - $post_time;
		if(($time_diff > ($recent * 60 * 60 * 24))
		&& ('open' == $post->comment_status)) {
			$post->comment_status = 'closed';
		}
		$posts2[] = $post;
	}
	return $posts2;
}

An additional check when a comment is posted is also used to prevent 
errant comments on old posts from malicious scripts.

Owen



More information about the wp-hackers mailing list