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' ) |
638 | 638 | do_action( 'add_option', $option, $value ); |
639 | 639 | |
640 | 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 ) ); |
| 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 | |
641 | 650 | if ( ! $result ) { |
642 | 651 | return false; |
643 | 652 | } |
… |
… |
function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) |
652 | 661 | } |
653 | 662 | } |
654 | 663 | |
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 | | |
663 | 664 | /** |
664 | 665 | * Fires after a specific option has been added. |
665 | 666 | * |
--
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' ) |
637 | 637 | */ |
638 | 638 | do_action( 'add_option', $option, $value ); |
639 | 639 | |
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 ) ); |
641 | 641 | |
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 | */ |
643 | 647 | $notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh. |
644 | 648 | |
645 | 649 | if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
… |
… |
function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) |
648 | 652 | } |
649 | 653 | |
650 | 654 | 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 | */ |
651 | 661 | return false; |
652 | 662 | } |
653 | 663 | |