From 7ad05f0e09624aa1b874a66b4359f6d78dfcfc4a Mon Sep 17 00:00:00 2001
From: Leho Kraav <leho@kraav.com>
Date: Thu, 20 Jun 2019 16:36:27 +0200
Subject: [PATCH] Bootstrap/Load: Allow recovery e-mail immediately after admin
 e-mail change. Fixes #47352.

---
 .../class-wp-recovery-mode-email-service.php   | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/wp-includes/class-wp-recovery-mode-email-service.php b/wp-includes/class-wp-recovery-mode-email-service.php
index 193a41483e..c85a53a038 100644
--- a/wp-includes/class-wp-recovery-mode-email-service.php
+++ b/wp-includes/class-wp-recovery-mode-email-service.php
@@ -13,7 +13,7 @@
  */
 final class WP_Recovery_Mode_Email_Service {
 
-	const RATE_LIMIT_OPTION = 'recovery_mode_email_last_sent';
+	const RATE_LIMIT_OPTION_PREFIX = 'recovery_mode_email_last_sent';
 
 	/**
 	 * Service to generate recovery mode URLs.
@@ -49,10 +49,10 @@ final class WP_Recovery_Mode_Email_Service {
 	 */
 	public function maybe_send_recovery_mode_email( $rate_limit, $error, $extension ) {
 
-		$last_sent = get_option( self::RATE_LIMIT_OPTION );
+		$last_sent = get_option( $this->get_rate_limit_option_name() );
 
 		if ( ! $last_sent || time() > $last_sent + $rate_limit ) {
-			if ( ! update_option( self::RATE_LIMIT_OPTION, time() ) ) {
+			if ( ! update_option( $this->get_rate_limit_option_name(), time() ) ) {
 				return new WP_Error( 'storage_error', __( 'Could not update the email last sent time.' ) );
 			}
 
@@ -90,7 +90,7 @@ final class WP_Recovery_Mode_Email_Service {
 	 * @return bool True on success, false on failure.
 	 */
 	public function clear_rate_limit() {
-		return delete_option( self::RATE_LIMIT_OPTION );
+		return delete_option( $this->get_rate_limit_option_name() );
 	}
 
 	/**
@@ -272,4 +272,14 @@ To keep your site safe, this link will expire in ###EXPIRES###. Don\'t worry abo
 
 		return $cause;
 	}
+
+	/**
+	 * Centralizes rate limit option name composition.
+	 *
+	 * @return string Option key name.
+	 * @since 5.3.0
+	 */
+	private function get_rate_limit_option_name() {
+		return sprintf( '%s_%s', self::RATE_LIMIT_OPTION_PREFIX, $this->get_recovery_mode_email_address() );;
+	}
 }
-- 
2.21.0

