PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.6
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.6
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.6, at front-end/recover.php

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