防止垃圾评论信息,比如纯字母,纯数字等无意义的评论!
修改内容
被修改文件目录位置:
/wp-content/themes/zibll/action/comment.php
搜索内容合规性判断
将代码填在上方
//拦截评论规则
$comment = $_POST['comment'];
$error_msg = '';
if (preg_match('/^[0-9]+$/u', $comment)) {
$error_msg = '您的评论不能完全由数字组成';
} elseif (preg_match('/^[a-zA-Z]+$/u', $comment)) {
$error_msg = '您的评论不能完全由英文字母组成';
} elseif (!preg_match('/[一-龥0-9a-zA-Z]/u', $comment)) {
$error_msg = '您的评论必须包含汉字、数字或英文字母';
} elseif (preg_match('/(.)\\1{2}/u', $comment)) {
$error_msg = '您的评论不能包含连续出现3次及以上的相同字符';
} elseif (preg_match('/[ぁ-ん]+|[ァ-ヴ]+/u', $comment)) {
$error_msg = '您的评论不能包含日文';
}
if ($error_msg) {
echo json_encode([
'error' => 1,
'ys' => 'danger',
'msg' => $error_msg,
]);
exit();
}
© 版权声明
分享是一种美德,转载请保留原链接
THE END
暂无评论内容