php - Issues adding Recaptcha v3 to Wordpress Registration

I'm having a problem with adding Recaptcha v3 to my WP registration form.The recaptcha seems to be registered and w

I'm having a problem with adding Recaptcha v3 to my WP registration form.

The recaptcha seems to be registered and working and communicating with Google's api. I'm running into problems when I try to fire a PHP function that checks the Recaptcha score which hooks into 'registration_errors'. See the code below:

function verify_recaptcha_on_register($errors, $sanitized_user_login, $user_email) {
$recaptcha_url = '';
$recaptcha_secret = 'SECRET KEY';
$recaptcha_response = $_POST['recaptcha_response'];

// Make and decode POST request:
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
$recaptcha = json_decode($recaptcha);
$score = $recaptcha->score;
// Take action based on the score returned:
if ($recaptcha->score > 0.5) {
    // Verified - 

    return $errors;    

} else {
    // Not verified - show form error
    return new WP_Error( 'Captcha Invalid', __('<strong>ERROR</strong>: You are a bot') );
}
}
add_filter('registration_errors', 'verify_recaptcha_on_register', 10, 2);

The $_POST['recaptcha_response'] gets its value from a hidden input field in the registration form, which gets a token value from the Recaptcha script (I've checked, and this part works).

When I submit the form, I'm getting the following result: "The site is experiencing technical difficulties. Please check your site admin email inbox for instructions."

I'm not sure if I have a minor mistake or this is actually entirely the wrong way to go about this. Any help would be appreciated.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745216834a4617063.html

相关推荐

  • php - Issues adding Recaptcha v3 to Wordpress Registration

    I'm having a problem with adding Recaptcha v3 to my WP registration form.The recaptcha seems to be registered and w

    4小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信