Created
June 7, 2019 07:56
-
-
Save VlooMan/b2f99357c8fd90c91ffc82b0d88003a9 to your computer and use it in GitHub Desktop.
No CAPTCHA reCAPTCHA for WooCommerce plugin - Lost password wrong link fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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