From 161766d0a2fd72b653b7fa5762c2ddffed044d9b Mon Sep 17 00:00:00 2001
From: "T.Todua" <7117978+ttodua@users.noreply.github.com>
Date: Thu, 9 Apr 2020 20:43:30 +0400
Subject: [PATCH] update

---
 src/wp-includes/functions.php | 13 +++++++++++++
 src/wp-login.php              | 10 ++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index bc9f276b89..b38ce41abd 100644
--- a/src/wp-includes/functions.php
+++ b/src/wp-includes/functions.php
@@ -6540,6 +6540,19 @@ function wp_auth_check( $response ) {
 	return $response;
 }
 
+/**
+ * Check whether user registration is disabled and password reset is also disabled
+ * for existing users, and in this case, redirects to login page.
+ *
+ * @since 5.4.0
+ */
+function wp_redirect_if_disabled_registration_and_reset() {
+	if ( !get_option( 'users_can_register' ) && ! apply_filters( 'allow_password_reset_for_existing_users', true ) ) {
+		wp_safe_redirect( 'wp-login.php' );
+		exit();
+	}
+}
+
 /**
  * Return RegEx body to liberally match an opening HTML tag.
  *
diff --git a/src/wp-login.php b/src/wp-login.php
index 0b552ef326..b471822621 100644
--- a/src/wp-login.php
+++ b/src/wp-login.php
@@ -801,6 +801,8 @@ switch ( $action ) {
 
 	case 'lostpassword':
 	case 'retrievepassword':
+		wp_redirect_if_disabled_registration_and_reset();
+		
 		if ( $http_post ) {
 			$errors = retrieve_password();
 
@@ -893,6 +895,8 @@ switch ( $action ) {
 
 	case 'resetpass':
 	case 'rp':
+		wp_redirect_if_disabled_registration_and_reset();
+		
 		list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
 		$rp_cookie       = 'wp-resetpass-' . COOKIEHASH;
 
@@ -1362,7 +1366,7 @@ switch ( $action ) {
 		?>
 
 		<form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
-			<p>
+			<p class="username-email">
 				<label for="user_login"><?php _e( 'Username or Email Address' ); ?></label>
 				<input type="text" name="log" id="user_login"<?php echo $aria_describedby_error; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" />
 			</p>
@@ -1430,7 +1434,9 @@ switch ( $action ) {
 					}
 
 					?>
-					<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
+					<?php if ( get_option( 'users_can_register' ) || apply_filters( 'allow_password_reset_for_existing_users', true ) ) : ?>
+						<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
+					<?php endif; ?>
 					<?php
 				}
 
-- 
2.24.1.windows.2

