无插件实现限制WordPress评论最小字数

  • A+
所属分类:Wordpress
/**
    *WordPress 限制评论最小字数
*/
function Bing_minimal_comment_length( $commentdata ){
    $minlength = 20;//评论最少字数
    preg_match_all( '/./u', trim( $commentdata['comment_content'] ), $maxlength );
    $maxlength = count( $maxlength[0] );
    if( $maxlength < $minlength ) wp_die( '评论最少需要 ' . $minlength . ' 字!' );
    return $commentdata;
}
add_filter( 'preprocess_comment', 'Bing_minimal_comment_length', 8 );

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: