如何在自定义注册表单中获得简单的验证码验证? 我有简单代码的形式和行:
<?php
$factor1 = rand (1,10);
$factor2 = rand(1,10);
$sum = $factor1 + $factor2;
$wp_session = WP_Session::get_instance( );
$wp_session['favcolor'] = $sum;
?>
<div class="bbp-captcha">
<label for="captcha">Match</label>
<input type="text" name="captcha" value=" <?php echo $factor1; ?> + <?php echo $factor2; ?>" disabled />
</div>
<div class="bbp-respond">
<label for="respond">Result</label>
<input type="number" name="result" required />
</div>
在我的functions.php中,我添加了:
add_filter( 'register_post', 'set_user_register', 10, 3 );
function set_user_register($sanitized_user_login, $user_email, $errors) {
$wp_session = WP_Session::get_instance( ) ;
if ( $_POST['result'] !== $wp_session['favcolor'] ) {
$errors->add( 'not_human', "<strong>ERROR</strong>: Are you bot?" );
}
}
我唯一得到的是error (not_human)
。