WordPress评论字数限制

将下面代码粘贴到functions.php,位置嘛找个空位置就行。

//评论字数限制
function Paopao_comment_length( $commentdata ) {
$minCommentlength = 2; //最少输入2个字,根据自己需要修改
$maxCommentlength = 10000; //最多输入10000个字,根据自己需要修改
$pointCommentlength = mb_strlen($commentdata['comment_content'],'UTF8'); //mb_strlen 1个中文字符当作1个长度
if ( $pointCommentlength < $minCommentlength )
{ //使用comments-ajax.php的请用err输出,没有的请用wp_die输出
err( __('抱歉,您的评论太短了,请至少输入' . $minCommentlength .'个字(已输入'. $pointCommentlength .'个字)') );
//wp_die('抱歉,您的评论太短了,请至少输入' . $minCommentlength .'个字(已输入'. $pointCommentlength .'个字)');
}
if ( $pointCommentlength > $maxCommentlength )
{
err( __('抱歉,您的评论太长了,请不要超过' . $maxCommentlength .'个字(已输入'. $pointCommentlength .'个字)') );
//wp_die('抱歉,您的评论太长了,请不要超过' . $maxCommentlength .'个字(已输入'. $pointCommentlength .'个字)');
}
return $commentdata;
}
add_filter( 'preprocess_comment', 'Paopao_comment_length' );

原文地址:
http://www.yuxiaoxi.com/2013-06-24-word-limit.html

This entry was posted in Technology and tagged , , . Bookmark the permalink. 1,763 views

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>