谈到 WordPress 的垃圾评论,我已经无语了。下面给出一个 WordPress 评论数学验证的简单实现方法。希望能够解决由垃圾评论给你带来的烦恼。
1. 编辑 WordPress 安装目录的 wp-comments-post.php 文件,修改下面列出的两处:
$comment_author = ( isset($_POST['author']) ) ? trim(strip_tags($_POST['author'])) : null;
$comment_author_email = ( isset($_POST['email']) ) ? trim($_POST['email']) : null;
$comment_author_url = ( isset($_POST['url']) ) ? trim($_POST['url']) : null;
$comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
// 在其后加入如下代码
/* Comment Math Checker
* Heihaier - [email protected]
*/
$comment_numa = (isset($_POST['numa'])) ? trim($_POST['numa']) : null;
$comment_numb = (isset($_POST['numb'])) ? trim($_POST['numb']) : null;
$comment_sumab = (isset($_POST['sumab'])) ? trim($_POST['sumab']) : null;
if ( get_option('require_name_email') && !$user->ID ) {
if ( 6 > strlen($comment_author_email) || '' == $comment_author )
wp_die( __('Error: please fill the required fields (name, email).') );
elseif ( !is_email($comment_author_email))
wp_die( __('Error: please enter a valid email address.') );
}
// 在其后加入如下代码
/* Comment Math Checker
* Heihaier - [email protected]
*/
if(!$user->ID) // guest user only
{
if((($comment_numa + $comment_numb) != $comment_sumab) || empty($comment_sumab))
wp_die(__('Error: please type the correct results of the math problems.'));
}
2. 编辑当前主题程序的 comments.php 文件,例如我使用 inove 主题就是 wp-content/themes/inove/comments.php
Over!
Oh my f***ing GOD
简单数学题评论验证插件 for WP 通过 HTTP 协议下载 Git 版本仓库出错