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.
November 29, 2006 at 8:24 pm |
You should put this on wp-plugins.org.
November 29, 2006 at 10:14 pm |
Done:
http://dev.wp-plugins.org/browser/cap-comments
November 29, 2006 at 11:16 pm |
[...] It seems that other people are starting to interest themselves in the question of comments too, and not just comment spam. Andy Skelton, for example, has come up with a Cap Comments code to limit the number of comments added to a specific post. This is not, of course, the same as the plug-in I commented on a couple of days ago, but really designed for weblogs which have way too much real traffic and need to put an end to it eventually, or the writer will never be able to get on with the important things in life. [...]
November 29, 2006 at 11:29 pm |
Nice quick plugin Andy. Thanks for sharing
November 30, 2006 at 12:14 pm |
whoa, that’s pretty sweet! Good idea, this will come in handy
November 30, 2006 at 12:29 pm |
Cool plugin!
November 30, 2006 at 6:38 pm |
That was speedy!
Nice work Andy, I gotta see this in action.
Thanx a lot again.
December 1, 2006 at 11:27 am |
[...] Andy Skelton came up with a Cap Comments code to limit the number of comments added to a specific post. This plugin is very useful for heavy traffic blogs. Here is the code: PLAIN TEXT PHP: [...]
December 5, 2006 at 1:02 pm |
[...] Andy Skelton: Minimalist Plugin: Cap Comments [...]
December 13, 2006 at 5:53 pm |
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!