Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OscarAbadFolgueira/a49a0321b32a379d0a8c to your computer and use it in GitHub Desktop.
Save OscarAbadFolgueira/a49a0321b32a379d0a8c to your computer and use it in GitHub Desktop.
WordPress Snippet to set the minimum length for comments
<?php
/**
* This WordPress / Woocommerce code snippet set the minimum length for comments.
*
* Author: Oscar Abad Folgueira
* Author URI: http://www.oscarabadfolgueira.com
*
* You can copy this snippet and paste in your functions.php or you can build your own plugin
*
* Change the number of characters to your needs.
*/
add_filter( 'preprocess_comment', 'set_minimal_length_for_comments' );
function set_minimal_length_for_comments( $comment ) {
$min_length = 15;
if ( strlen( $comment['comment_content'] ) < $min_length ){
wp_die( 'Los comentarios deben ser por lo menos de ' . $min_length . ' caracteres.' );
}
return $comment;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment