| | 442 | /** |
| | 443 | * Handles sending recovery_link retrieval email to user. |
| | 444 | * |
| | 445 | * @since 5.3.0 |
| | 446 | * |
| | 447 | * @return bool|WP_Error True: when finish. WP_Error on error |
| | 448 | */ |
| | 449 | function retrieve_recovery_link() { |
| | 450 | $errors = new WP_Error(); |
| | 451 | |
| | 452 | if ( empty( $_POST['user_login'] ) || ! is_string( $_POST['user_login'] ) ) { |
| | 453 | $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Enter a username or email address.' ) ); |
| | 454 | } elseif ( strpos( $_POST['user_login'], '@' ) ) { |
| | 455 | $user_data = get_user_by( 'email', trim( wp_unslash( $_POST['user_login'] ) ) ); |
| | 456 | if ( empty( $user_data ) ) { |
| | 457 | $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: There is no account with that username or email address.' ) ); |
| | 458 | } |
| | 459 | } else { |
| | 460 | $login = trim( $_POST['user_login'] ); |
| | 461 | $user_data = get_user_by( 'login', $login ); |
| | 462 | } |
| | 463 | |
| | 464 | if ( $errors->has_errors() ) { |
| | 465 | return $errors; |
| | 466 | } |
| | 467 | |
| | 468 | if ( ! $user_data ) { |
| | 469 | $errors->add( 'invalidcombo', __( '<strong>ERROR</strong>: There is no account with that username or email address.' ) ); |
| | 470 | |
| | 471 | return $errors; |
| | 472 | } |
| | 473 | |
| | 474 | if ( ! user_can( $user_data, 'resume_plugins' ) && user_can( $user_data, 'resume_themes' ) ) { |
| | 475 | $errors->add( 'invaliduser', __( '<strong>ERROR</strong>: This account is unable to access recovery mode.' ) ); |
| | 476 | |
| | 477 | return $errors; |
| | 478 | } |
| | 479 | |
| | 480 | wp_recovery_mode()->get_email_service()->set_recovery_mode_email_address( $user_data->user_email ); |
| | 481 | wp_recovery_mode()->get_email_service()->maybe_send_recovery_mode_email( 0, array(), array() ); |
| | 482 | |
| | 483 | return true; |
| | 484 | } |
| | 485 | |
| 447 | | if ( ! in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login', 'confirmaction', WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED ), true ) && false === has_filter( 'login_form_' . $action ) ) { |
| | 498 | if ( ! in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login', 'confirmaction', 'recovery_request', 'recovery_recieved', WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED ), true ) && false === has_filter( 'login_form_' . $action ) ) { |
| | 680 | |
| | 681 | <p id="nav"> |
| | 682 | <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
| | 683 | <?php |
| | 684 | if ( get_option( 'users_can_register' ) ) : |
| | 685 | $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |
| | 686 | |
| | 687 | echo esc_html( $login_link_separator ); |
| | 688 | |
| | 689 | /** This filter is documented in wp-includes/general-template.php */ |
| | 690 | echo apply_filters( 'register', $registration_url ); |
| | 691 | endif; |
| | 692 | ?> |
| | 693 | </p> |
| | 694 | |
| | 695 | <?php |
| | 696 | login_footer( 'user_login' ); |
| | 697 | |
| | 698 | break; |
| | 699 | case 'recovery_recieved': |
| | 700 | |
| | 701 | $message = '<p class="message">' . __( 'Check your email for the recovery link.' ) . '</p>'; |
| | 702 | |
| | 703 | login_header( __( 'User action confirmed.' ), $message ); |
| | 704 | login_footer(); |
| | 705 | exit; |
| | 706 | |
| | 707 | case 'recovery_request': |
| | 708 | if ( $http_post ) { |
| | 709 | $errors = retrieve_recovery_link(); |
| | 710 | if ( ! is_wp_error( $errors ) ) { |
| | 711 | $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm'; |
| | 712 | wp_safe_redirect( $redirect_to ); |
| | 713 | exit(); |
| | 714 | } |
| | 715 | } |
| | 716 | |
| | 717 | $recovery_request_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
| | 718 | /** |
| | 719 | * Filters the URL redirected to after submitting the recovery_request form. |
| | 720 | * |
| | 721 | * @since 5.3.0 |
| | 722 | * |
| | 723 | * @param string $recovery_request The redirect destination URL. |
| | 724 | */ |
| | 725 | $redirect_to = apply_filters( 'recovery_request_redirect', $recovery_request_redirect ); |
| | 726 | |
| | 727 | |
| | 728 | |
| | 729 | login_header( __( 'Lost Password' ), '<p class="message">' . __( 'Please enter your username or email address. You will receive a recovery link via email.' ) . '</p>', $errors ); |
| | 730 | |
| | 731 | $user_login = ''; |
| | 732 | |
| | 733 | if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) { |
| | 734 | $user_login = wp_unslash( $_POST['user_login'] ); |
| | 735 | } |
| | 736 | |
| | 737 | ?> |
| | 738 | |
| | 739 | <form name="recovery_request" id="recovery_request" action="<?php echo esc_url( site_url( 'wp-login.php?action=recovery_request', 'recovery_request' ) ); ?>" method="post"> |
| | 740 | <p> |
| | 741 | <label for="user_login" ><?php _e( 'Username or Email Address' ); ?><br /> |
| | 742 | <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" /></label> |
| | 743 | </p> |
| | 744 | <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" /> |
| | 745 | <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Request recovery email' ); ?>" /></p> |
| | 746 | </form> |
| 630 | | <p id="nav"> |
| 631 | | <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
| 632 | | <?php |
| 633 | | if ( get_option( 'users_can_register' ) ) : |
| 634 | | $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |
| | 748 | <p id="nav"> |
| | 749 | <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
| | 750 | <?php |
| | 751 | if ( get_option( 'users_can_register' ) ) : |
| | 752 | $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |