0

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.

2
  • 1
    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. – Timothy Jacobs Oct 1 '19 at 1:26
  • This works! Thank You. Note: if you please copy your comment and paste as an answer, I will choose it as the answer. – Shah Alom Oct 1 '19 at 19:11
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.