这种生态成熟,或者说受众较大的产品,难免惦记的人就多。之前已经增加了很多方法,来弥补 akismet的不足,包括禁止非中文评论,评论长度限制,是否包含中文等等。
虽然拦截了很多垃圾评论,但是还有一些显而易见的垃圾,却还是要进审核或者回收站,这就让人的确不爽。
至于 wp 自带的评论设置,只能说没什么大用,设置了,还是一样要手工删除,这就 tmd 贼恶心。
设置了关键字之后,还是难以直接屏蔽广西的这个屌毛,天天来发币安的广告,之前已经删了无数次,加到禁止评论关键词里面还是继续发。
并且,找到了规律之后,还会带着中文发,这就很 tm 操蛋了。
还有这种来法验证码广告的:
我之所以不加验证码,主要还是觉得这个东西体验太差了。然而为了屏蔽这些傻屌,随之而来的另外一个问题就是需要在 functions.php 中改的次数越来越多了,现在已经变成了下面的样子:
/** * 检查评论内容是否包含禁用词 * @param string $content 评论内容 * @param array $banned_words 禁用词数组 * @return bool 是否包含禁用词 */ function has_banned_word($content, $banned_words) { foreach ($banned_words as $word) { if (stripos($content, $word) !== false) { return true; } } return false; } /* * WordPress控制文章评论最少字数 */ function custom_comment_length( $commentdata ) { $max_length = 1800; // 设置最大字数限制 if ( mb_strlen( $commentdata['comment_content'] ) > $max_length ) { wp_die( '额,你评论的内容太多啦,最多可以输入1800个字,不要再评论区写论文啊!' ,'宝贝,出错了哦 - obaby@mars', array( 'back_link'=>true ) ); } if ( ! is_admin() ) { $comment_content = $commentdata['comment_content']; if ( preg_match( '/[\x{4e00}-\x{9fa5}]/u', $comment_content ) === 0) { //if (strpos($commentdata['comment_author_url'],'http')!==false || strpos($comment_content,'http')!==false){ // wp_die( '不要乱发哦,让姐姐我不开心就不好了嘛!','姐姐我不开心啦! - obaby@mars', array( 'back_link'=>true ) ); //} //if (strpos($commentdata['comment_author_url'],'http')!==false || strpos($comment_content,'http')!==false){ wp_die( '不要乱发哦,让姐姐我不开心就不好了嘛!(评论禁止纯英文字符、数字内容)','姐姐我不开心啦! - obaby@mars', array( 'back_link'=>true ) ); //} } $banned_words = ['binance.info', 'binance.com','xrumersale.site']; if (has_banned_word($comment_content, $banned_words)){ wp_die( '不要乱发哦,让姐姐我不开心就不好了嘛!(你tmd别发广告了ok?你是傻逼吗?!)','姐姐我不开心啦! - obaby@mars', array( 'back_link'=>true ) ); } } return $commentdata; } add_filter( 'preprocess_comment', 'custom_comment_length' );
每次要屏蔽一个傻逼,就要修改一次:banned_words。的确是有些烦人,所以,直接弄了个插件出来,当然还是得感谢 cursor,写了 99% 的代码。哈哈哈。
功能页面:
代码开源地址:
https://github.com/obaby/baby-wp-comment-filter
插件 zip 下载:
https://github.com/obaby/baby-wp-comment-filter/releases/tag/wp
无法访问的,搭配https://ghproxy.link 食用。
3 comments
这个好
不错。
目前我手动删除。
你这回骂反馈,简单粗暴又友好,哈哈