Is there any hook to validate google recaptcha dislayed in wp-signup page [in Wordpress Multisite]

wordpress.stackexchange https://wordpress.stackexchange.com/questions/349736

  •  17-04-2021
  •  | 
  •  

First time working on a directory base WordPress multi-site. I need to add google ReCaptcha in the wp-signup.php page.

I just look at the wp-signup.php file and found do_action( 'signup_extra_fields', $errors ); in the show_user_form function to display a google ReCaptcha in the wp-signup.php page. Here is the code how I added the google ReCaptcha box in the registration form ...

function mcqacnet_example_callback( $errors ) {
    printf( '<div class="g-recaptcha" data-sitekey="%s"></div>', 'my-secret-key' );
}

add_action( 'signup_extra_fields', 'mcqacnet_example_callback', 99);

function mcqacnet_captcha_js_in_footer() {
    echo '<script src="https://www.google.com/recaptcha/api.js" async defer></script>';
}

add_action( 'wp_print_footer_scripts', 'mcqacnet_captcha_js_in_footer' );

Now its time to validate the captcha when a user submits registration form. I looked at the wpmu_signup_user function but no hook define to use.

Please let me know if you have any idea to verify reCaptcha before registration.

Thank you for your time.

有帮助吗?

解决方案

The wpmu_validate_user_signup hook might help. Though you'd have to be careful to only apply the reCAPTCHA validation when necessary. For instance, it shouldn't be checked during a REST API request for creating a user.

许可以下: CC-BY-SA归因
scroll top