Skip to content

Instantly share code, notes, and snippets.

@wpspeak
Created June 13, 2013 01:56
Show Gist options
  • Save wpspeak/5770706 to your computer and use it in GitHub Desktop.
Save wpspeak/5770706 to your computer and use it in GitHub Desktop.
Set minimal character limit before comments being accepted
<?php
/*
* Set minimal character limit before comments being accepted
* @url: http://www.paulund.co.uk/set-minimal-comment-limit-in-wordpress
* /
add_filter( 'preprocess_comment', 'minimal_comment_length' );
function minimal_comment_length( $commentdata ) {
$minimalCommentLength = 20;
if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength )
{
wp_die( 'All comments must be at least ' . $minimalCommentLength . ' characters long.' );
}
return $commentdata;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment