Ticket #37181: 37181.9.diff
File 37181.9.diff, 20.1 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-network-query.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
111 111 * @type array $path__not_in Array of paths to exclude affiliated networks for. Default empty. 112 112 * @type string $search Search term(s) to retrieve matching networks for. Default empty. 113 113 * @type bool $update_network_cache Whether to prime the cache for found networks. Default true. 114 * @type bool $update_network_meta_cache Whether to prime the metadata (option) cache for found networks. 115 * Default true. 114 116 * } 115 117 */ 116 118 public function __construct( $query = '' ) { … … 132 134 'path__not_in' => '', 133 135 'search' => '', 134 136 'update_network_cache' => true, 137 'update_network_meta_cache' => true, 138 135 139 ); 136 140 137 141 if ( ! empty( $query ) ) { … … 243 247 } 244 248 245 249 if ( $this->query_vars['update_network_cache'] ) { 246 _prime_network_caches( $network_ids );250 _prime_network_caches( $network_ids, $this->query_vars['update_network_meta_cache'] ); 247 251 } 248 252 249 253 // Fetch full network objects from the primed cache. -
src/wp-includes/load.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
581 581 } 582 582 583 583 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 584 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) );584 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta', 'site_meta' ) ); 585 585 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 586 586 } 587 587 -
src/wp-includes/ms-blogs.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
1046 1046 if ( is_array( $global_groups ) ) { 1047 1047 wp_cache_add_global_groups( $global_groups ); 1048 1048 } else { 1049 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );1049 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta', 'site_meta' ) ); 1050 1050 } 1051 1051 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 1052 1052 } … … 1114 1114 if ( is_array( $global_groups ) ) { 1115 1115 wp_cache_add_global_groups( $global_groups ); 1116 1116 } else { 1117 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );1117 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta', 'site_meta' ) ); 1118 1118 } 1119 1119 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 1120 1120 } … … 1394 1394 1395 1395 foreach ( (array) $ids as $id ) { 1396 1396 wp_cache_delete( $id, 'networks' ); 1397 wp_cache_delete( $id, 'site_meta' ); 1397 1398 1398 1399 /** 1399 1400 * Fires immediately after a network has been removed from the object cache. … … 1416 1417 * cache using the network group with the key using the ID of the networks. 1417 1418 * 1418 1419 * @since 4.6.0 1420 * @since 5.0.0 Introduced the `$update_meta_cache` parameter. 1419 1421 * 1420 1422 * @param array $networks Array of network row objects. 1423 * @param bool $update_meta_cache Whether to update sitemeta cache. Default true. 1421 1424 */ 1422 function update_network_cache( $networks ) { 1425 function update_network_cache( $networks, $update_meta_cache = true ) { 1426 $network_ids = array(); 1423 1427 foreach ( (array) $networks as $network ) { 1428 $network_ids[] = $network->id; 1424 1429 wp_cache_add( $network->id, $network, 'networks' ); 1425 1430 } 1431 if ( $update_meta_cache ) { 1432 update_meta_cache( 'site', $network_ids ); 1433 } 1426 1434 } 1427 1435 1428 1436 /** 1429 1437 * Adds any networks from the given IDs to the cache that do not already exist in cache. 1430 1438 * 1431 1439 * @since 4.6.0 1440 * @since 5.0.0 Introduced the `$update_meta_cache` parameter. 1432 1441 * @access private 1433 1442 * 1434 1443 * @see update_network_cache() 1435 1444 * @global wpdb $wpdb WordPress database abstraction object. 1436 1445 * 1437 1446 * @param array $network_ids Array of network IDs. 1447 * @param bool $update_meta_cache Whether to update sitemeta cache. Default true. 1438 1448 */ 1439 function _prime_network_caches( $network_ids ) {1449 function _prime_network_caches( $network_ids, $update_meta_cache = true ) { 1440 1450 global $wpdb; 1441 1451 1442 1452 $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); 1443 1453 if ( ! empty( $non_cached_ids ) ) { 1444 1454 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); 1445 1455 1446 update_network_cache( $fresh_networks );1456 update_network_cache( $fresh_networks, $update_meta_cache ); 1447 1457 } 1448 1458 } 1449 1459 -
src/wp-includes/option.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
236 236 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used. 237 237 * 238 238 * @since 3.0.0 239 * 240 * @global wpdb $wpdb WordPress database abstraction object. 239 * @since 5.0.0 Uses update_meta_cache 241 240 * 242 241 * @param int $network_id Optional site ID for which to query the options. Defaults to the current site. 243 242 */ 244 243 function wp_load_core_site_options( $network_id = null ) { 245 global $wpdb;246 244 247 245 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) { 248 246 return; … … 252 250 $network_id = get_current_network_id(); 253 251 } 254 252 255 $core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' ); 256 257 $core_options_in = "'" . implode( "', '", $core_options ) . "'"; 258 $options = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) ); 259 260 foreach ( $options as $option ) { 261 $key = $option->meta_key; 262 $cache_key = "{$network_id}:$key"; 263 $option->meta_value = maybe_unserialize( $option->meta_value ); 264 265 wp_cache_set( $cache_key, $option->meta_value, 'site-options' ); 266 } 253 update_meta_cache( 'site', $network_id ); 267 254 } 268 255 269 256 /** … … 1243 1230 return $pre; 1244 1231 } 1245 1232 1246 // prevent non-existent options from triggering multiple queries 1247 $notoptions_key = "$network_id:notoptions"; 1248 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1249 1250 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1251 1252 /** 1253 * Filters a specific default network option. 1254 * 1255 * The dynamic portion of the hook name, `$option`, refers to the option name. 1256 * 1257 * @since 3.4.0 1258 * @since 4.4.0 The `$option` parameter was added. 1259 * @since 4.7.0 The `$network_id` parameter was added. 1260 * 1261 * @param mixed $default The value to return if the site option does not exist 1262 * in the database. 1263 * @param string $option Option name. 1264 * @param int $network_id ID of the network. 1265 */ 1266 return apply_filters( "default_site_option_{$option}", $default, $option, $network_id ); 1267 } 1268 1269 if ( ! is_multisite() ) { 1270 /** This filter is documented in wp-includes/option.php */ 1271 $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1272 $value = get_option( $option, $default ); 1273 } else { 1274 $cache_key = "$network_id:$option"; 1275 $value = wp_cache_get( $cache_key, 'site-options' ); 1276 1277 if ( ! isset( $value ) || false === $value ) { 1278 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1279 1280 // Has to be get_row instead of get_var because of funkiness with 0, false, null values 1281 if ( is_object( $row ) ) { 1282 $value = $row->meta_value; 1283 $value = maybe_unserialize( $value ); 1284 wp_cache_set( $cache_key, $value, 'site-options' ); 1285 } else { 1286 if ( ! is_array( $notoptions ) ) { 1287 $notoptions = array(); 1288 } 1289 $notoptions[ $option ] = true; 1290 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1291 1292 /** This filter is documented in wp-includes/option.php */ 1293 $value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1294 } 1233 if ( ! is_multisite() ) { 1234 /** This filter is documented in wp-includes/option.php */ 1235 $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1236 $value = get_option( $option, $default ); 1237 } else { 1238 $meta = get_metadata( 'site', $network_id, $option ); 1239 if ( is_array( $meta ) && ! empty( $meta ) ) { 1240 $value = array_shift( $meta ); 1241 $value = maybe_unserialize( $value ); 1242 } else { 1243 /** 1244 * Filters a specific default network option. 1245 * 1246 * The dynamic portion of the hook name, `$option`, refers to the option name. 1247 * 1248 * @since 3.4.0 1249 * @since 4.4.0 The `$option` parameter was added. 1250 * @since 4.7.0 The `$network_id` parameter was added. 1251 * 1252 * @param mixed $default The value to return if the site option does not exist 1253 * in the database. 1254 * @param string $option Option name. 1255 * @param int $network_id ID of the network. 1256 */ 1257 $value = apply_filters( 'default_site_option_' . $option, $default, $option ); 1295 1258 } 1296 1259 } 1297 1298 if ( ! is_array( $notoptions ) ) {1299 $notoptions = array();1300 wp_cache_set( $notoptions_key, $notoptions, 'site-options' );1301 }1302 1260 1303 1261 /** 1304 1262 * Filters the value of an existing network option. … … 1323 1281 * Existing options will not be updated. 1324 1282 * 1325 1283 * @since 4.4.0 1284 * @since 5.0.0 Uses add_metadata 1326 1285 * 1327 1286 * @see add_option() 1287 * @see add_metadata() 1328 1288 * 1329 1289 * @global wpdb $wpdb 1330 1290 * … … 1365 1325 */ 1366 1326 $value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id ); 1367 1327 1368 $notoptions_key = "$network_id:notoptions";1369 1370 1328 if ( ! is_multisite() ) { 1371 1329 $result = add_option( $option, $value, '', 'no' ); 1372 1330 } else { 1373 $cache_key = "$network_id:$option"; 1374 1375 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 1376 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1377 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1378 if ( false !== get_network_option( $network_id, $option, false ) ) { 1379 return false; 1380 } 1381 } 1382 1383 $value = sanitize_option( $option, $value ); 1384 1385 $serialized_value = maybe_serialize( $value ); 1386 $result = $wpdb->insert( 1387 $wpdb->sitemeta, array( 1388 'site_id' => $network_id, 1389 'meta_key' => $option, 1390 'meta_value' => $serialized_value, 1391 ) 1392 ); 1393 1394 if ( ! $result ) { 1395 return false; 1396 } 1397 1398 wp_cache_set( $cache_key, $value, 'site-options' ); 1399 1400 // This option exists now 1401 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh 1402 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1403 unset( $notoptions[ $option ] ); 1404 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1405 } 1331 $value = sanitize_option( $option, $value ); 1332 $value = maybe_serialize( $value ); 1333 $result = add_metadata( 'site', $network_id, $option, $value, true ); 1406 1334 } 1407 1335 1408 1336 if ( $result ) { … … 1444 1372 * Removes a network option by name. 1445 1373 * 1446 1374 * @since 4.4.0 1375 * @since 5.0.0 Uses delete_metadata 1447 1376 * 1448 1377 * @see delete_option() 1378 * @see delete_metadata() 1449 1379 * 1450 1380 * @global wpdb $wpdb 1451 1381 * … … 1484 1414 if ( ! is_multisite() ) { 1485 1415 $result = delete_option( $option ); 1486 1416 } else { 1487 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1488 if ( is_null( $row ) || ! $row->meta_id ) { 1489 return false; 1490 } 1491 $cache_key = "$network_id:$option"; 1492 wp_cache_delete( $cache_key, 'site-options' ); 1493 1494 $result = $wpdb->delete( 1495 $wpdb->sitemeta, array( 1496 'meta_key' => $option, 1497 'site_id' => $network_id, 1498 ) 1499 ); 1417 $result = delete_metadata( 'site', $network_id, $option, '' ); 1500 1418 } 1501 1419 1502 1420 if ( $result ) { … … 1589 1507 return add_network_option( $network_id, $option, $value ); 1590 1508 } 1591 1509 1592 $notoptions_key = "$network_id:notoptions";1593 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1594 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {1595 unset( $notoptions[ $option ] );1596 wp_cache_set( $notoptions_key, $notoptions, 'site-options' );1597 }1598 1599 1510 if ( ! is_multisite() ) { 1600 1511 $result = update_option( $option, $value, 'no' ); 1601 1512 } else { 1602 $value = sanitize_option( $option, $value ); 1603 1604 $serialized_value = maybe_serialize( $value ); 1605 $result = $wpdb->update( 1606 $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 1607 'site_id' => $network_id, 1608 'meta_key' => $option, 1609 ) 1610 ); 1611 1612 if ( $result ) { 1613 $cache_key = "$network_id:$option"; 1614 wp_cache_set( $cache_key, $value, 'site-options' ); 1615 } 1513 $value = sanitize_option( $option, $value ); 1514 $value = maybe_serialize( $value ); 1515 $result = update_metadata( 'site', $network_id, $option, $value ); 1616 1516 } 1617 1517 1618 1518 if ( $result ) { -
tests/phpunit/includes/testcase.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
328 328 $wp_object_cache->__remoteset(); 329 329 } 330 330 wp_cache_flush(); 331 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );331 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta', 'site_meta' ) ); 332 332 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 333 333 } 334 334 -
tests/phpunit/tests/option/multisite.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
146 146 //$this->assertFalse( get_option( $key2 ) ); // check get_option() 147 147 } 148 148 149 /**150 * @group multisite151 */152 function test_site_notoptions() {153 $network_id = get_current_network_id();154 $notoptions_key = "{$network_id}:notoptions";155 156 $_notoptions = wp_cache_get( 'notoptions', 'site-options' );157 $this->assertEmpty( $_notoptions );158 $_notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );159 $this->assertEmpty( $_notoptions1 );160 161 get_site_option( 'burrito' );162 163 $notoptions = wp_cache_get( 'notoptions', 'site-options' );164 $this->assertEmpty( $notoptions );165 $notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );166 $this->assertNotEmpty( $notoptions1 );167 }168 169 149 function test_users_can_register_signup_filter() { 170 150 171 151 $registration = get_site_option( 'registration' ); -
tests/phpunit/tests/option/networkOption.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
123 123 } 124 124 125 125 /** 126 * @ticket 43506126 * @ticket 37181 127 127 * @group ms-required 128 128 */ 129 public function test_get_network_option_sets_notoptions_if_option_found() { 130 $network_id = get_current_network_id(); 131 $notoptions_key = "$network_id:notoptions"; 129 public function test_meta_api_use_values_in_network_option() { 130 $network_id = self::factory()->network->create(); 131 $option = __FUNCTION__; 132 $value = __FUNCTION__; 132 133 133 $original_cache = wp_cache_get( $notoptions_key, 'site-options' ); 134 if ( false !== $original_cache ) { 135 wp_cache_delete( $notoptions_key, 'site-options' ); 136 } 137 138 // Retrieve any existing option. 139 get_network_option( $network_id, 'site_name' ); 140 141 $cache = wp_cache_get( $notoptions_key, 'site-options' ); 142 if ( false !== $original_cache ) { 143 wp_cache_set( $notoptions_key, $original_cache, 'site-options' ); 144 } 145 146 $this->assertSame( array(), $cache ); 134 add_metadata( 'site', $network_id, $option, $value, true ); 135 $this->assertEquals( get_metadata( 'site', $network_id, $option ), array( get_network_option( $network_id, $option, true ) ) ); 147 136 } 148 137 149 138 /** 150 * @ticket 43506139 * @ticket 37181 151 140 * @group ms-required 152 141 */ 153 public function test_ get_network_option_sets_notoptions_if_option_not_found() {154 $network_id = get_current_network_id();155 $ notoptions_key = "$network_id:notoptions";156 157 $original_cache = wp_cache_get( $notoptions_key, 'site-options');158 if ( false !== $original_cache ) {159 wp_cache_delete( $notoptions_key, 'site-options');160 142 public function test_meta_api_multiple_values_in_network_option() { 143 $network_id = self::factory()->network->create(); 144 $option = __FUNCTION__; 145 add_metadata( 'site', $network_id, $option, 'monday', true ); 146 add_metadata( 'site', $network_id, $option, 'tuesday', true ); 147 add_metadata( 'site', $network_id, $option, 'wednesday', true ); 148 $this->assertEquals( 'monday', get_network_option( $network_id, $option, true ) ); 149 } 161 150 162 // Retrieve any non-existing option. 163 get_network_option( $network_id, 'this_does_not_exist' ); 151 /** 152 * @ticket 37181 153 * @group ms-required 154 */ 155 function test_funky_post_meta() { 156 $network_id = self::factory()->network->create(); 157 $option = __FUNCTION__; 158 $classy = new StdClass(); 159 $classy->ID = 1; 160 $classy->stringy = 'I love slashes\\\\'; 161 $funky_meta[] = $classy; 164 162 165 $cache = wp_cache_get( $notoptions_key, 'site-options' ); 166 if ( false !== $original_cache ) { 167 wp_cache_set( $notoptions_key, $original_cache, 'site-options' ); 168 } 163 $classy = new StdClass(); 164 $classy->ID = 2; 165 $classy->stringy = 'I love slashes\\\\ more'; 166 $funky_meta[] = $classy; 167 168 // Add a network meta item 169 $this->assertInternalType( 'integer', add_metadata( 'site', $network_id, $option, $funky_meta, true ) ); 169 170 170 $this->assertSame( array( 'this_does_not_exist' => true ), $cache ); 171 //Check they exists 172 $this->assertEquals( $funky_meta, get_network_option( $network_id, $option ) ); 173 171 174 } 172 175 }