Minimalist Plugin: Cap Comments

By Andy

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.

10 Responses to “Minimalist Plugin: Cap Comments”

  1. Matt Says:

    You should put this on wp-plugins.org.

  2. Andy Says:

    Done:

    http://dev.wp-plugins.org/browser/cap-comments

  3. The Private intellectual » The Bandwagon. Says:

    [...] 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. [...]

  4. Ajay D'Souza Says:

    Nice quick plugin Andy. Thanks for sharing :)

  5. Jonathan Dingman Says:

    whoa, that’s pretty sweet! Good idea, this will come in handy :)

  6. Javier Says:

    Cool plugin!

  7. Torley Linden Says:

    That was speedy!

    Nice work Andy, I gotta see this in action. :D

    Thanx a lot again.

  8. Limit the number of comments added to a specific post in WordPress » Webmasters? Let's talk! Says:

    [...] 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: [...]

  9. at Noowz.com Says:

    [...] Andy Skelton: Minimalist Plugin: Cap Comments [...]

  10. parrott Says:

    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!

Leave a Reply