为WP添加简单注册验证
为了防止恶意注册, 我们需要注册用户回答简单的问题。例如下面的例子中, 我们要求用户回答本站名称。
直接将下列代码放到你的functions.php
//add verification on register page
function register_code(){ ?>
<p>
<label for="vercode"><?php _e("请输入本站名称: <strong>VanRaspi</strong>", "userfun"); ?><br />
<input id="vercode" class="input" size="25" type="text" name="vercode" /></label>
</p>
<?php
}
//add validation
function register_code_validate($sanitized_user_login, $user_email, $errors){
$vercode=$_POST['vercode'];
//haven't input
if (!isset($vercode) || $vercode==''){
return $errors->add('vercode_error', __("<strong>错误 : </strong>请输入本站名称!","userfun"));
}elseif(strtolower($vercode)!='vanraspi'){
//if the question is not right
return $errors->add('vercode_fail', __("<strong>错误 : </strong>你输入的站点名不正确!", "userfun"));
}
}
add_action('register_form', 'register_code');
add_action('register_post', 'register_code_validate', 10, 3);
参考链接
本作品采用创作共用版权协议, 要求署名、非商业用途和保持一致. 转载本站内容必须也遵循署名-非商业用途-保持一致的创作共用协议.

发表回复