data->ID, 'user_status' ) ){ $message = ''. __('ERROR: ', 'profile-builder') . '' . __('Your account has to be confirmed by an administrator before you can use the "Password Reset" feature.', 'profile-builder'); $message = apply_filters('wppb_recover_password_unapporved_user', $message); } } return $message; } /** * Function that retrieves the unique user key from the database. If we don't have one we generate one and add it to the database * * @param string $requested_user_login the user login */ function wppb_retrieve_activation_key( $requested_user_login ){ $user = get_user_by( 'login', $requested_user_login ); if( empty( $user ) || !function_exists( 'get_password_reset_key' ) ) return false; return get_password_reset_key( $user ); } /** * Function that creates a generate new password form * * @param array $post_data $_POST * */ function wppb_create_recover_password_form( $user, $post_data ){ ?>
user_login; else $display_username_email = $user->user_email; return $display_username_email; } /** * Send the email for the password recovery request * @param $user * @return bool|string|void */ function wppb_send_recovery_email( $user, $success ){ if ( $success == 'wppb_recaptcha_error') return false; $user_object = new WP_User( $user->ID ); if( empty( $user_object->ID ) ) return false; $requested_user_id = $user_object->ID; $requested_user_login = $user_object->user_login; $requested_user_email = $user_object->user_email; //search if there is already an activation key present, if not create one $key = get_password_reset_key( $user_object ); $display_username_email = wppb_get_email_display_username($user); //send primary email message $recovery_email_message = sprintf( __('Someone requested that the password be reset for the following account: %1$s'.$warning.'
'; } else { $output .= $warning; } } } } // If the user used the correct key-code, update his/her password elseif ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action2'] ) && $_POST['action2'] === 'recover_password2' && isset( $_POST['password_recovery_nonce_field2'] ) && isset( $_POST['userData'] ) && wp_verify_nonce( sanitize_text_field( $_POST['password_recovery_nonce_field2'] ), 'verify_true_password_recovery2_'.absint( sanitize_text_field( $_POST['userData'] ) ) ) ) { $password_change_message = ''; if( ( !empty( $_POST['passw1'] ) && !empty( $_POST['passw2'] ) ) ){ //get the login name and key and verify if they match the ones in the database if( isset( $_POST['key'] ) ) $key = sanitize_text_field( $_POST['key'] ); else $key = ''; if( empty( $key ) ){ $password_change_message = __('The key cannot be empty!', 'profile-builder'); $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' ); } if( isset( $_POST['login'] ) ) $login = sanitize_text_field( $_POST['login'] ); else $login = ''; if( empty( $login ) ){ $password_change_message = __('Login cannot be empty!', 'profile-builder'); $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' ); } $user = check_password_reset_key( $key, $login ); if( is_wp_error( $user ) || empty( $user ) || ( !empty( $user ) && $user->ID != absint( $_POST['userData'] ) ) ){ $password_change_message = __('Invalid key!', 'profile-builder'); $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' ); } if( $_POST['passw1'] != $_POST['passw2'] ) { $password_change_message = __('The entered passwords don\'t match!', 'profile-builder'); $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' ); } if( !empty( $wppb_generalSettings['minimum_password_length'] ) || ( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ) ){ if( wppb_check_password_length( $_POST['passw1'] ) ){//phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $password_change_message = sprintf( __( "The password must have the minimum length of %s characters", "profile-builder" ), $wppb_generalSettings['minimum_password_length'] ) . '' . $redirect_message . '
'; } } } else{ $password_change_message .= __( "The password must not be empty!", "profile-builder" ); $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' ); } } // use this action hook to add extra content before the password recovery form do_action( 'wppb_before_recover_password_fields' ); //this is the part that shows the forms if( isset( $_GET['key'] ) && isset( $_GET['login'] ) ){ $key = sanitize_text_field( $_GET['key'] ); $login = sanitize_text_field( $_GET['login'] ); if( !empty( $key ) && !empty( $login ) && !$password_changed_success ) { $user = check_password_reset_key( $key, $login ); if( !is_wp_error( $user ) ){ ob_start(); wppb_create_recover_password_form( $user, $_POST ); $output .= ob_get_contents(); ob_end_clean(); } else { $output .= wppb_password_recovery_error('' . __('ERROR:', 'profile-builder') . '' . __('Invalid key!', 'profile-builder'), 'wppb_recover_password_invalid_key_message'); } } elseif ( !$password_changed_success && !$password_email_sent ) { ob_start(); wppb_create_generate_password_form($_POST); $output .= ob_get_contents(); ob_end_clean(); } } else { if( !$password_email_sent ) { ob_start(); wppb_create_generate_password_form($_POST); $output .= ob_get_contents(); ob_end_clean(); } } // use this action hook to add extra content after the password recovery form. do_action( 'wppb_after_recover_password_fields' ); $output .= ''.$message.'
', $message ); } /* function for displaying warning messages on the recover password page */ function wppb_password_recovery_warning( $message, $filter ){ if( $message !== '' ) { return apply_filters( $filter, ''.$message.'
', $message ); } else { return apply_filters( $filter, '', $message ); } } /* function for displaying error messages on the recover password page */ function wppb_password_recovery_error( $message, $filter ){ return apply_filters( $filter, ''.$message.'
', $message ); } // include missing scripts needed on Elementor Pages (Form inside an Elementor Popup) function wppb_recover_password_scripts_and_styles() { if ( is_plugin_active('elementor-pro/elementor-pro.php') && defined( 'WPPB_PAID_PLUGIN_URL' ) ) wp_enqueue_script( 'wppb_elementor_popup_script', WPPB_PAID_PLUGIN_URL . 'features/elementor-pro/assets/js/elementor-popup.js', array('jquery') ); } add_action( 'elementor/frontend/after_enqueue_scripts', 'wppb_recover_password_scripts_and_styles' );