WordPress.org

Make WordPress Core

Changeset 27888


Ignore:
Timestamp:
04/01/2014 04:06:27 AM (8 years ago)
Author:
nacin
Message:

Prefix the notoptions cache key in the multisite site-options group with $wpdb->siteid to avoid collisions.

Merges [26304] (and [26305]) from 3.8 to the 3.7 branch.

props wonderboymusic.
fixes #25883.

Location:
branches/3.7
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

  • branches/3.7/src/wp-includes/option.php

    r25926 r27888  
    758758
    759759    // prevent non-existent options from triggering multiple queries
    760     $notoptions = wp_cache_get( 'notoptions', 'site-options' );
     760    $notoptions_key = "{$wpdb->siteid}:notoptions";
     761    $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
    761762    if ( isset( $notoptions[$option] ) )
    762763        return apply_filters( 'default_site_option_' . $option, $default );
     
    780781            } else {
    781782                $notoptions[$option] = true;
    782                 wp_cache_set( 'notoptions', $notoptions, 'site-options' );
     783                wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
    783784                $value = apply_filters( 'default_site_option_' . $option, $default );
    784785            }
     
    813814
    814815    $value = apply_filters( 'pre_add_site_option_' . $option, $value );
     816    $notoptions_key = "{$wpdb->siteid}:notoptions";
    815817
    816818    if ( !is_multisite() ) {
     
    820822
    821823        // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
    822         $notoptions = wp_cache_get( 'notoptions', 'site-options' );
     824        $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
    823825        if ( ! is_array( $notoptions ) || ! isset( $notoptions[$option] ) )
    824826            if ( false !== get_site_option( $option ) )
     
    836838
    837839        // This option exists now
    838         $notoptions = wp_cache_get( 'notoptions', 'site-options' ); // yes, again... we need it to be fresh
     840        $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh
    839841        if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    840842            unset( $notoptions[$option] );
    841             wp_cache_set( 'notoptions', $notoptions, 'site-options' );
     843            wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
    842844        }
    843845    }
     
    923925        return add_site_option( $option, $value );
    924926
    925     $notoptions = wp_cache_get( 'notoptions', 'site-options' );
     927    $notoptions_key = "{$wpdb->siteid}:notoptions";
     928    $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
    926929    if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    927930        unset( $notoptions[$option] );
    928         wp_cache_set( 'notoptions', $notoptions, 'site-options' );
     931        wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
    929932    }
    930933
  • branches/3.7/tests/phpunit/tests/option/siteOption.php

    r25002 r27888  
    9191        $this->assertFalse( get_site_option( $option ) );
    9292    }
     93
     94    /**
     95     * @group multisite
     96     */
     97    function test_site_notoptions() {
     98        if ( ! is_multisite() ) {
     99            $this->markTestSkipped( 'Should only run in multisite' );
     100        }
     101
     102        global $wpdb;
     103        $notoptions_key = "{$wpdb->siteid}:notoptions";
     104
     105        $_notoptions = wp_cache_get( 'notoptions', 'site-options' );
     106        $this->assertEmpty( $_notoptions );
     107        $_notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );
     108        $this->assertEmpty( $_notoptions1 );
     109
     110        get_site_option( 'burrito' );
     111
     112        $notoptions = wp_cache_get( 'notoptions', 'site-options' );
     113        $this->assertEmpty( $notoptions );
     114        $notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );
     115        $this->assertNotEmpty( $notoptions1 );
     116    }
    93117}
Note: See TracChangeset for help on using the changeset viewer.