Minimalist Plugin: Cap Comments

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 Comments

Filed under Plugins, WordPress

10 Responses to Minimalist Plugin: Cap Comments

  1. You should put this on wp-plugins.org.

  2. Pingback: The Private intellectual » The Bandwagon.

  3. Nice quick plugin Andy. Thanks for sharing :)

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

  5. That was speedy!

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

    Thanx a lot again.

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

  7. Pingback: at Noowz.com

  8. 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s