Ticket #37181: 37181.8.diff
File 37181.8.diff, 23.6 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-network-query.php
89 89 * @param string|array $query { 90 90 * Optional. Array or query string of network query parameters. Default empty. 91 91 * 92 * @type array $network__in Array of network IDs to include. Default empty. 93 * @type array $network__not_in Array of network IDs to exclude. Default empty. 94 * @type bool $count Whether to return a network count (true) or array of network objects. 95 * Default false. 96 * @type string $fields Network fields to return. Accepts 'ids' (returns an array of network IDs) 97 * or empty (returns an array of complete network objects). Default empty. 98 * @type int $number Maximum number of networks to retrieve. Default empty (no limit). 99 * @type int $offset Number of networks to offset the query. Used to build LIMIT clause. 100 * Default 0. 101 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 102 * @type string|array $orderby Network status or array of statuses. Accepts 'id', 'domain', 'path', 103 * 'domain_length', 'path_length' and 'network__in'. Also accepts false, 104 * an empty array, or 'none' to disable `ORDER BY` clause. Default 'id'. 105 * @type string $order How to order retrieved networks. Accepts 'ASC', 'DESC'. Default 'ASC'. 106 * @type string $domain Limit results to those affiliated with a given domain. Default empty. 107 * @type array $domain__in Array of domains to include affiliated networks for. Default empty. 108 * @type array $domain__not_in Array of domains to exclude affiliated networks for. Default empty. 109 * @type string $path Limit results to those affiliated with a given path. Default empty. 110 * @type array $path__in Array of paths to include affiliated networks for. Default empty. 111 * @type array $path__not_in Array of paths to exclude affiliated networks for. Default empty. 112 * @type string $search Search term(s) to retrieve matching networks for. Default empty. 113 * @type bool $update_network_cache Whether to prime the cache for found networks. Default true. 114 * } 92 * @type array $network__in Array of network IDs to include. Default empty. 93 * @type array $network__not_in Array of network IDs to exclude. Default empty. 94 * @type bool $count Whether to return a network count (true) or array of network objects. 95 * Default false. 96 * @type string $fields Network fields to return. Accepts 'ids' (returns an array of network IDs) 97 * or empty (returns an array of complete network objects). Default empty. 98 * @type int $number Maximum number of networks to retrieve. Default empty (no limit). 99 * @type int $offset Number of networks to offset the query. Used to build LIMIT clause. 100 * Default 0. 101 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 102 * @type string|array $orderby Network status or array of statuses. Accepts 'id', 'domain', 'path', 103 * 'domain_length', 'path_length' and 'network__in'. Also accepts false, 104 * an empty array, or 'none' to disable `ORDER BY` clause. Default 'id'. 105 * @type string $order How to order retrieved networks. Accepts 'ASC', 'DESC'. Default 'ASC'. 106 * @type string $domain Limit results to those affiliated with a given domain. Default empty. 107 * @type array $domain__in Array of domains to include affiliated networks for. Default empty. 108 * @type array $domain__not_in Array of domains to exclude affiliated networks for. Default empty. 109 * @type string $path Limit results to those affiliated with a given path. Default empty. 110 * @type array $path__in Array of paths to include affiliated networks for. Default empty. 111 * @type array $path__not_in Array of paths to exclude affiliated networks for. Default empty. 112 * @type string $search Search term(s) to retrieve matching networks for. Default empty. 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. 116 * 115 117 */ 116 118 public function __construct( $query = '' ) { 117 119 $this->query_var_defaults = array( 118 'network__in' => '', 119 'network__not_in' => '', 120 'count' => false, 121 'fields' => '', 122 'number' => '', 123 'offset' => '', 124 'no_found_rows' => true, 125 'orderby' => 'id', 126 'order' => 'ASC', 127 'domain' => '', 128 'domain__in' => '', 129 'domain__not_in' => '', 130 'path' => '', 131 'path__in' => '', 132 'path__not_in' => '', 133 'search' => '', 134 'update_network_cache' => true, 120 'network__in' => '', 121 'network__not_in' => '', 122 'count' => false, 123 'fields' => '', 124 'number' => '', 125 'offset' => '', 126 'no_found_rows' => true, 127 'orderby' => 'id', 128 'order' => 'ASC', 129 'domain' => '', 130 'domain__in' => '', 131 'domain__not_in' => '', 132 'path' => '', 133 'path__in' => '', 134 'path__not_in' => '', 135 'search' => '', 136 'update_network_cache' => true, 137 'update_network_meta_cache' => true, 135 138 ); 136 139 137 140 if ( ! empty( $query ) ) { … … 202 205 203 206 // Ignore the $fields argument as the queried result will be the same regardless. 204 207 unset( $_args['fields'] ); 208 unset( $_args['update_network_cache'] ); 209 unset( $_args['update_network_meta_cache'] ); 205 210 206 211 $key = md5( serialize( $_args ) ); 207 212 $last_changed = wp_cache_get_last_changed( 'networks' ); … … 243 248 } 244 249 245 250 if ( $this->query_vars['update_network_cache'] ) { 246 _prime_network_caches( $network_ids );251 _prime_network_caches( $network_ids, $this->query_vars['update_network_meta_cache'] ); 247 252 } 248 253 249 254 // Fetch full network objects from the primed cache. -
src/wp-includes/load.php
567 567 } 568 568 569 569 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 570 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' ) );570 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', 'site_meta' ) ); 571 571 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 572 572 } 573 573 } … … 592 592 593 593 require( ABSPATH . WPINC . '/kses.php' ); 594 594 require( ABSPATH . WPINC . '/pluggable.php' ); 595 require( ABSPATH . WPINC . '/formatting.php' );596 595 597 596 $link = wp_guess_url() . '/wp-admin/install.php'; 598 597 -
src/wp-includes/ms-blogs.php
869 869 if ( is_array( $global_groups ) ) { 870 870 wp_cache_add_global_groups( $global_groups ); 871 871 } else { 872 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' ) );872 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', 'site_meta' ) ); 873 873 } 874 874 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 875 875 } … … 937 937 if ( is_array( $global_groups ) ) { 938 938 wp_cache_add_global_groups( $global_groups ); 939 939 } else { 940 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' ) );940 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', 'site_meta' ) ); 941 941 } 942 942 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 943 943 } … … 1217 1217 1218 1218 foreach ( (array) $ids as $id ) { 1219 1219 wp_cache_delete( $id, 'networks' ); 1220 wp_cache_delete( $id, 'site_meta' ); 1220 1221 1221 1222 /** 1222 1223 * Fires immediately after a network has been removed from the object cache. … … 1239 1240 * cache using the network group with the key using the ID of the networks. 1240 1241 * 1241 1242 * @since 4.6.0 1243 * @since 4.9.0 Introduced the `$update_meta_cache` parameter. 1242 1244 * 1243 1245 * @param array $networks Array of network row objects. 1246 * @param bool $update_meta_cache Whether to update sitemeta cache. Default true. 1244 1247 */ 1245 function update_network_cache( $networks ) { 1248 function update_network_cache( $networks, $update_meta_cache = true ) { 1249 $network_ids = array(); 1246 1250 foreach ( (array) $networks as $network ) { 1251 $network_ids[] = $network->id; 1247 1252 wp_cache_add( $network->id, $network, 'networks' ); 1248 1253 } 1254 1255 if ( $update_meta_cache ) { 1256 update_meta_cache( 'site', $network_ids ); 1257 } 1249 1258 } 1250 1259 1251 1260 /** 1252 1261 * Adds any networks from the given IDs to the cache that do not already exist in cache. 1253 1262 * 1254 1263 * @since 4.6.0 1264 * @since 4.9.0 Introduced the `$update_meta_cache` parameter. 1255 1265 * @access private 1256 1266 * 1257 1267 * @see update_network_cache() 1258 1268 * @global wpdb $wpdb WordPress database abstraction object. 1259 1269 * 1260 1270 * @param array $network_ids Array of network IDs. 1271 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 1261 1272 */ 1262 function _prime_network_caches( $network_ids ) {1273 function _prime_network_caches( $network_ids, $update_meta_cache = true ) { 1263 1274 global $wpdb; 1264 1275 1265 1276 $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); 1266 1277 if ( ! empty( $non_cached_ids ) ) { 1267 1278 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); 1268 1279 1269 update_network_cache( $fresh_networks );1280 update_network_cache( $fresh_networks, $update_meta_cache ); 1270 1281 } 1271 1282 } 1272 1283 -
src/wp-includes/option.php
237 237 * 238 238 * @since 3.0.0 239 239 * 240 * @global wpdb $wpdb WordPress database abstraction object.241 *242 240 * @param int $network_id Optional site ID for which to query the options. Defaults to the current site. 243 241 */ 244 242 function wp_load_core_site_options( $network_id = null ) { 245 global $wpdb;246 243 247 244 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) { 248 245 return; … … 252 249 $network_id = get_current_network_id(); 253 250 } 254 251 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 } 252 update_meta_cache( 'site', $network_id ); 267 253 } 268 254 269 255 /** … … 1243 1229 return $pre; 1244 1230 } 1245 1231 1246 // prevent non-existent options from triggering multiple queries1247 $notoptions_key = "$network_id:notoptions";1248 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1249 1250 if ( 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.01258 * @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 exist1262 * 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 1232 1269 1233 if ( ! is_multisite() ) { 1270 1234 /** This filter is documented in wp-includes/option.php */ 1271 1235 $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1272 1236 $value = get_option( $option, $default ); 1273 1237 } 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 } 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 $value = apply_filters( 'default_site_option_' . $option, $default, $option ); 1295 1244 } 1296 1245 } 1297 1246 … … 1360 1309 */ 1361 1310 $value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id ); 1362 1311 1363 $notoptions_key = "$network_id:notoptions";1364 1365 1312 if ( ! is_multisite() ) { 1366 1313 $result = add_option( $option, $value, '', 'no' ); 1367 1314 } else { 1368 $cache_key = "$network_id:$option"; 1369 1370 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 1371 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1372 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1373 if ( false !== get_network_option( $network_id, $option, false ) ) { 1374 return false; 1375 } 1376 } 1377 1378 $value = sanitize_option( $option, $value ); 1379 1380 $serialized_value = maybe_serialize( $value ); 1381 $result = $wpdb->insert( 1382 $wpdb->sitemeta, array( 1383 'site_id' => $network_id, 1384 'meta_key' => $option, 1385 'meta_value' => $serialized_value, 1386 ) 1387 ); 1388 1389 if ( ! $result ) { 1390 return false; 1391 } 1392 1393 wp_cache_set( $cache_key, $value, 'site-options' ); 1394 1395 // This option exists now 1396 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh 1397 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1398 unset( $notoptions[ $option ] ); 1399 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1400 } 1315 $value = sanitize_option( $option, $value ); 1316 $value = maybe_serialize( $value ); 1317 $result = add_metadata( 'site', $network_id, $option, $value, true ); 1401 1318 } 1402 1319 1403 1320 if ( $result ) { … … 1479 1396 if ( ! is_multisite() ) { 1480 1397 $result = delete_option( $option ); 1481 1398 } else { 1482 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1483 if ( is_null( $row ) || ! $row->meta_id ) { 1484 return false; 1485 } 1486 $cache_key = "$network_id:$option"; 1487 wp_cache_delete( $cache_key, 'site-options' ); 1488 1489 $result = $wpdb->delete( 1490 $wpdb->sitemeta, array( 1491 'meta_key' => $option, 1492 'site_id' => $network_id, 1493 ) 1494 ); 1399 $result = delete_metadata( 'site', $network_id, $option, '' ); 1495 1400 } 1496 1401 1497 1402 if ( $result ) { … … 1584 1489 return add_network_option( $network_id, $option, $value ); 1585 1490 } 1586 1491 1587 $notoptions_key = "$network_id:notoptions";1588 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1589 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {1590 unset( $notoptions[ $option ] );1591 wp_cache_set( $notoptions_key, $notoptions, 'site-options' );1592 }1593 1594 1492 if ( ! is_multisite() ) { 1595 1493 $result = update_option( $option, $value, 'no' ); 1596 1494 } else { 1597 $value = sanitize_option( $option, $value ); 1598 1599 $serialized_value = maybe_serialize( $value ); 1600 $result = $wpdb->update( 1601 $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 1602 'site_id' => $network_id, 1603 'meta_key' => $option, 1604 ) 1605 ); 1606 1607 if ( $result ) { 1608 $cache_key = "$network_id:$option"; 1609 wp_cache_set( $cache_key, $value, 'site-options' ); 1610 } 1495 $value = sanitize_option( $option, $value ); 1496 $value = maybe_serialize( $value ); 1497 $result = update_metadata( 'site', $network_id, $option, $value ); 1611 1498 } 1612 1499 1613 1500 if ( $result ) { -
src/wp-settings.php
95 95 // Load early WordPress files. 96 96 require( ABSPATH . WPINC . '/compat.php' ); 97 97 require( ABSPATH . WPINC . '/class-wp-list-util.php' ); 98 require( ABSPATH . WPINC . '/formatting.php' ); 99 require( ABSPATH . WPINC . '/meta.php' ); 98 100 require( ABSPATH . WPINC . '/functions.php' ); 99 101 require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' ); 100 102 require( ABSPATH . WPINC . '/class-wp.php' ); … … 143 145 // Load most of WordPress. 144 146 require( ABSPATH . WPINC . '/class-wp-walker.php' ); 145 147 require( ABSPATH . WPINC . '/class-wp-ajax-response.php' ); 146 require( ABSPATH . WPINC . '/formatting.php' ); 148 147 149 require( ABSPATH . WPINC . '/capabilities.php' ); 148 150 require( ABSPATH . WPINC . '/class-wp-roles.php' ); 149 151 require( ABSPATH . WPINC . '/class-wp-role.php' ); … … 158 160 require( ABSPATH . WPINC . '/class-wp-user-query.php' ); 159 161 require( ABSPATH . WPINC . '/class-wp-session-tokens.php' ); 160 162 require( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' ); 161 require( ABSPATH . WPINC . '/meta.php' );162 163 require( ABSPATH . WPINC . '/class-wp-meta-query.php' ); 163 164 require( ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php' ); 164 165 require( ABSPATH . WPINC . '/general-template.php' ); -
tests/phpunit/includes/testcase.php
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' ) );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', 'site_meta' ) ); 332 332 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 333 333 } 334 334 -
tests/phpunit/tests/cache.php
22 22 global $wp_object_cache; 23 23 $cache_class = get_class( $wp_object_cache ); 24 24 $cache = new $cache_class(); 25 $cache->add_global_groups( array( 'global-cache-test', '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' ) );25 $cache->add_global_groups( array( 'global-cache-test', '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', 'site_meta' ) ); 26 26 return $cache; 27 27 } 28 28 -
tests/phpunit/tests/option/multisite.php
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
79 79 } 80 80 81 81 /** 82 * @ticket 37181 83 * @group ms-required 84 */ 85 public function test_meta_api_use_in_network_option() { 86 $network_id = self::factory()->network->create(); 87 $option = 'test_option_name'; 88 add_metadata( 'site', $network_id, $option, 'monday', true ); 89 add_metadata( 'site', $network_id, $option, 'tuesday', true ); 90 add_metadata( 'site', $network_id, $option, 'wednesday', true ); 91 $this->assertEquals( 'monday', get_network_option( $network_id, $option, true ) ); 92 } 93 94 /** 82 95 * @dataProvider data_network_id_parameter 83 96 * 84 97 * @param $network_id