I added the code to my functions.php
function my_frontend_ur_lostpassword_form_captcha(){
......
}
add_action('user_registration_lostpassword_form', 'my_frontend_ur_lostpassword_form_captcha', 10, 2);
function my_ur_lostpassword_form_verification($true){
if ( isset($_POST['captcha_token']) && isset($_POST['captcha_server']) ) {
$captcha_token = $_POST['captcha_token'];
$captcha_server = $_POST['captcha_server'];
$myCaptcha = new myCaptcha();
if ( $myCaptcha->$myCaptcha_verification( $captcha_server, $captcha_token ) == true ){
return $true;
}else{
return new WP_Error("Captcha Invalid", __("<strong>ERROR</strong>: Captcha verification failed, please try again.", 'mycaptcha'));
}
}else{
return new WP_Error("Captcha Invalid", __("<strong>ERROR</strong>: Captcha verification failed, please try again. If not then enable JavaScript", 'mycaptcha'));
}
}
return $true;
}
add_filter( 'allow_password_reset','my_ur_lostpassword_form_verification', 10, 3);
when I test it on the lostpassword page after I input the email address and the captcha done, everything works fine, but click the reset password button will give this Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string in /var/www/html/wp-content/plugins/user-registration/includes/class-ur-emailer.php:605 Stack trace: #0 /var/www/html/wp-content/plugins/user-registration/includes/class-ur-emailer.php(605): str_replace('{{key}}', Object(WP_Error), 'Someone has req...') #1 /var/www/html/wp-content/plugins/user-registration/includes/class-ur-emailer.php(439): UR_Emailer::parse_smart_tags('Someone has req...', Array) #2 /var/www/html/wp-content/plugins/user-registration/includes/shortcodes/class-ur-shortcode-my-account.php(371): UR_Emailer::lost_password_email('[email protected]...', Object(WP_User), Object(WP_Error)) #3 /var/www/html/wp-content/plugins/user-registration/includes/class-ur-form-handler.php(487): UR_Shortcode_My_Account::retrieve_password() #4 /var/www/html/wp-includes/class-wp-hook.php(303): UR_Form_Handler::process_lost_password('') #5 /var/www/html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array) #6 /var/www/html/wp- in /var/www/html/wp-content/plugins/user-registration/includes/class-ur-emailer.php on line 605
It seems that the user registration plugin does not allow other plugins to add the verification code to the lost password page and I found the filter “allow_password_reset” in /var/www/html/wp-content/plugins/user-registration/includes/shortcodes/class-ur-shortcode-my-account.php $allow = apply_filters( ‘allow_password_reset’, true, $user_data->ID ); ,
I don’t know why the user registration plugin use the wordpress default filter name “allow_password_reset”, is there have any other filter let me to add my own custom captcha verification to User Registration lostpassword page ?
-
This reply was modified 3 years, 3 months ago by
csit.