WordPress 评论数学验证的简单实现

谈到 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 - admin@heiher.info 
 */
$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 - admin@heiher.info 
 */
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.'));
}

Continue reading WordPress 评论数学验证的简单实现