Make WordPress Core

Ticket #55952: 55952-rfc.patch

File 55952-rfc.patch, 3.6 KB (added by karl94, 2 years ago)
  • wp-includes/option.php

    From e098cc8ff486979855b991770184c0511b9e0054 Mon Sep 17 00:00:00 2001
    From: Carlo Cannas <carlo94@gmail.com>
    Date: Thu, 9 Jun 2022 03:11:00 +0200
    Subject: [RFC PATCH 1/2] Options: Always update `notoptions` after `INSERT` in
     `add_option()`
    
    ---
     wp-includes/option.php | 17 +++++++++--------
     1 file changed, 9 insertions(+), 8 deletions(-)
    
    diff --git a/wp-includes/option.php b/wp-includes/option.php
    index a65326f0a6..0a6df2b7e3 100644
    a b function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) 
    638638        do_action( 'add_option', $option, $value );
    639639
    640640        $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) );
     641
     642        // This option exists now.
     643        $notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh.
     644
     645        if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
     646                unset( $notoptions[ $option ] );
     647                wp_cache_set( 'notoptions', $notoptions, 'options' );
     648        }
     649
    641650        if ( ! $result ) {
    642651                return false;
    643652        }
    function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) 
    652661                }
    653662        }
    654663
    655         // This option exists now.
    656         $notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh.
    657 
    658         if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
    659                 unset( $notoptions[ $option ] );
    660                 wp_cache_set( 'notoptions', $notoptions, 'options' );
    661         }
    662 
    663664        /**
    664665         * Fires after a specific option has been added.
    665666         *
  • wp-includes/option.php

    -- 
    2.25.1
    
    
    From 1b7ae2fc8819d087aa5c35a134b7ad61408126e4 Mon Sep 17 00:00:00 2001
    From: Carlo Cannas <carlo94@gmail.com>
    Date: Thu, 9 Jun 2022 03:11:44 +0200
    Subject: [RFC PATCH 2/2] Options: Never update existing options with
     `add_option()`
    
    ---
     wp-includes/option.php | 14 ++++++++++++--
     1 file changed, 12 insertions(+), 2 deletions(-)
    
    diff --git a/wp-includes/option.php b/wp-includes/option.php
    index 0a6df2b7e3..28174d558d 100644
    a b function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) 
    637637         */
    638638        do_action( 'add_option', $option, $value );
    639639
    640         $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) );
     640        $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `autoload` = `autoload`", $option, $serialized_value, $autoload ) );
    641641
    642         // This option exists now.
     642        /*
     643         * This option should exist now:
     644         *  - either we just created it ( $result === 1 ), or
     645         *  - it was already present in the DB ( $result === 0 ).
     646         */
    643647        $notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh.
    644648
    645649        if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
    function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) 
    648652        }
    649653
    650654        if ( ! $result ) {
     655                /*
     656                 * This is reached both:
     657                 *  - in case the query failed ( $result === * false ), or
     658                 *  - it was already present a row with the given
     659                 *    `$option_name` ( $result === 0 ).
     660                 */
    651661                return false;
    652662        }
    653663