WordPress.org

Make WordPress Core

Ticket #47352: 47352-lkraav.diff

File 47352-lkraav.diff, 2.2 KB (added by lkraav, 2 years ago)

Update option name strategy (no hashing, because why?)

  • wp-includes/class-wp-recovery-mode-email-service.php

    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  
    1313 */
    1414final class WP_Recovery_Mode_Email_Service {
    1515
    16         const RATE_LIMIT_OPTION = 'recovery_mode_email_last_sent';
     16        const RATE_LIMIT_OPTION_PREFIX = 'recovery_mode_email_last_sent';
    1717
    1818        /**
    1919         * Service to generate recovery mode URLs.
    final class WP_Recovery_Mode_Email_Service { 
    4949         */
    5050        public function maybe_send_recovery_mode_email( $rate_limit, $error, $extension ) {
    5151
    52                 $last_sent = get_option( self::RATE_LIMIT_OPTION );
     52                $last_sent = get_option( $this->get_rate_limit_option_name() );
    5353
    5454                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() ) ) {
    5656                                return new WP_Error( 'storage_error', __( 'Could not update the email last sent time.' ) );
    5757                        }
    5858
    final class WP_Recovery_Mode_Email_Service { 
    9090         * @return bool True on success, false on failure.
    9191         */
    9292        public function clear_rate_limit() {
    93                 return delete_option( self::RATE_LIMIT_OPTION );
     93                return delete_option( $this->get_rate_limit_option_name() );
    9494        }
    9595
    9696        /**
    To keep your site safe, this link will expire in ###EXPIRES###. Don\'t worry abo 
    272272
    273273                return $cause;
    274274        }
     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        }
    275285}