Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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