WordPress comments This piece, some people are sad, sad is frequent advertising good annoying, hi a variety of restrictions on the operation has made the comments very quiet, such as uncle, Haha, a few days ago, said the breast of the site comments XSS bug ... I hurried to say, to try my, he told me, "No, you have too many restrictions," then what is black technology to make comments how reassuring? Please come into the "WordPress Spam Review of the new tactics," but, today, is WordPress commented on the word limit, so more stringent norms of the reviewer's behavior!
So directly on today's black tech bar, insert the following code into the functions.php of the subject,
WordPress Default Comment Mode:
/* Set Comment word limit start * *
function Set_comments_length ($commentdata) {
$minCommentlength = 3; Minimum word limit
$maxCommentlength = 1000; Maximum word limit
$pointCommentlength = Mb_strlen ($commentdata [' comment_content '], ' UTF8 '); Mb_strlen 1 Chinese characters as 1 lengths
if ($pointCommentlength < $minCommentlength) {
Header ("content-type:text/html; Charset=utf-8 ");
Wp_die (' Sorry, your comments are too few words, please enter at least '. $minCommentlength. ' Words (current words: '. $pointCommentlength. ' Word) ');
Exit
}
if ($pointCommentlength > $maxCommentlength) {
Header ("content-type:text/html; Charset=utf-8 ");
Wp_die (' Sorry, your comments are too many words, please less than '. $maxCommentlength. ' Words (current words: '. $pointCommentlength. ' Word) ');
Exit
}
return $commentdata;
}
Add_filter (' preprocess_comment ', ' set_comments_length ');
/* Set Comment word limit end * *
Ajax Comment Way:
/* Set Comment word limit start * *
function Set_comments_length ($commentdata) {
$minCommentlength = 3; Minimum word limit
$maxCommentlength = 1000; Maximum word limit
$pointCommentlength = Mb_strlen ($commentdata [' comment_content '], ' UTF8 '); Mb_strlen 1 Chinese characters as 1 lengths
if ($pointCommentlength < $minCommentlength) {
Err (' Sorry, your comments are too few words, please enter at least '. $minCommentlength. ') Words (current words: '. $pointCommentlength. ' Word) ');
Exit
}
if ($pointCommentlength > $maxCommentlength) {
Err (' Sorry, your comments are too many words, please less than '. $maxCommentlength. ' Words (current words: '. $pointCommentlength. ' Word) ');
Exit
}
return $commentdata;
}
Add_filter (' preprocess_comment ', ' set_comments_length ');
/* Set Comment word limit end * *
Distinguish your own way of commenting, and then create it, SAO years!
The following Web site also collates some examples
First put the following code into the current theme of the functions.php, pay attention to modify the minimum number of words:
Function Bing_minimal_comment_length ($commentdata) {
$minlength = 20;//comments least words
preg_match_ All ('/./u ', trim ($commentdata [' comment_content ']), $maxlength);
$maxlength = count ($maxlength [0]);
if ($maxlength < $minlength) Wp_die (' comments are minimal needed '. $minlength. Word ' );
return $commentdata;
}
Add_filter (' preprocess_comment ', ' bing_minimal_comment_length ', 8);
This code also supports the number of words in Chinese Oh!