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
|
b
|
|
| 13 | 13 | */ |
| 14 | 14 | final class WP_Recovery_Mode_Email_Service { |
| 15 | 15 | |
| 16 | | const RATE_LIMIT_OPTION = 'recovery_mode_email_last_sent'; |
| | 16 | const RATE_LIMIT_OPTION_PREFIX = 'recovery_mode_email_last_sent'; |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Service to generate recovery mode URLs. |
| … |
… |
final class WP_Recovery_Mode_Email_Service { |
| 49 | 49 | */ |
| 50 | 50 | public function maybe_send_recovery_mode_email( $rate_limit, $error, $extension ) { |
| 51 | 51 | |
| 52 | | $last_sent = get_option( self::RATE_LIMIT_OPTION ); |
| | 52 | $last_sent = get_option( $this->get_rate_limit_option_name() ); |
| 53 | 53 | |
| 54 | 54 | if ( ! $last_sent || time() > $last_sent + $rate_limit ) { |
| 55 | | if ( ! update_option( self::RATE_LIMIT_OPTION, time() ) ) { |
| | 55 | if ( ! update_option( $this->get_rate_limit_option_name(), time() ) ) { |
| 56 | 56 | return new WP_Error( 'storage_error', __( 'Could not update the email last sent time.' ) ); |
| 57 | 57 | } |
| 58 | 58 | |
| … |
… |
final class WP_Recovery_Mode_Email_Service { |
| 90 | 90 | * @return bool True on success, false on failure. |
| 91 | 91 | */ |
| 92 | 92 | public function clear_rate_limit() { |
| 93 | | return delete_option( self::RATE_LIMIT_OPTION ); |
| | 93 | return delete_option( $this->get_rate_limit_option_name() ); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
| … |
… |
To keep your site safe, this link will expire in ###EXPIRES###. Don\'t worry abo |
| 272 | 272 | |
| 273 | 273 | return $cause; |
| 274 | 274 | } |
| | 275 | |
| | 276 | /** |
| | 277 | * Centralizes rate limit option name composition. |
| | 278 | * |
| | 279 | * @return string Option key name. |
| | 280 | * @since 5.3.0 |
| | 281 | */ |
| | 282 | private function get_rate_limit_option_name() { |
| | 283 | return sprintf( '%s_%s', self::RATE_LIMIT_OPTION_PREFIX, $this->get_recovery_mode_email_address() );; |
| | 284 | } |
| 275 | 285 | } |