diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php
index 4e3886630d..9b93ad9237 100644
|
a
|
b
|
function wp_load_options( $options ) { |
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
| | 278 | // Filter options that are known not to exist. |
| | 279 | $notoptions = wp_cache_get( 'notoptions', 'options' ); |
| | 280 | if ( ! is_array( $notoptions ) ) { |
| | 281 | $notoptions = array(); |
| | 282 | } |
| | 283 | $options_to_prime = array_diff( $options_to_prime, array_keys( $notoptions ) ); |
| | 284 | |
| | 285 | // Bail early if there are no options to be loaded. |
| | 286 | if ( empty( $options_to_prime ) ) { |
| | 287 | return; |
| | 288 | } |
| | 289 | |
| 278 | 290 | global $wpdb; |
| 279 | 291 | $results = $wpdb->get_results( |
| 280 | 292 | $wpdb->prepare( |
diff --git a/tests/phpunit/tests/option/wpLoadOptions.php b/tests/phpunit/tests/option/wpLoadOptions.php
index bf6a8d5895..0168017a58 100644
|
a
|
b
|
class Tests_Option_PrimeOptions extends WP_UnitTestCase { |
| 96 | 96 | foreach ( $options_to_load as $option ) { |
| 97 | 97 | $this->assertArrayHasKey( $option, $new_notoptions, "$option was not added to the notoptions cache." ); |
| 98 | 98 | } |
| | 99 | |
| | 100 | $initial_num_queries = get_num_queries(); |
| | 101 | |
| | 102 | // Check getting the options does not result in a database query. |
| | 103 | foreach ( $options_to_load as $option ) { |
| | 104 | get_option( $option ); |
| | 105 | $this->assertSame( 0, get_num_queries() - $initial_num_queries, "Loading notoption '{$option}' resulted in a database query." ); |
| | 106 | } |
| | 107 | |
| | 108 | // Check re-loading does not result in a database query. |
| | 109 | wp_load_options( $options_to_load ); |
| | 110 | $this->assertSame( 0, get_num_queries() - $initial_num_queries, 'Reloading resulted in a database query.' ); |
| 99 | 111 | } |
| 100 | 112 | |
| 101 | 113 | /** |
| … |
… |
class Tests_Option_PrimeOptions extends WP_UnitTestCase { |
| 111 | 123 | |
| 112 | 124 | $this->assertSame( $alloptions, wp_cache_get( 'alloptions', 'options' ), 'The alloptions cache was modified.' ); |
| 113 | 125 | $this->assertSame( $notoptions, wp_cache_get( 'notoptions', 'options' ), 'The notoptions cache was modified.' ); |
| | 126 | |
| | 127 | $initial_num_queries = get_num_queries(); |
| | 128 | |
| | 129 | // Check re-loading does not result in a database query. |
| | 130 | wp_load_options( array() ); |
| | 131 | $this->assertSame( 0, get_num_queries() - $initial_num_queries, 'Reloading resulted in a database query.' ); |
| 114 | 132 | } |
| 115 | 133 | |
| 116 | 134 | /** |
| … |
… |
class Tests_Option_PrimeOptions extends WP_UnitTestCase { |
| 126 | 144 | $notoptions = wp_cache_get( 'notoptions', 'options' ); |
| 127 | 145 | $this->assertIsArray( $notoptions, 'The notoptions cache should be an array.' ); |
| 128 | 146 | $this->assertArrayHasKey( 'nonexistent_option', $notoptions, 'nonexistent_option was not added to notoptions.' ); |
| | 147 | |
| | 148 | $initial_num_queries = get_num_queries(); |
| | 149 | |
| | 150 | // Check getting the options does not result in a database query. |
| | 151 | get_option( 'nonexistent_option' ); |
| | 152 | $this->assertSame( 0, get_num_queries() - $initial_num_queries, "Loading notoption 'nonexistent_option' resulted in a database query." ); |
| | 153 | |
| | 154 | // Check re-loading does not result in a database query. |
| | 155 | wp_load_options( array( 'nonexistent_option' ) ); |
| | 156 | $this->assertSame( 0, get_num_queries() - $initial_num_queries, 'Reloading resulted in a database query.' ); |
| 129 | 157 | } |
| 130 | 158 | } |