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

1
2
3
4
5
6
7
8
9
10
11
/**
    *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 );
原文链接:https://xiaohost.com/1460.html,转载请注明出处。
0

评论0

请先