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.

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 )
add_action('comment_post', 'cc_comment_post');


No support will be offered. No warranty will be honored. No fool will be suffered.

10 thoughts on “Minimalist Plugin: Cap Comments”

  1. Pingback: at
  2. 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!

Comments are closed.