Make WordPress Core


Ignore:
Timestamp:
09/26/2023 03:53:39 PM (3 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r56681 r56717  
    777777        $value = apply_filters( 'pre_update_option', $value, $option, $old_value );
    778778
     779        /*
     780         * To get the actual raw old value from the database, any existing pre filters need to be temporarily disabled.
     781         * Immediately after getting the raw value, they are reinstated.
     782         * The raw value is only used to determine whether a value is present in the database. It is not used anywhere
     783         * else, and is not passed to any of the hooks either.
     784         */
     785        if ( has_filter( "pre_option_{$option}" ) ) {
     786                global $wp_filter;
     787
     788                $old_filters = $wp_filter[ "pre_option_{$option}" ];
     789                unset( $wp_filter[ "pre_option_{$option}" ] );
     790
     791                $raw_old_value                       = get_option( $option );
     792                $wp_filter[ "pre_option_{$option}" ] = $old_filters;
     793        } else {
     794                $raw_old_value = $old_value;
     795        }
     796
    779797        /** This filter is documented in wp-includes/option.php */
    780798        $default_value = apply_filters( "default_option_{$option}", false, $option, false );
    … …  
    788806         * See https://core.trac.wordpress.org/ticket/38903 and https://core.trac.wordpress.org/ticket/22192.
    789807         */
    790         if ( $old_value !== $default_value && _is_equal_database_value( $old_value, $value ) ) {
     808        if ( $raw_old_value !== $default_value && _is_equal_database_value( $raw_old_value, $value ) ) {
    791809                return false;
    792810        }
    793811
    794         if ( $old_value === $default_value ) {
     812        if ( $raw_old_value === $default_value ) {
    795813
    796814                // Default setting for new options is 'yes'.
Note: See TracChangeset for help on using the changeset viewer.