Skip to content

Instantly share code, notes, and snippets.

@VlooMan
Created June 7, 2019 07:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VlooMan/b2f99357c8fd90c91ffc82b0d88003a9 to your computer and use it in GitHub Desktop.
Save VlooMan/b2f99357c8fd90c91ffc82b0d88003a9 to your computer and use it in GitHub Desktop.
No CAPTCHA reCAPTCHA for WooCommerce plugin - Lost password wrong link fix.
<?php
/**
* This piece of code fixes the "No CAPTCHA reCAPTCHA for WooCommerce" plugin's incorrect code when generating
* lost password link. You can copy it to functions.php of your theme or child theme until the plugin developer fixes
* the plugin behavior.
*/
// Add our fixed version only if the original filter is hooked already.
if ( has_filter( 'allow_password_reset', array( 'WC_Ncr_Lost_Password_Captcha', 'validate_lost_password_captcha' ) ) ) {
add_filter( 'allow_password_reset', 'my_theme_prefix_validate_lost_password_captcha', 11 );
}
function my_theme_prefix_validate_lost_password_captcha( $allow ) {
// Only run if password reset form sent and captcha response exists.
if ( isset( $_POST['wc_reset_password'] ) && isset( $_POST['g-recaptcha-response'] ) ) {
// Since we are running the filter with priority 11 it will run after the first time of the original validation.
// We want to then remove the original filter as it will be called 2nd time when generating the reset link and
// the captcha key will already be invalid as already validated the first time.
if ( $allow ) {
// Remove the broken validation hook from the plugin.
remove_filter( 'allow_password_reset', array( 'WC_Ncr_Lost_Password_Captcha', 'validate_lost_password_captcha' ) );
}
}
return $allow;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment