From 7e1caa5b441647891ee78cefa6fc0021c2705d78 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 26 Sep 2023 15:55:18 +0000 Subject: [PATCH] Options, Meta APIs: Fix follow up bug when comparing values for options using the `pre_option_{$option}` filter. This fix is relevant for options such as `gmt_offset` that use a filter to force a specific value regardless of what is stored in the database. Props mamaduka, flixos90, mukesh27, spacedmonkey. See #22192. Built from https://develop.svn.wordpress.org/trunk@56717 git-svn-id: http://core.svn.wordpress.org/trunk@56229 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/option.php | 22 ++++++++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/wp-includes/option.php b/wp-includes/option.php index 2beb5eeef3..e6e276cc1f 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -776,6 +776,24 @@ function update_option( $option, $value, $autoload = null ) { */ $value = apply_filters( 'pre_update_option', $value, $option, $old_value ); + /* + * To get the actual raw old value from the database, any existing pre filters need to be temporarily disabled. + * Immediately after getting the raw value, they are reinstated. + * The raw value is only used to determine whether a value is present in the database. It is not used anywhere + * else, and is not passed to any of the hooks either. + */ + if ( has_filter( "pre_option_{$option}" ) ) { + global $wp_filter; + + $old_filters = $wp_filter[ "pre_option_{$option}" ]; + unset( $wp_filter[ "pre_option_{$option}" ] ); + + $raw_old_value = get_option( $option ); + $wp_filter[ "pre_option_{$option}" ] = $old_filters; + } else { + $raw_old_value = $old_value; + } + /** This filter is documented in wp-includes/option.php */ $default_value = apply_filters( "default_option_{$option}", false, $option, false ); @@ -787,11 +805,11 @@ function update_option( $option, $value, $autoload = null ) { * * See https://core.trac.wordpress.org/ticket/38903 and https://core.trac.wordpress.org/ticket/22192. */ - if ( $old_value !== $default_value && _is_equal_database_value( $old_value, $value ) ) { + if ( $raw_old_value !== $default_value && _is_equal_database_value( $raw_old_value, $value ) ) { return false; } - if ( $old_value === $default_value ) { + if ( $raw_old_value === $default_value ) { // Default setting for new options is 'yes'. if ( null === $autoload ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index a6bd2ff1b3..b42d506292 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56716'; +$wp_version = '6.4-alpha-56717'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.