Make WordPress Core

Ticket #43506: 43506.diff

File 43506.diff, 2.4 KB (added by flixos90, 9 years ago)
  • src/wp-includes/option.php

     
    12471247        $notoptions_key = "$network_id:notoptions";
    12481248        $notoptions     = wp_cache_get( $notoptions_key, 'site-options' );
    12491249
    1250         if ( isset( $notoptions[ $option ] ) ) {
     1250        if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
    12511251
    12521252                /**
    12531253                 * Filters a specific default network option.
    … …  
    12951295                }
    12961296        }
    12971297
     1298        if ( ! is_array( $notoptions ) ) {
     1299                $notoptions = array();
     1300                wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
     1301        }
     1302
    12981303        /**
    12991304         * Filters the value of an existing network option.
    13001305         *
  • tests/phpunit/tests/option/networkOption.php

     
    121121                        array( 'string', false ),
    122122                );
    123123        }
     124
     125        /**
     126         * @ticket 43506
     127         */
     128        public function test_get_network_option_sets_notoptions_if_option_found() {
     129                $network_id     = get_current_network_id();
     130                $notoptions_key = "$network_id:notoptions";
     131
     132                $original_cache = wp_cache_get( $notoptions_key, 'site-options' );
     133                if ( false !== $original_cache ) {
     134                        wp_cache_delete( $notoptions_key, 'site-options' );
     135                }
     136
     137                // Retrieve any existing option.
     138                get_network_option( $network_id, 'site_name' );
     139
     140                $cache = wp_cache_get( $notoptions_key, 'site-options' );
     141                if ( false !== $original_cache ) {
     142                        wp_cache_set( $notoptions_key, $original_cache, 'site-options' );
     143                }
     144
     145                $this->assertSame( array(), $cache );
     146        }
     147
     148        /**
     149         * @ticket 43506
     150         */
     151        public function test_get_network_option_sets_notoptions_if_option_not_found() {
     152                $network_id     = get_current_network_id();
     153                $notoptions_key = "$network_id:notoptions";
     154
     155                $original_cache = wp_cache_get( $notoptions_key, 'site-options' );
     156                if ( false !== $original_cache ) {
     157                        wp_cache_delete( $notoptions_key, 'site-options' );
     158                }
     159
     160                // Retrieve any non-existing option.
     161                get_network_option( $network_id, 'this_does_not_exist' );
     162
     163                $cache = wp_cache_get( $notoptions_key, 'site-options' );
     164                if ( false !== $original_cache ) {
     165                        wp_cache_set( $notoptions_key, $original_cache, 'site-options' );
     166                }
     167
     168                $this->assertSame( array( 'this_does_not_exist' => true ), $cache );
     169        }
    124170}