I whipped this up for a particularly busy blog. If anybody wants to use it or flesh it out with way too many options and UI enhancements, feel free.
<?php
/*
Plugin Name: Cap Comments
Plugin Author: Andy Skelton
Description: Turn off comments at a pre-set comment count
License: GPL
*/
define('CC_COMMENT_LIMIT', 100);
define('CC_CLOSE_COMMENTS', true);
define('CC_CLOSE_PINGS', true);
function cc_comments_off($post) {
if ( $post->comment_status != 'closed' && CC_CLOSE_COMMENTS ) {
$post->comment_status = 'closed';
$update = true;
}
if ( $post->ping_status != 'closed' && CC_CLOSE_PINGS ) {
$post->ping_status = 'closed';
$update = true;
}
if ( $update )
return wp_update_post($post);
}
function cc_comment_post($comment_ID) {
$comment = get_comment($comment_ID);
$post = get_post($comment->comment_post_ID);
if ( $post->comment_count >= CC_COMMENT_LIMIT )
cc_comments_off($post);
}
add_action('comment_post', 'cc_comment_post');
?>
No support will be offered. No warranty will be honored. No fool will be suffered.
You should put this on wp-plugins.org.
Done:
http://dev.wp-plugins.org/browser/cap-comments
Nice quick plugin Andy. Thanks for sharing 🙂
whoa, that’s pretty sweet! Good idea, this will come in handy 🙂
Cool plugin!
That was speedy!
Nice work Andy, I gotta see this in action. 😀
Thanx a lot again.
Awesome! for the longer pages that get rubbish comments for miles this is a dream. Saves processor time also. Thanks – I am off to have a play!