Make WordPress Core

Changeset 57920


Ignore:
Timestamp:
04/03/2024 09:29:13 PM (7 weeks ago)
Author:
flixos90
Message:

Options, Meta APIs: Use more sensible default for autoloading options which allows WordPress core to make a decision.

An excessive amount of autoloaded options is a common cause for slow database responses, sometimes caused by very large individual autoloaded options. As it is not mandatory to provide an autoload value when adding an option to the database, it tends to be ignored, which in combination with a default value of "yes" and lack of documentation can lead to the aforementioned problem.

This changeset enhances the option autoloading behavior in several ways:

  • Update the function documentation to encourage the use of boolean true or false to explicitly provide an autoload value for an option.
  • Use new string values on and off for explicitly provided values stored in the database, to distinguish them from yes and no, since yes does not allow determining whether it was set intentionally by the developer or only as a default.
  • Effectively deprecate the values yes and no. They are still supported for backward compatibility, but now discouraged.
  • Use null as new default autoload value for add_option(). If the developer does not provide an explicit value, this will now trigger WordPress logic to determine an autoload value to use:
    • If WordPress determines that the option should not be autoloaded, it is stored in the database as auto-off. As part of this changeset, the single heuristic introduced for that is to check whether the option size is larger than a threshold of 150k bytes. This threshold is filterable via a new wp_max_autoloaded_option_size filter.
    • If WordPress determines that the option should be autoloaded, it is stored in the database as auto-on. No logic to make such a decision is introduced as part of this changeset, but a new filter wp_default_autoload_value can be used to define such heuristics, e.g. by optimization plugins.
    • If WordPress cannot determine whether or not to autoload the option, it is stored in the database as auto.
    • This effectively means that any option without an explicit autoload value provided by the developer will be stored with an autoload value of auto, unless the option's size exceeds the aforementioned threshold. Options with a value of auto are still autoloaded as of today, most importantly for backward compatibility. A new function wp_autoload_values_to_autoload() returns the list of autolaod values that dictate for an option to be autoloaded, and a new filter wp_autoload_values_to_autoload can be used to alter that list.

These behavioral changes encourage developers to be more mindful of autoloading, while providing WordPress core and optimization plugins with additional control over heuristics for autoloading options where no explicit autoload value was provided.

At the same time, the changes are fully backward compatible from a functionality perspective, with the only exception being that very large options will now no longer be autoloaded if the developer did not explicitly request for them to be autoloaded. Neither WordPress core nor plugins are able to override an explicitly provided value, which is intentional to continue giving developers full control over their own options.

Props pbearne, flixos90, joemcgill, azaozz, spacedmonkey, swissspidy, mukesh27, markjaquith.
Fixes #42441.

Location:
trunk
Files:
2 added
9 edited

