<?php
/*
Plugin Name: Auto-Close Comments
Version: 0.2
Plugin URI: http://codex.wordpress.org/Plugins/Auto_shutoff_comments
Description: Autoclose comments after 21 days.
Author: Scott Hanson
Author URI: http://www.papascott.de/
*/
/* Add an index on comment_status to wp_posts to speed this up. */
function autoclose_comments() {
global $wpdb, $tableposts;
if (!isset($tableposts))
$tableposts = $wpdb->posts;
// Set $age to the age at which a post should become stale
$age = '120 DAY';
$date = $wpdb->get_var("
SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $age), INTERVAL 1 DAY)
");
$wpdb->query("
UPDATE $tableposts
SET comment_status = 'open', ping_status = 'open'
WHERE (comment_status = 'close' OR ping_status = 'close')
AND post_status = 'publish'
AND post_date < '$date'
");
}
add_action('publish_post', 'autoclose_comments', 7);
add_action('edit_post', 'autoclose_comments', 7);
add_action('delete_post', 'autoclose_comments', 7);
add_action('comment_post', 'autoclose_comments', 7);
add_action('trackback_post', 'autoclose_comments', 7);
add_action('pingback_post', 'autoclose_comments', 7);
add_action('edit_comment', 'autoclose_comments', 7);
add_action('delete_comment', 'autoclose_comments', 7);
add_action('template_save', 'autoclose_comments', 7);
?>
A plugin called Comment Timeout will do just that.
http://jamesmckay.net/code/comment-timeout