PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.9
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.9
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / front-end / recover.php

recover.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.9.9, at front-end/recover.php

528 lines 26.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 /**
5 * Function that checks if a user is approved before reseting the password
6 *
7 * @param string $data either the user login or the users email
8 * @param string $what what field we query for when getting the user
9 */
10 function wppb_check_for_unapproved_user( $data, $what ){
11 $message = '';
12
13 $wppb_generalSettings = get_option( 'wppb_general_settings' );
14 if( wppb_get_admin_approval_option_value() === 'yes' ){
15 $user = ( ( $what == 'user_email' ) ? get_user_by( 'email', $data ) : get_user_by( 'login', $data ) );
16
17 if ( wp_get_object_terms( $user->data->ID, 'user_status' ) ){
18 $message = '<strong>'. __('ERROR: ', 'profile-builder') . '</strong>' . __('Your account has to be confirmed by an administrator before you can use the "Password Reset" feature.', 'profile-builder');
19 $message = apply_filters('wppb_recover_password_unapporved_user', $message);
20 }
21 }
22
23 return $message;
24 }
25
26 /**
27
28 * 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
29 *
30 * @param string $requested_user_login the user login
31 */
32
33 function wppb_retrieve_activation_key( $requested_user_login ){
34
35 $user = get_user_by( 'login', $requested_user_login );
36
37 if( empty( $user ) || !function_exists( 'get_password_reset_key' ) )
38 return false;
39
40 return get_password_reset_key( $user );
41
42 }
43
44 /**
45 * Function that creates a generate new password form
46 *
47 * @param array $post_data $_POST
48 *
49 */
50 function wppb_create_recover_password_form( $user, $post_data ){
51 ?>
52 <form enctype="multipart/form-data" method="post" id="wppb-recover-password" class="wppb-user-forms" action="<?php echo esc_url( wppb_curpageurl() ); ?>">
53 <ul>
54 <?php
55
56 if( !empty( $post_data['passw1'] ) )
57 $passw_one = $post_data['passw1'];
58 else
59 $passw_one = '';
60
61 if( !empty( $post_data['passw2'] ) )
62 $passw_two = $post_data['passw2'];
63 else
64 $passw_two = '';
65
66 $password_label = __( 'Password', 'profile-builder' );
67 $repeat_password_label = __( 'Repeat Password', 'profile-builder' );
68
69 $recover_inputPassword = '
70 <li class="wppb-form-field passw1'. apply_filters( 'wppb_recover_field_extra_css_class', '', 'passw1') .'">
71 <label for="passw1">'. esc_html( $password_label ) .'</label>
72 <input class="password" name="passw1" type="password" id="passw1" value="" autocomplete="off" title="'. esc_attr( wppb_password_length_text() ).'" '. apply_filters( 'wppb_recover_password_extra_attr', '', esc_html( $password_label ), 'password' ) .' />
73 '. wppb_password_visibility_toggle_html() .'
74 <span class="wppb-description-delimiter">'. wppb_password_length_text() .' '. wppb_password_strength_description() .'</span>'.
75 /* if we have active the password strength checker */
76 wppb_password_strength_checker_html().'
77 </li><!-- .passw1 -->
78 <input type="hidden" name="userData" value="'. esc_attr( $user->ID ).'"/>
79 <li class="wppb-form-field passw2'. apply_filters( 'wppb_recover_field_extra_css_class', '', 'passw2') .'">
80 <label for="passw2">'. esc_html( $repeat_password_label ) .'</label>
81 <input class="password" name="passw2" type="password" id="passw2" value="" autocomplete="off" '. apply_filters( 'wppb_recover_password_extra_attr', '', esc_html( $repeat_password_label ), 'repeat_password' ) .' />
82 '. wppb_password_visibility_toggle_html() .'
83 </li><!-- .passw2 -->';
84
85 echo apply_filters( 'wppb_recover_password_form_input', $recover_inputPassword, $passw_one, $passw_two, $user->ID ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
86 ?>
87 </ul>
88 <p class="form-submit">
89 <?php $button_name = __('Reset Password', 'profile-builder'); ?>
90 <input name="recover_password2" type="submit" id="wppb-recover-password-button" class="<?php echo esc_attr( apply_filters( 'wppb_recover_submit_class', "submit button" ) ); ?>" value="<?php echo esc_attr( apply_filters('wppb_recover_password_button_name1', $button_name) ); ?>" />
91 <input name="action2" type="hidden" id="action2" value="recover_password2" />
92 <input name="key" type="hidden" id="key" value="<?php echo esc_attr( isset( $_GET['key'] ) ? sanitize_text_field( $_GET['key'] ) : '' ) ?>" />
93 <input name="login" type="hidden" id="login" value="<?php echo esc_attr( isset( $_GET['login'] ) ? sanitize_text_field( $_GET['login'] ) : '' ) ?>" />
94 </p><!-- .form-submit -->
95 <?php wp_nonce_field( 'verify_true_password_recovery2_'.$user->ID, 'password_recovery_nonce_field2' ); ?>
96 </form><!-- #recover_password -->
97 <?php
98 }
99
100 /**
101 * Function that generates the recover password form
102 *
103 * @param WP_User $user the user object
104 * @param array $post_data $_POST
105 *
106 */
107 function wppb_create_generate_password_form( $post_data ){
108 ?>
109 <form enctype="multipart/form-data" method="post" id="wppb-recover-password" class="wppb-user-forms" action="<?php echo esc_url( wppb_curpageurl() ); ?>">
110 <?php
111 $wppb_generalSettings = get_option( 'wppb_general_settings' );
112
113 if( !empty( $wppb_generalSettings['loginWith'] ) && $wppb_generalSettings['loginWith'] == 'email' ){
114 $recover_notification = '<p>' . __( 'Please enter your email address.', 'profile-builder' );
115 $username_email_label = __( 'Email', 'profile-builder' );
116 }
117 else{
118 $recover_notification = '<p>' . __( 'Please enter your username or email address.', 'profile-builder' );
119 $username_email_label = __( 'Username or Email', 'profile-builder' );
120 }
121
122 $recover_notification .= '<br/>'.__( 'You will receive a link to create a new password via email.', 'profile-builder' ).'</p>';
123 echo wp_kses_post( apply_filters( 'wppb_recover_password_message1', $recover_notification ) );
124
125 $username_email = ( isset( $post_data['username_email'] ) ? $post_data['username_email'] : '' );
126
127 $recover_input = '<ul>
128 <li class="wppb-form-field wppb-username-email'. apply_filters( 'wppb_recover_field_extra_css_class', '', 'username_email') .'">
129 <label for="username_email">'. esc_html( $username_email_label ) .'</label>
130 <input class="text-input" name="username_email" type="text" id="username_email" value="'.esc_attr( trim( $username_email ) ).'" '. apply_filters( 'wppb_recover_password_extra_attr', '', esc_html( $username_email_label ), 'username_email' ) .' />
131 </li><!-- .username_email --></ul>';
132 echo apply_filters( 'wppb_recover_password_generate_password_input', $recover_input, trim( $username_email ) ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
133 ?>
134 <p class="form-submit">
135 <?php $button_name = __('Get New Password', 'profile-builder'); ?>
136 <input name="recover_password" type="submit" id="wppb-recover-password-button" class="<?php echo esc_attr( apply_filters( 'wppb_recover_submit_class', "submit button" ) );?>" value="<?php echo esc_attr( apply_filters('wppb_recover_password_button_name3', $button_name) ); ?>" />
137 <input name="action" type="hidden" id="action" value="recover_password" />
138 </p>
139 <?php wp_nonce_field( 'verify_true_password_recovery', 'password_recovery_nonce_field' ); ?>
140 </form>
141 <?php
142 }
143
144 /**
145 * Determine based on the PB login settings what to display in the email sent on password reset: username or email
146 * @param $user
147 * @return mixed
148 */
149 function wppb_get_email_display_username($user){
150 //Get general settings
151 $wppb_generalSettings = get_option( 'wppb_general_settings' );
152
153 if( $wppb_generalSettings['loginWith'] == 'username' || $wppb_generalSettings['loginWith'] == 'usernameemail' )
154 $display_username_email = $user->user_login;
155 else
156 $display_username_email = $user->user_email;
157
158 return $display_username_email;
159 }
160
161 /**
162 * Send the email for the password recovery request
163 * @param $user
164 * @return bool|string|void
165 */
166 function wppb_send_recovery_email( $user, $success ){
167
168 if ( $success == 'wppb_recaptcha_error')
169 return false;
170
171 $user_object = new WP_User( $user->ID );
172
173 if( empty( $user_object->ID ) )
174 return false;
175
176 $requested_user_id = $user_object->ID;
177 $requested_user_login = $user_object->user_login;
178 $requested_user_email = $user_object->user_email;
179
180 //search if there is already an activation key present, if not create one
181 $key = get_password_reset_key( $user_object );
182
183 $display_username_email = wppb_get_email_display_username($user);
184
185 //send primary email message
186 $recovery_email_message = sprintf( __('Someone requested that the password be reset for the following account: <b>%1$s</b><br/>If this was a mistake, just ignore this email and nothing will happen.<br/>To reset your password, visit the following link:%2$s', 'profile-builder'), $display_username_email, '<a href="'.esc_url( add_query_arg( array( 'key' => $key, 'login' => $requested_user_login ), wppb_curpageurl() ) ).'">'.esc_url( add_query_arg( array( 'key' => $key, 'login' => $requested_user_login ), wppb_curpageurl() ) ).'</a>' );
187 $recovery_email_message = apply_filters( 'wppb_recover_password_message_content_sent_to_user1', $recovery_email_message, $requested_user_id, $requested_user_login, $requested_user_email );
188
189 $recovery_email_message_title = sprintf(__('Password Reset from %1$s', 'profile-builder'), $blogname = get_option('blogname') );
190 $recovery_email_message_title = apply_filters('wppb_recover_password_message_title_sent_to_user1', $recovery_email_message_title, $requested_user_login);
191
192 $recovery_email_from = apply_filters ( 'wppb_recover_password_notification_email_from_field', get_bloginfo( 'name' ) );
193 $recovery_email_context = 'email_user_recover';
194
195
196 $sent = false;
197 //send mail to the user notifying him of the reset request
198 if (trim($recovery_email_message_title) != '') {
199 $sent = wppb_mail($requested_user_email, $recovery_email_message_title, $recovery_email_message, $recovery_email_from, $recovery_email_context);
200 }
201
202 return $sent;
203
204 }
205
206 /**
207 * Function that sends the successful password reset email to the user
208 * @param $user
209 * @param $new_pass
210 */
211 function wppb_send_successful_password_reset_email( $user, $new_pass ){
212
213 $display_username_email = wppb_get_email_display_username($user);
214
215 //send secondary mail to the user containing the username and the new password
216 $recovery_email_message = __( 'You have successfully reset your password.', 'profile-builder' );
217 $recovery_email_message = apply_filters( 'wppb_recover_password_message_content_sent_to_user2', $recovery_email_message, $display_username_email, $new_pass, $user->ID );
218 $recovery_email_message_title = sprintf( __('Password Successfully Reset for %1$s on %2$s', 'profile-builder' ), $display_username_email, $blogname = get_option('blogname') );
219 $recovery_email_message_title = apply_filters( 'wppb_recover_password_message_title_sent_to_user2', $recovery_email_message_title, $display_username_email );
220 $recovery_email_from = apply_filters ( 'wppb_recover_password_success_notification_email_from_field', get_bloginfo( 'name' ) );
221 $recovery_email_context = 'email_user_recover_success';
222 //send mail to the user notifying him of the reset request
223 if ( trim( $recovery_email_message_title ) != '' )
224 wppb_mail( $user->user_email, $recovery_email_message_title, $recovery_email_message, $recovery_email_from, $recovery_email_context );
225 }
226
227 /**
228 * Function that sends an email to the admin after the password was reset
229 * we disable the feature to send the admin a notification mail but can be still used using filters
230 * @param $user
231 */
232 function wppb_send_admin_password_reset_email( $user ){
233
234 $display_username_email = wppb_get_email_display_username($user);
235
236 $recovery_admin_email_message = sprintf( __( '%1$s has requested a password change via the password reset feature.<br/>His/her new password is:%2$s', 'profile-builder' ), $display_username_email, '' );
237 $recovery_admin_email_message = apply_filters( 'wppb_recover_password_message_content_sent_to_admin', $recovery_admin_email_message, $display_username_email, '', $user->ID );
238 //we disable the feature to send the admin a notification mail but can be still used using filters
239 $recovery_admin_email_title = '';
240 $recovery_admin_email_title = apply_filters( 'wppb_recover_password_message_title_sent_to_admin', $recovery_admin_email_title, $display_username_email );
241 $recovery_email_from = apply_filters ( 'wppb_recover_password_success_notification_email_from_field', get_bloginfo( 'name' ) );
242 $recovery_admin_email_context = 'email_admin_recover_success';
243 //send mail to the admin notifying him of of a user with a password reset request
244 if (trim($recovery_admin_email_title) != '')
245 wppb_mail(get_option('admin_email'), $recovery_admin_email_title, $recovery_admin_email_message, $recovery_email_from, $recovery_admin_email_context);
246 }
247
248 /**
249 * The function for the recover password shortcode
250 *
251 */
252 function wppb_front_end_password_recovery( $atts ){
253 global $wppb_shortcode_on_front;
254 $wppb_shortcode_on_front = true;
255 global $wppb_password_recovery_shortcode_on_front;
256 $wppb_password_recovery_shortcode_on_front = true;
257 $password_email_sent = false;
258 $password_changed_success = false;
259
260 extract( shortcode_atts( array( 'block' => false ), $atts ) );
261
262 $output = '<div class="wppb_holder" id="wppb-recover-password-container">';
263
264 global $wpdb;
265
266 // check if the form is being displayed in the Elementor editor
267 $is_elementor_edit_mode = false;
268 if( class_exists ( '\Elementor\Plugin' ) ){
269 $is_elementor_edit_mode = \Elementor\Plugin::$instance->editor->is_edit_mode();
270 }
271
272 if( is_user_logged_in() && !( $is_elementor_edit_mode || $block ) ) {
273 return apply_filters('wppb_recover_password_already_logged_in', __('You are already logged in. You can change your password on the edit profile form.', 'profile-builder'));
274 }
275
276 //Get general settings
277 $wppb_generalSettings = get_option( 'wppb_general_settings' );
278
279 // If the user entered an email/username, process the request
280 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'recover_password' && isset( $_POST['password_recovery_nonce_field'] ) && wp_verify_nonce( sanitize_text_field( $_POST['password_recovery_nonce_field'] ),'verify_true_password_recovery') ) {
281 // filter must be applied on the $_POST variable so that the value returned to the form can be corrected too
282
283 if( !empty( $_POST['username_email'] ) )
284 $username_email = apply_filters( 'wppb_before_processing_email_from_forms', sanitize_text_field( $_POST['username_email'] ) ); //we get the raw data
285 else
286 $username_email = '';
287
288 //check to see if it's an e-mail (and if this is valid/present in the database) or is a username
289
290 // if we do not have an email in the posted date we try to get the email for that user
291 if( !is_email( $username_email ) ){
292 /* make sure it is a username */
293 $username = sanitize_user( $username_email );
294 if ( username_exists($username) ){
295 $query = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE user_login= %s", $username ) );
296 if( !empty( $query[0] ) ){
297 $username_email = $query[0]->user_email;
298 }
299 }
300 else{
301 $warning = __( 'The username entered wasn\'t found in the database!', 'profile-builder').'<br/>'.__('Please check that you entered the correct username.', 'profile-builder' );
302 $warning = apply_filters( 'wppb_recover_password_sent_message4', $warning );
303 $output .= wppb_password_recovery_warning( $warning, 'wppb_recover_password_displayed_message1' );
304 }
305 }
306
307 // we should have an email by this point
308 if ( is_email( $username_email ) ){
309 if ( email_exists( $username_email ) ){
310 $warning = wppb_check_for_unapproved_user($username_email, 'user_email');
311 if ($warning != ''){
312 $output .= wppb_password_recovery_warning( $warning, 'wppb_recover_password_displayed_message1' );
313 }else{
314 $success = sprintf( __( 'Check your email for the confirmation link.', 'profile-builder'), $username_email );
315 $success = apply_filters( 'wppb_recover_password_sent_message1', $success, $username_email );
316
317 if ( $success != 'wppb_recaptcha_error')
318 $output .= wppb_password_recovery_success( $success, 'wppb_recover_password_displayed_message2' );
319
320 //verify e-mail validity
321 $query = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE user_email= %s", sanitize_email( $username_email ) ) );
322 if( !empty( $query[0] ) ){
323 $user = $query[0];
324
325 //send mail to the user notifying him of the reset request
326 $sent = wppb_send_recovery_email( $user, $success );
327 if ($sent === false){
328 $warning = '<strong>'. __( 'ERROR:', 'profile-builder' ) .'</strong>' . sprintf( __( 'There was an error while trying to send the activation link to %1$s!', 'profile-builder' ), $username_email );
329 $warning = apply_filters( 'wppb_recover_password_sent_message_error_sending', $warning );
330 $output .= wppb_password_recovery_warning( $warning, 'wppb_recover_password_displayed_message1' );
331 }
332 else
333 $password_email_sent = true;
334
335 }
336
337 }
338 }elseif ( !email_exists( $username_email ) ){
339 // check reCAPTCHA
340 $warning = wppb_password_recovery_warning( '', 'wppb_recover_password_displayed_message1' );
341
342 // if there is no reCAPTCHA error show the invalid email address error
343 if( $warning === '' ) {
344 $warning = __('The email address entered wasn\'t found in the database!', 'profile-builder').'<br/>'.__('Please check that you entered the correct email address.', 'profile-builder');
345 $warning = apply_filters('wppb_recover_password_sent_message2', $warning);
346 $output .= '<p class="wppb-warning">'.$warning.'</p>';
347 } else {
348 $output .= $warning;
349 }
350 }
351 }
352 }
353 // If the user used the correct key-code, update his/her password
354 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'] ) ) ) ) {
355
356 $password_change_message = '';
357
358 if( ( !empty( $_POST['passw1'] ) && !empty( $_POST['passw2'] ) ) ){
359
360 //get the login name and key and verify if they match the ones in the database
361 if( isset( $_POST['key'] ) )
362 $key = sanitize_text_field( $_POST['key'] );
363 else
364 $key = '';
365
366 if( empty( $key ) ){
367 $password_change_message = __('The key cannot be empty!', 'profile-builder');
368 $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' );
369 }
370
371 if( isset( $_POST['login'] ) )
372 $login = sanitize_text_field( $_POST['login'] );
373 else
374 $login = '';
375
376 if( empty( $login ) ){
377 $password_change_message = __('Login cannot be empty!', 'profile-builder');
378 $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' );
379 }
380
381 $user = check_password_reset_key( $key, $login );
382
383 if( is_wp_error( $user ) || empty( $user ) || ( !empty( $user ) && $user->ID != absint( $_POST['userData'] ) ) ){
384 $password_change_message = __('Invalid key!', 'profile-builder');
385 $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' );
386 }
387
388 if( $_POST['passw1'] != $_POST['passw2'] ) {
389 $password_change_message = __('The entered passwords don\'t match!', 'profile-builder');
390 $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' );
391 }
392
393 if( !empty( $wppb_generalSettings['minimum_password_length'] ) || ( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ) ){
394 if( wppb_check_password_length( $_POST['passw1'] ) ){//phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
395 $password_change_message = sprintf( __( "The password must have the minimum length of %s characters", "profile-builder" ), $wppb_generalSettings['minimum_password_length'] ) . '<br/>';
396 $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' );
397 }
398 if( wppb_check_password_strength() ){
399 $password_change_message = sprintf( __( "The password must have a minimum strength of %s", "profile-builder" ), wppb_check_password_strength() );
400 $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' );
401 }
402 }
403
404 if( empty($password_change_message) ){
405
406 $password_change_message = __( 'Your password has been successfully changed!', 'profile-builder' );
407 $output .= wppb_password_recovery_success( $password_change_message, 'wppb_recover_password_password_changed_message1' );
408 $password_changed_success = true;
409
410 $userID = $user->ID;
411 $new_pass = $_POST['passw1']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
412
413 //update the new password and delete the key
414 do_action( 'wppb_password_reset', $userID, $new_pass );
415 wp_set_password( $new_pass, $userID );
416
417 /* log out of all sessions on password reset */
418 $sessions = WP_Session_Tokens::get_instance( $userID );
419 $sessions->destroy_all();
420
421 $user_info = get_userdata( $userID );
422
423 //send email to user
424 wppb_send_successful_password_reset_email( $user_info, $new_pass );
425
426 //send email to admin
427 wppb_send_admin_password_reset_email( $user_info );
428
429 // CHECK FOR REDIRECT
430 $redirect_url = wppb_get_redirect_url( 'normal', 'after_success_password_reset', '', sanitize_user( $user_info->user_login ) );
431
432 //log the user in if the option was selected
433 if ( apply_filters( 'wppb_recover_password_autologin', false ) ){
434 $nonce = wp_create_nonce( 'autologin-'. sanitize_user( $user_info->ID ) .'-'. (int)( time() / 60 ) );
435
436 //use the after_login redirect if no after_success_password_reset redirect is set
437 if( empty( $redirect_url ) ) {
438 $redirect_url = wppb_get_redirect_url( 'normal', 'after_login', '', sanitize_user( $user_info->user_login ) );
439 $redirect_url = apply_filters( 'wppb_after_recover_and_login', $redirect_url );
440 }
441 if( empty( $redirect_url ) ) {
442 $redirect_url = remove_query_arg( 'key', wppb_curpageurl() );
443 }
444
445 $redirect_url = add_query_arg( array( 'autologin' => 'true', 'uid' => sanitize_user( $user_info->ID ), '_wpnonce' => $nonce ), $redirect_url );
446 }
447
448 $redirect_delay = apply_filters( 'wppb_success_password_reset_redirect_delay', 3, sanitize_user( $user_info->user_login ) );
449 $redirect_message = wppb_build_redirect( $redirect_url, $redirect_delay, 'after_success_password_reset' );
450
451 if( isset( $redirect_message ) && ! empty( $redirect_message ) ) {
452 $output .= '<p>' . $redirect_message . '</p>';
453 }
454 }
455 }
456 else{
457 $password_change_message .= __( "The password must not be empty!", "profile-builder" );
458 $output .= wppb_password_recovery_error( $password_change_message, 'wppb_recover_password_password_changed_message2' );
459 }
460 }
461
462 // use this action hook to add extra content before the password recovery form
463 do_action( 'wppb_before_recover_password_fields' );
464
465
466 //this is the part that shows the forms
467 if( isset( $_GET['key'] ) && isset( $_GET['login'] ) ){
468
469 $key = sanitize_text_field( $_GET['key'] );
470 $login = sanitize_text_field( $_GET['login'] );
471
472 if( !empty( $key ) && !empty( $login ) && !$password_changed_success ) {
473
474 $user = check_password_reset_key( $key, $login );
475
476 if( !is_wp_error( $user ) ){
477
478 ob_start();
479 wppb_create_recover_password_form( $user, $_POST );
480 $output .= ob_get_contents();
481 ob_end_clean();
482 }
483 else {
484 $output .= wppb_password_recovery_error('<strong>' . __('ERROR:', 'profile-builder') . '</strong>' . __('Invalid key!', 'profile-builder'), 'wppb_recover_password_invalid_key_message');
485 }
486
487 } elseif ( !$password_changed_success && !$password_email_sent ) {
488 ob_start();
489 wppb_create_generate_password_form($_POST);
490 $output .= ob_get_contents();
491 ob_end_clean();
492 }
493
494 } else {
495 if( !$password_email_sent ) {
496 ob_start();
497 wppb_create_generate_password_form($_POST);
498 $output .= ob_get_contents();
499 ob_end_clean();
500 }
501 }
502
503 // use this action hook to add extra content after the password recovery form.
504 do_action( 'wppb_after_recover_password_fields' );
505
506 $output .= '</div>';
507 return apply_filters( 'wppb_recover_password_before_content_output', $output );
508 }
509
510 /* function for displaying success messages on the recover password page */
511 function wppb_password_recovery_success( $message, $filter ){
512 return apply_filters( $filter, '<p class="wppb-success">'.$message.'</p>', $message );
513 }
514
515 /* function for displaying warning messages on the recover password page */
516 function wppb_password_recovery_warning( $message, $filter ){
517 if( $message !== '' ) {
518 return apply_filters( $filter, '<p class="wppb-warning">'.$message.'</p>', $message );
519 } else {
520 return apply_filters( $filter, '', $message );
521 }
522 }
523
524 /* function for displaying error messages on the recover password page */
525 function wppb_password_recovery_error( $message, $filter ){
526 return apply_filters( $filter, '<p class="wppb-error">'.$message.'</p>', $message );
527 }
528