Legend:

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

    r57919 r57920  
    287287
    288288// Misc filters.
     289add_filter( 'wp_default_autoload_value', 'wp_filter_default_autoload_value_via_option_size', 10, 4 );
    289290add_filter( 'option_ping_sites', 'privacy_ping_filter' );
    290291add_filter( 'option_blog_charset', '_wp_specialchars' ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop.
  • trunk/src/wp-includes/option.php

    r57110 r57920  
    393393
    394394    $grouped_options = array(
    395         'yes' => array(),
    396         'no' => array(),
     395        'on' => array(),
     396        'off' => array(),
    397397    );
    398398    $results         = array();
    399399    foreach ( $options as $option => $autoload ) {
    400400        wp_protect_special_option( $option ); // Ensure only valid options can be passed.
    401         if ( 'no' === $autoload || false === $autoload ) { // Sanitize autoload value and categorize accordingly.
    402             $grouped_options['no'][] = $option;
     401        if ( 'off' === $autoload || 'no' === $autoload || false === $autoload ) { // Sanitize autoload value and categorize accordingly.
     402            $grouped_options['off'][] = $option;
    403403        } else {
    404             $grouped_options['yes'][] = $option;
     404            $grouped_options['on'][] = $option;
    405405        }
    406406        $results[ $option ] = false; // Initialize result value.
     
    466466
    467467    /*
    468      * If any options were changed to 'yes', delete their individual caches, and delete 'alloptions' cache so that it
     468     * If any options were changed to 'on', delete their individual caches, and delete 'alloptions' cache so that it
    469469     * is refreshed as needed.
    470      * If no options were changed to 'yes' but any options were changed to 'no', delete them from the 'alloptions'
    471      * cache. This is not necessary when options were changed to 'yes', since in that situation the entire cache is
     470     * If no options were changed to 'on' but any options were changed to 'no', delete them from the 'alloptions'
     471     * cache. This is not necessary when options were changed to 'on', since in that situation the entire cache is
    472472     * deleted anyway.
    473473     */
    474     if ( $grouped_options['yes'] ) {
    475         wp_cache_delete_multiple( $grouped_options['yes'], 'options' );
     474    if ( $grouped_options['on'] ) {
     475        wp_cache_delete_multiple( $grouped_options['on'], 'options' );
    476476        wp_cache_delete( 'alloptions', 'options' );
    477     } elseif ( $grouped_options['no'] ) {
     477    } elseif ( $grouped_options['off'] ) {
    478478        $alloptions = wp_load_alloptions( true );
    479479
    480         foreach ( $grouped_options['no'] as $option ) {
     480        foreach ( $grouped_options['off'] as $option ) {
    481481            if ( isset( $alloptions[ $option ] ) ) {
    482482                unset( $alloptions[ $option ] );
     
    607607    if ( ! $alloptions ) {
    608608        $suppress      = $wpdb->suppress_errors();
    609         $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" );
     609        $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload IN ( '" . implode( "', '", wp_autoload_values_to_autoload() ) . "' )" );
     610
    610611        if ( ! $alloptions_db ) {
    611612            $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
     
    706707 * @global wpdb $wpdb WordPress database abstraction object.
    707708 *
    708  * @param string      $option   Name of the option to update. Expected to not be SQL-escaped.
    709  * @param mixed       $value    Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
    710  * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options,
    711  *                              `$autoload` can only be updated using `update_option()` if `$value` is also changed.
    712  *                              Accepts 'yes'|true to enable or 'no'|false to disable.
    713  *                              Autoloading too many options can lead to performance problems, especially if the
    714  *                              options are not frequently used. For options which are accessed across several places
    715  *                              in the frontend, it is recommended to autoload them, by using 'yes'|true.
    716  *                              For options which are accessed only on few specific URLs, it is recommended
    717  *                              to not autoload them, by using 'no'|false. For non-existent options, the default value
    718  *                              is 'yes'. Default null.
     709 * @param string    $option   Name of the option to update. Expected to not be SQL-escaped.
     710 * @param mixed     $value    Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
     711 * @param bool|null $autoload Optional. Whether to load the option when WordPress starts up.
     712 *                            Accepts a boolean, or `null` to stick with the initial value or, if no initial value is set,
     713 *                            to leave the decision up to default heuristics in WordPress.
     714 *                            For existing options,
     715 *                            `$autoload` can only be updated using `update_option()` if `$value` is also changed.
     716 *                            For backward compatibility 'yes' and 'no' are also accepted.
     717 *                            Autoloading too many options can lead to performance problems, especially if the
     718 *                            options are not frequently used. For options which are accessed across several places
     719 *                            in the frontend, it is recommended to autoload them, by using true.
     720 *                            For options which are accessed only on few specific URLs, it is recommended
     721 *                            to not autoload them, by using false.
     722 *                            For non-existent options, the default is null, which means WordPress will determine
     723 *                            the autoload value.
    719724 * @return bool True if the value was updated, false otherwise.
    720725 */
     
    802807    /** This filter is documented in wp-includes/option.php */
    803808    if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) {
    804         // Default setting for new options is 'yes'.
    805         if ( null === $autoload ) {
    806             $autoload = 'yes';
    807         }
    808 
    809809        return add_option( $option, $value, '', $autoload );
    810810    }
     
    828828
    829829    if ( null !== $autoload ) {
    830         $update_args['autoload'] = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
     830        $update_args['autoload'] = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload );
     831    } else {
     832        // Retrieve the current autoload value to reevaluate it in case it was set automatically.
     833        $raw_autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
     834        $allow_values = array( 'auto-on', 'auto-off', 'auto' );
     835        if ( in_array( $raw_autoload, $allow_values, true ) ) {
     836            $autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload );
     837            if ( $autoload !== $raw_autoload ) {
     838                $update_args['autoload'] = $autoload;
     839            }
     840        }
    831841    }
    832842
     
    854864                wp_cache_set( $option, $serialized_value, 'options' );
    855865            }
    856         } elseif ( 'yes' === $update_args['autoload'] ) {
     866        } elseif ( in_array( $update_args['autoload'], wp_autoload_values_to_autoload(), true ) ) {
    857867            // Delete the individual cache, then set in alloptions cache.
    858868            wp_cache_delete( $option, 'options' );
     
    916926 *
    917927 * @since 1.0.0
     928 * @since 6.6.0 The $autoload parameter's default value was changed to null.
    918929 *
    919930 * @global wpdb $wpdb WordPress database abstraction object.
    920931 *
    921  * @param string      $option     Name of the option to add. Expected to not be SQL-escaped.
    922  * @param mixed       $value      Optional. Option value. Must be serializable if non-scalar.
    923  *                                Expected to not be SQL-escaped.
    924  * @param string      $deprecated Optional. Description. Not used anymore.
    925  * @param string|bool $autoload   Optional. Whether to load the option when WordPress starts up.
    926  *                                Accepts 'yes'|true to enable or 'no'|false to disable.
    927  *                                Autoloading too many options can lead to performance problems, especially if the
    928  *                                options are not frequently used. For options which are accessed across several places
    929  *                                in the frontend, it is recommended to autoload them, by using 'yes'|true.
    930  *                                For options which are accessed only on few specific URLs, it is recommended
    931  *                                to not autoload them, by using 'no'|false. Default 'yes'.
     932 * @param string    $option     Name of the option to add. Expected to not be SQL-escaped.
     933 * @param mixed     $value      Optional. Option value. Must be serializable if non-scalar.
     934 *                              Expected to not be SQL-escaped.
     935 * @param string    $deprecated Optional. Description. Not used anymore.
     936 * @param bool|null $autoload   Optional. Whether to load the option when WordPress starts up.
     937 *                              Accepts a boolean, or `null` to leave the decision up to default heuristics in WordPress.
     938 *                              For backward compatibility 'yes' and 'no' are also accepted.
     939 *                              Autoloading too many options can lead to performance problems, especially if the
     940 *                              options are not frequently used. For options which are accessed across several places
     941 *                              in the frontend, it is recommended to autoload them, by using 'yes'|true.
     942 *                              For options which are accessed only on few specific URLs, it is recommended
     943 *                              to not autoload them, by using false.
     944 *                              Default is null, which means WordPress will determine the autoload value.
    932945 * @return bool True if the option was added, false otherwise.
    933946 */
    934 function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
     947function add_option( $option, $value = '', $deprecated = '', $autoload = null ) {
    935948    global $wpdb;
    936949
     
    9921005
    9931006    $serialized_value = maybe_serialize( $value );
    994     $autoload         = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
     1007
     1008    $autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload );
    9951009
    9961010    /**
     
    10101024
    10111025    if ( ! wp_installing() ) {
    1012         if ( 'yes' === $autoload ) {
     1026        if ( in_array( $autoload, wp_autoload_values_to_autoload(), true ) ) {
    10131027            $alloptions            = wp_load_alloptions( true );
    10141028            $alloptions[ $option ] = $serialized_value;
     
    10941108
    10951109    if ( ! wp_installing() ) {
    1096         if ( 'yes' === $row->autoload ) {
     1110        if ( in_array( $row->autoload, wp_autoload_values_to_autoload(), true ) ) {
    10971111            $alloptions = wp_load_alloptions( true );
    10981112
     
    11321146
    11331147    return false;
     1148}
     1149
     1150/**
     1151 *  Determines the appropriate autoload value for an option based on input.
     1152 *
     1153 *  This function checks the provided autoload value and returns a standardized value
     1154 *  ('on', 'off', 'auto-on', 'auto-off', or 'auto') based on specific conditions.
     1155 *
     1156 * If no explicit autoload value is provided, the function will check for certain heuristics around the given option.
     1157 * It will return `auto-on` to indicate autoloading, `auto-off` to indicate not autoloading, or `auto` if no clear
     1158 * decision could be made.
     1159 *
     1160 * @since 6.6.0
     1161 * @access private
     1162 *
     1163 * @param string $option          The name of the option.
     1164 * @param mixed $value            The value of the option to check its autoload value.
     1165 * @param mixed $serialized_value The serialized value of the option to check its autoload value.
     1166 * @param bool|null $autoload     The autoload value to check.
     1167 *                                Accepts 'on'|true to enable or 'off'|false to disable, or
     1168 *                                'auto-on', 'auto-off', or 'auto' for internal purposes.
     1169 *                                Any other autoload value will be forced to either 'auto-on',
     1170 *                                'auto-off', or 'auto'.
     1171 *                                'yes' and 'no' are supported for backward compatibility.
     1172 * @return string Returns the original $autoload value if explicit, or 'auto-on', 'auto-off',
     1173 *                or 'auto' depending on default heuristics.
     1174 */
     1175function wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ) {
     1176
     1177    // Check if autoload is a boolean.
     1178    if ( is_bool( $autoload ) ) {
     1179        return $autoload ? 'on' : 'off';
     1180    }
     1181
     1182    switch ( $autoload ) {
     1183        case 'on':
     1184        case 'yes':
     1185            return 'on';
     1186        case 'off':
     1187        case 'no':
     1188            return 'off';
     1189    }
     1190
     1191    /**
     1192     * Allows to determine the default autoload value for an option where no explicit value is passed.
     1193     *
     1194     * @since 6.6.0
     1195     *
     1196     * @param bool|null $autoload The default autoload value to set. Returning true will be set as 'auto-on' in the
     1197     *                            database, false will be set as 'auto-off', and null will be set as 'auto'.
     1198     * @param string    $option   The passed option name.
     1199     * @param mixed     $value    The passed option value to be saved.
     1200     */
     1201    $autoload = apply_filters( 'wp_default_autoload_value', null, $option, $value, $serialized_value );
     1202    if ( is_bool( $autoload ) ) {
     1203        return $autoload ? 'auto-on' : 'auto-off';
     1204    }
     1205
     1206    return 'auto';
     1207}
     1208
     1209/**
     1210 * Filters the default autoload value to disable autoloading if the option value is too large.
     1211 *
     1212 * @since 6.6.0
     1213 * @access private
     1214 *
     1215 * @param bool|null $autoload         The default autoload value to set.
     1216 * @param string    $option           The passed option name.
     1217 * @param mixed     $value            The passed option value to be saved.
     1218 * @param mixed     $serialized_value The passed option value to be saved, in serialized form.
     1219 * @return bool|null Potentially modified $default.
     1220 */
     1221function wp_filter_default_autoload_value_via_option_size( $autoload, $option, $value, $serialized_value ) {
     1222    /**
     1223     * Filters the maximum size of option value in bytes.
     1224     *
     1225     * @since 6.6.0
     1226     *
     1227     * @param int    $max_option_size The option-size threshold, in bytes. Default 150000.
     1228     * @param string $option          The name of the option.
     1229     */
     1230    $max_option_size = (int) apply_filters( 'wp_max_autoloaded_option_size', 150000, $option );
     1231    $size            = ! empty( $serialized_value ) ? strlen( $serialized_value ) : 0;
     1232
     1233    if ( $size > $max_option_size ) {
     1234        return false;
     1235    }
     1236
     1237    return $autoload;
    11341238}
    11351239
     
    29253029    return $registered[ $option ]['default'];
    29263030}
     3031
     3032/**
     3033 * Returns the values that trigger autoloading from the options table.
     3034 *
     3035 * @since 6.6.0
     3036 *
     3037 * @return array The values that trigger autoloading.
     3038 */
     3039function wp_autoload_values_to_autoload() {
     3040    $autoload_values = array( 'yes', 'on', 'auto-on', 'auto' );
     3041
     3042    /**
     3043     * Filters the autoload values that should be considered for autoloading from the options table.
     3044     *
     3045     * The filter can only be used to remove autoload values from the default list.
     3046     *
     3047     * @since 6.6.0
     3048     *
     3049     * @param array $autoload_values Autoload values used to autoload option.
     3050     *                               Default list contains 'yes', 'on', 'auto-on', and 'auto'.
     3051     */
     3052    $filtered_values = apply_filters( 'wp_autoload_values_to_autoload', $autoload_values );
     3053
     3054    return array_intersect( $filtered_values, $autoload_values );
     3055}
  • trunk/tests/phpunit/tests/customize/setting.php

    r56536 r57920  
    611611        $setting->save();
    612612        $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) );
    613         $this->assertSame( 'yes', $autoload );
     613        $this->assertSame( 'on', $autoload );
    614614        $this->assertSame( $value, get_option( $name ) );
    615615
     
    627627        $setting->save();
    628628        $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) );
    629         $this->assertSame( 'yes', $autoload );
     629        $this->assertSame( 'on', $autoload );
    630630        $this->assertSame( $value, get_option( $name ) );
    631631
     
    643643        $setting->save();
    644644        $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) );
    645         $this->assertSame( 'no', $autoload );
     645        $this->assertSame( 'off', $autoload );
    646646        $this->assertSame( $value, get_option( $name ) );
    647647
     
    666666        $setting1->save();
    667667        $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $id_base ) );
    668         $this->assertSame( 'no', $autoload, 'Even though setting1 did not indicate autoload (thus normally true), since another multidimensional option setting of the base did say autoload=false, it should be autoload=no' );
     668        $this->assertSame( 'off', $autoload, 'Even though setting1 did not indicate autoload (thus normally true), since another multidimensional option setting of the base did say autoload=false, it should be autoload=no' );
    669669    }
    670670
  • trunk/tests/phpunit/tests/option/option.php

    r56946 r57920  
    309309            'string 123'   => array( '123' ),
    310310            'integer 123'  => array( 123 ),
    311             'integer -123' => array( -123 ),
     311            'integer -123' => array( - 123 ),
    312312            'float 12.3'   => array( 12.3 ),
    313             'float -1.23'  => array( -1.23 ),
     313            'float -1.23'  => array( - 1.23 ),
    314314            'boolean true' => array( true ),
    315315        );
     
    360360    public function data_option_autoloading() {
    361361        return array(
    362             array( 'autoload_yes', 'yes', 'yes' ),
    363             array( 'autoload_true', true, 'yes' ),
    364             array( 'autoload_string', 'foo', 'yes' ),
    365             array( 'autoload_int', 123456, 'yes' ),
    366             array( 'autoload_array', array(), 'yes' ),
    367             array( 'autoload_no', 'no', 'no' ),
    368             array( 'autoload_false', false, 'no' ),
    369         );
     362            // Supported values.
     363            array( 'autoload_yes', 'yes', 'on' ),
     364            array( 'autoload_true', true, 'on' ),
     365            array( 'autoload_no', 'no', 'off' ),
     366            array( 'autoload_false', false, 'off' ),
     367            array( 'autoload_null', null, 'auto' ),
     368
     369            // Technically unsupported values.
     370            array( 'autoload_string', 'foo', 'auto' ),
     371            array( 'autoload_int', 123456, 'auto' ),
     372            array( 'autoload_array', array(), 'auto' ),
     373        );
     374    }
     375
     376    /**
     377     * @ticket 42441
     378     *
     379     * @covers ::update_option
     380     *
     381     * @dataProvider data_option_autoloading_large_option
     382     */
     383    public function test_update_option_autoloading_large_option( $autoload, $expected ) {
     384        global $wpdb;
     385        $name = 'foo';
     386        add_option( $name, 'bar' );
     387        add_filter( 'wp_max_autoloaded_option_size', array( $this, 'filter_max_option_size' ) );
     388        $value   = file( DIR_TESTDATA . '/formatting/entities.txt' );
     389        $updated = update_option( $name, $value, $autoload );
     390        $this->assertTrue( $updated );
     391
     392        $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $name ) );
     393        $this->assertSame( $expected, $actual->autoload );
     394    }
     395
     396    public function data_option_autoloading_large_option() {
     397        return array(
     398            'on'    => array(
     399                'autoload' => 'on',
     400                'expected' => 'on',
     401            ),
     402            'off'   => array(
     403                'autoload' => 'off',
     404                'expected' => 'off',
     405            ),
     406            'yes'   => array(
     407                'autoload' => 'yes',
     408                'expected' => 'on',
     409            ),
     410            'true'  => array(
     411                'autoload' => true,
     412                'expected' => 'on',
     413            ),
     414            'no'    => array(
     415                'autoload' => 'no',
     416                'expected' => 'off',
     417            ),
     418            'false' => array(
     419                'autoload' => false,
     420                'expected' => 'off',
     421            ),
     422            'null'  => array(
     423                'autoload' => null,
     424                'expected' => 'auto-off',
     425            ),
     426        );
     427    }
     428
     429    public function filter_max_option_size( $current ) {
     430        return 1000;
     431    }
     432
     433    /**
     434     * @ticket 42441
     435     *
     436     * @covers ::update_option
     437     */
     438    public function test_update_option_autoloading_small_option_auto() {
     439        global $wpdb;
     440
     441        $name = 'foo';
     442        add_option( $name, 'bar' );
     443        $updated = update_option( $name, 'small_option_data' );
     444        $this->assertTrue( $updated );
     445
     446        $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $name ) );
     447        $this->assertSame( 'auto', $actual->autoload );
    370448    }
    371449
  • trunk/tests/phpunit/tests/option/wpLoadAlloptions.php

    r55745 r57920  
    1818    public function test_if_alloptions_is_cached() {
    1919        $this->assertNotEmpty( wp_cache_get( 'alloptions', 'options' ) );
     20    }
     21
     22    /**
     23     * @ticket 42441
     24     *
     25     * @covers ::wp_load_alloptions
     26     */
     27    public function test_default_and_yes() {
     28        add_option( 'foo', 'bar' );
     29        add_option( 'bar', 'foo', '', 'yes' );
     30        $alloptions = wp_load_alloptions();
     31        $this->assertArrayHasKey( 'foo', $alloptions );
     32        $this->assertArrayHasKey( 'bar', $alloptions );
     33    }
     34
     35    /**
     36     * @ticket 42441
     37     *
     38     * @covers ::wp_load_alloptions
     39     */
     40    public function test_default_and_no() {
     41        add_option( 'foo', 'bar' );
     42        add_option( 'bar', 'foo', '', 'no' );
     43        $alloptions = wp_load_alloptions();
     44        $this->assertArrayHasKey( 'foo', $alloptions );
     45        $this->assertArrayNotHasKey( 'bar', $alloptions );
    2046    }
    2147
  • trunk/tests/phpunit/tests/option/wpSetOptionAutoload.php

    r56508 r57920  
    2323
    2424        $this->assertTrue( wp_set_option_autoload( $option, 'yes' ), 'Function did not succeed' );
    25         $this->assertSame( 'yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );
     25        $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );
    2626        $this->assertFalse( wp_cache_get( $option, 'options' ), 'Option not deleted from individual cache' );
    2727        $this->assertFalse( wp_cache_get( 'alloptions', 'options' ), 'Alloptions cache not cleared' );
     
    4242
    4343        $this->assertTrue( wp_set_option_autoload( $option, 'no' ), 'Function did not succeed' );
    44         $this->assertSame( 'no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );
     44        $this->assertSame( 'off', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );
    4545        $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), 'Option not deleted from alloptions cache' );
    4646    }
     
    6060
    6161        $this->assertFalse( wp_set_option_autoload( $option, 'yes' ), 'Function did unexpectedly succeed' );
    62         $this->assertSame( 'yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value unexpectedly updated in database' );
     62        $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value unexpectedly updated in database' );
    6363    }
    6464
     
    9393
    9494        $this->assertTrue( wp_set_option_autoload( $option, true ), 'Function did not succeed' );
    95         $this->assertSame( 'yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );
     95        $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );
    9696    }
    9797
     
    110110
    111111        $this->assertTrue( wp_set_option_autoload( $option, false ), 'Function did not succeed' );
    112         $this->assertSame( 'no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );
     112        $this->assertSame( 'off', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );
    113113    }
    114114}
  • trunk/tests/phpunit/tests/option/wpSetOptionAutoloadValues.php

    r56559 r57920  
    3131        $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' );
    3232        $this->assertSame( $num_queries + 2, get_num_queries(), 'Function made unexpected amount of database queries' );
    33         $this->assertSame( array( 'yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     33        $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    3434        foreach ( $options as $option => $autoload ) {
    3535            $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) );
     
    6262        $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' );
    6363        $this->assertSame( $num_queries + 2, get_num_queries(), 'Function made unexpected amount of database queries' );
    64         $this->assertSame( array( 'no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     64        $this->assertSame( array( 'off', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    6565        foreach ( $options as $option => $autoload ) {
    6666            $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s not deleted from alloptions cache', $option ) );
     
    9090        $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' );
    9191        $this->assertSame( $num_queries + 1, get_num_queries(), 'Function made unexpected amount of database queries' );
    92         $this->assertSame( array( 'yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     92        $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    9393        foreach ( $options as $option => $autoload ) {
    9494            $this->assertArrayHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s unexpectedly deleted from alloptions cache', $option ) );
     
    125125        $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' );
    126126        $this->assertSame( $num_queries + 3, get_num_queries(), 'Function made unexpected amount of database queries' );
    127         $this->assertSameSets( array( 'yes', 'no', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     127        $this->assertSameSets( array( 'on', 'off', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    128128        foreach ( $options as $option => $autoload ) {
    129129            $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) );
     
    159159        $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' );
    160160        $this->assertSame( $num_queries + 2, get_num_queries(), 'Function made unexpected amount of database queries' );
    161         $this->assertSameSets( array( 'yes', 'no', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     161        $this->assertSameSets( array( 'on', 'off', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    162162        foreach ( $options as $option => $autoload ) {
    163163            if ( 'no' === $autoload ) {
     
    200200
    201201        $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' );
    202         $this->assertSame( array( 'no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     202        $this->assertSame( array( 'off', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    203203    }
    204204
     
    225225        $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' );
    226226        $this->assertSame( $num_queries + 3, get_num_queries(), 'Function made unexpected amount of database queries' );
    227         $this->assertSameSets( array( 'yes', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     227        $this->assertSameSets( array( 'on', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    228228    }
    229229
  • trunk/tests/phpunit/tests/option/wpSetOptionsAutoload.php

    r56508 r57920  
    3131        $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function did not succeed' );
    3232        $this->assertSame( $num_queries + 2, get_num_queries(), 'Updating options autoload value ran too many queries' );
    33         $this->assertSame( array( 'yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     33        $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    3434        foreach ( $options as $option => $value ) {
    3535            $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) );
     
    6060        $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'no' ), 'Function did not succeed' );
    6161        $this->assertSame( $num_queries + 2, get_num_queries(), 'Updating options autoload value ran too many queries' );
    62         $this->assertSame( array( 'no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     62        $this->assertSame( array( 'off', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    6363        foreach ( $options as $option => $value ) {
    6464            $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s not deleted from alloptions cache', $option ) );
     
    8888        $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function did unexpectedly succeed' );
    8989        $this->assertSame( $num_queries + 1, get_num_queries(), 'Function attempted to update options autoload value in database' );
    90         $this->assertSame( array( 'yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Options autoload value unexpectedly updated in database' );
     90        $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Options autoload value unexpectedly updated in database' );
    9191    }
    9292
     
    134134
    135135        $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function produced unexpected result' );
    136         $this->assertSame( array( 'yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     136        $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    137137        foreach ( $options as $option => $value ) {
    138138            $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) );
     
    162162
    163163        $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), true ), 'Function produced unexpected result' );
    164         $this->assertSame( array( 'yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     164        $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    165165    }
    166166
     
    186186
    187187        $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), false ), 'Function produced unexpected result' );
    188         $this->assertSame( array( 'no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
     188        $this->assertSame( array( 'off', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    189189    }
    190190}
  • trunk/tests/phpunit/tests/theme/autoloadThemeMods.php

    r57153 r57920  
    2929        switch_theme( $new_theme_stylesheet );
    3030
    31         $this->assertSame( 'no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' );
    32         $this->assertSame( 'yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' );
     31        $this->assertSame( 'off', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' );
     32        $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' );
    3333
    3434        switch_theme( $current_theme_stylesheet );
    3535
    36         $this->assertSame( 'yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' );
    37         $this->assertSame( 'no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' );
     36        $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' );
     37        $this->assertSame( 'off', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' );
    3838
    3939        // Basic assertion to make sure that we haven't lost the mods.
Note: See TracChangeset for help on using the changeset viewer.