Make WordPress Core

Changeset 37223


Ignore:
Timestamp:
04/16/2016 07:47:14 PM (9 years ago)
Author:
jeremyfelt
Message:

Options: Do not set network options to autoload in single site

When multisite is not configured, the _site_transient() and _site_option() functions fallback to _option() and store network "meta/options" in wp_options.

Previously, those calls to _option() did not explicitly set the autoload parameter and anything assigned as a transient or option at the network level would be set to autoload by default, even though autoload is not yet a concept at the network option level.

This changes that behavior and forces the autoload setting to no. If autoload is desired, the single site option functions should be used.

Props thomaswm.
Fixes #22846.

Location:
trunk
Files:
3 edited

Legend:

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

    r36234 r37223  
    12241224
    12251225    if ( ! is_multisite() ) {
    1226         $result = add_option( $option, $value );
     1226        $result = add_option( $option, $value, '', 'no' );
    12271227    } else {
    12281228        $cache_key = "$network_id:$option";
     
    14321432
    14331433    if ( ! is_multisite() ) {
    1434         $result = update_option( $option, $value );
     1434        $result = update_option( $option, $value, 'no' );
    14351435    } else {
    14361436        $value = sanitize_option( $option, $value );
  • trunk/tests/phpunit/tests/option/networkOption.php

    r37222 r37223  
    5454
    5555    /**
     56     * @ticket 22846
     57     */
     58    public function test_add_network_option_is_not_stored_as_autoload_option() {
     59        $key = rand_str();
     60
     61        if ( is_multisite() ) {
     62            $this->markTestSkipped( 'Does not apply when used in multisite.' );
     63        }
     64
     65        add_network_option( null, $key, 'Not an autoload option' );
     66
     67        $options = wp_load_alloptions();
     68
     69        $this->assertFalse( isset( $options[ $key ] ) );
     70    }
     71
     72    /**
     73     * @ticket 22846
     74     */
     75    public function test_update_network_option_is_not_stored_as_autoload_option() {
     76        $key = rand_str();
     77
     78        if ( is_multisite() ) {
     79            $this->markTestSkipped( 'Does not apply when used in multisite.' );
     80        }
     81
     82        update_network_option( null, $key, 'Not an autoload option' );
     83
     84        $options = wp_load_alloptions();
     85
     86        $this->assertFalse( isset( $options[ $key ] ) );
     87    }
     88
     89    /**
    5690     * @dataProvider data_network_id_parameter
    5791     *
  • trunk/tests/phpunit/tests/option/siteTransient.php

    r34767 r37223  
    4242        $this->assertTrue( delete_site_transient( $key ) );
    4343    }
     44
     45    /**
     46     * @ticket 22846
     47     */
     48    public function test_set_site_transient_is_not_stored_as_autoload_option() {
     49        $key = rand_str();
     50
     51        if ( is_multisite() ) {
     52            $this->markTestSkipped( 'Does not apply when used in multisite.' );
     53        }
     54        set_site_transient( $key, 'Not an autoload option' );
     55
     56        $options = wp_load_alloptions();
     57
     58        $this->assertFalse( isset( $options[ '_site_transient_' . $key ] ) );
     59    }
    4460}
Note: See TracChangeset for help on using the changeset viewer.