| | 453 | /** |
| | 454 | * Handles sending recovery_link retrieval email to user. |
| | 455 | * |
| | 456 | * @since 5.3.0 |
| | 457 | * |
| | 458 | * @return bool|WP_Error True: when finish. WP_Error on error |
| | 459 | */ |
| | 460 | function retrieve_recovery_link() { |
| | 461 | $errors = new WP_Error(); |
| | 462 | |
| | 463 | if ( empty( $_POST['user_login'] ) || ! is_string( $_POST['user_login'] ) ) { |
| | 464 | $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Enter a username or email address.' ) ); |
| | 465 | $user_data = false; |
| | 466 | } elseif ( is_email( $_POST['user_login']) ) { |
| | 467 | $user_data = get_user_by( 'email', trim( wp_unslash( $_POST['user_login'] ) ) ); |
| | 468 | if ( empty( $user_data ) ) { |
| | 469 | $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: There is no account with that username or email address.' ) ); |
| | 470 | } |
| | 471 | } else { |
| | 472 | $login = trim( $_POST['user_login'] ); |
| | 473 | $user_data = get_user_by( 'login', $login ); |
| | 474 | } |
| | 475 | |
| | 476 | if ( $errors->has_errors() ) { |
| | 477 | return $errors; |
| | 478 | } |
| | 479 | |
| | 480 | if ( ! $user_data ) { |
| | 481 | $errors->add( 'invalidcombo', __( '<strong>ERROR</strong>: There is no account with that username or email address.' ) ); |
| | 482 | |
| | 483 | return $errors; |
| | 484 | } |
| | 485 | |
| | 486 | if ( ! user_can( $user_data, 'resume_plugins' ) && user_can( $user_data, 'resume_themes' ) ) { |
| | 487 | $errors->add( 'invaliduser', __( '<strong>ERROR</strong>: This account is unable to access recovery mode.' ) ); |
| | 488 | |
| | 489 | return $errors; |
| | 490 | } |
| | 491 | |
| | 492 | wp_recovery_mode()->get_email_service()->set_recovery_mode_email_address( $user_data->user_email ); |
| | 493 | $email_sent = wp_recovery_mode()->get_email_service()->send_recovery_mode_email( 0, array(), array() ); |
| | 494 | |
| | 495 | if ( ! $email_sent ) { |
| | 496 | $errors->add( 'unable_to_send', __( '<strong>ERROR</strong>: Unable to send email.' ) ); |
| | 497 | return $email_sent; |
| | 498 | } |
| | 499 | |
| | 500 | return true; |
| | 501 | } |
| | 502 | |
| 456 | | 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 ) ) { |
| | 515 | 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 ) ) { |
| | 725 | |
| | 726 | login_header( $page_title, $message ); |
| | 727 | login_footer(); |
| | 728 | exit; |
| | 729 | |
| | 730 | case 'recovery_request': |
| | 731 | if ( is_multisite() ) { |
| | 732 | $page_title = __( 'User action disabled.' ); |
| | 733 | $message = '<p class="message">' . __( 'Recovery mode not supported in multiste.' ) . '</p>'; |
| | 734 | |
| | 735 | login_header( $page_title, $message ); |
| | 736 | login_footer(); |
| | 737 | exit; |
| | 738 | } |
| | 739 | if ( $http_post ) { |
| | 740 | $errors = retrieve_recovery_link(); |
| | 741 | if ( ! is_wp_error( $errors ) ) { |
| | 742 | $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?action=recovery_recieved'; |
| | 743 | wp_safe_redirect( $redirect_to ); |
| | 744 | exit(); |
| | 745 | } |
| | 746 | } |
| | 747 | |
| | 748 | $recovery_request_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
| | 749 | /** |
| | 750 | * Filters the URL redirected to after submitting the recovery_request form. |
| | 751 | * |
| | 752 | * @since 5.3.0 |
| | 753 | * |
| | 754 | * @param string $recovery_request The redirect destination URL. |
| | 755 | */ |
| | 756 | $redirect_to = apply_filters( 'recovery_request_redirect', $recovery_request_redirect ); |
| | 757 | |
| | 758 | |
| | 759 | |
| | 760 | login_header( __( 'Request recovery ink' ), '<p class="message">' . __( 'Please enter your username or email address. You will receive a recovery link via email.' ) . '</p>', $errors ); |
| | 761 | |
| | 762 | $user_login = ''; |
| | 763 | |
| | 764 | if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) { |
| | 765 | $user_login = wp_unslash( $_POST['user_login'] ); |
| | 766 | } |
| | 767 | |
| | 768 | ?> |
| | 769 | |
| | 770 | <form name="recovery_request" id="recovery_request" action="<?php echo esc_url( site_url( 'wp-login.php?action=recovery_request', 'recovery_request' ) ); ?>" method="post"> |
| | 771 | <p> |
| | 772 | <label for="user_login" ><?php _e( 'Username or Email Address' ); ?><br /> |
| | 773 | <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" /></label> |
| | 774 | </p> |
| | 775 | <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" /> |
| | 776 | <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> |
| | 777 | </form> |
| | 778 | |
| | 779 | <p id="nav"> |
| | 780 | <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
| | 781 | <?php |
| | 782 | if ( get_option( 'users_can_register' ) ) : |
| | 783 | $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |
| | 784 | |
| | 785 | echo esc_html( $login_link_separator ); |
| | 786 | |
| | 787 | /** This filter is documented in wp-includes/general-template.php */ |
| | 788 | echo apply_filters( 'register', $registration_url ); |
| | 789 | endif; |
| | 790 | ?> |
| | 791 | </p> |
| | 792 | |
| | 793 | <?php |
| | 794 | login_footer( 'user_login' ); |
| | 795 | |
| | 796 | break; |
| | 797 | |
| | 798 | |