WordPress评论必须中文+禁止外链方法

释放双眼,带上耳机,听听看~!

必须包含中文

防止灌水,判断评论内容是否包含中文,不能包含其他语言文字。

// 评论必须含中文
function wp_refused_spam_comments($comment_data) {
$pattern = '/[一-龥]/u';
$jpattern = '/[ぁ-ん]+|[ァ-ヴ]+/u';
if (!preg_match($pattern, $comment_data['comment_content'])) {
err(__('评论中需要有一个汉字!'));
}
if (preg_match($jpattern, $comment_data['comment_content'])) {
err(__('不能有日文!'));
}
return ($comment_data);
}
add_filter('preprocess_comment', 'wp_refused_spam_comments');

禁止带外链

防止发外链的评论,自然就断绝了很多想灌水发推广的人的脚步。

//禁止发链接
function wp_comment_post( $incoming_comment ) {
$http = '/[href="|rel="nofollow"|http:\/\/|<\/a>]/u';
if(preg_match($http, $incoming_comment['comment_content'])) {
err( "禁止发链接地址!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'wp_comment_post');

使用方法

把以上两段代码添加到当前主题模板的functions.php文件中就可以了。

如何你觉得修改functions.php文件太麻烦,推荐你使用Code Snippets插件来代替

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
七七八八

phpts免费PHP开发环境集成一键端工具

2024-4-18 5:08:25

七七八八

wordpress怎么换域名?

2024-4-19 16:25:59

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索