Ticket #37181: 37181.7.diff
File 37181.7.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 ) ) { … … 203 206 204 207 // Ignore the $fields argument as the queried result will be the same regardless. 205 208 unset( $_args['fields'] ); 209 unset( $_args['update_network_cache'] ); 210 unset( $_args['update_network_meta_cache'] ); 206 211 207 212 $key = md5( serialize( $_args ) ); 208 213 $last_changed = wp_cache_get_last_changed( 'networks' ); … … 244 249 } 245 250 246 251 if ( $this->query_vars['update_network_cache'] ) { 247 _prime_network_caches( $network_ids );252 _prime_network_caches( $network_ids, $this->query_vars['update_network_meta_cache'] ); 248 253 } 249 254 250 255 // Fetch full network objects from the primed cache. -
src/wp-includes/load.php
517 517 } 518 518 519 519 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 520 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' ) );520 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' ) ); 521 521 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 522 522 } 523 523 } … … 542 542 543 543 require( ABSPATH . WPINC . '/kses.php' ); 544 544 require( ABSPATH . WPINC . '/pluggable.php' ); 545 require( ABSPATH . WPINC . '/formatting.php' );546 545 547 546 $link = wp_guess_url() . '/wp-admin/install.php'; 548 547 -
src/wp-includes/ms-blogs.php
848 848 if ( is_array( $global_groups ) ) { 849 849 wp_cache_add_global_groups( $global_groups ); 850 850 } else { 851 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' ) );851 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' ) ); 852 852 } 853 853 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 854 854 } … … 916 916 if ( is_array( $global_groups ) ) { 917 917 wp_cache_add_global_groups( $global_groups ); 918 918 } else { 919 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' ) );919 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' ) ); 920 920 } 921 921 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 922 922 } … … 1186 1186 1187 1187 foreach ( (array) $ids as $id ) { 1188 1188 wp_cache_delete( $id, 'networks' ); 1189 wp_cache_delete( $id, 'site_meta' ); 1189 1190 1190 1191 /** 1191 1192 * Fires immediately after a network has been removed from the object cache. … … 1208 1209 * cache using the network group with the key using the ID of the networks. 1209 1210 * 1210 1211 * @since 4.6.0 1212 * @since 4.9.0 Introduced the `$update_meta_cache` parameter. 1211 1213 * 1212 1214 * @param array $networks Array of network row objects. 1215 * @param bool $update_meta_cache Whether to update sitemeta cache. Default true. 1213 1216 */ 1214 function update_network_cache( $networks ) { 1217 function update_network_cache( $networks, $update_meta_cache = true ) { 1218 $network_ids = array(); 1215 1219 foreach ( (array) $networks as $network ) { 1220 $network_ids[] = $network->id; 1216 1221 wp_cache_add( $network->id, $network, 'networks' ); 1217 1222 } 1223 1224 if ( $update_meta_cache ) { 1225 update_meta_cache( 'site', $network_ids ); 1226 } 1218 1227 } 1219 1228 1220 1229 /** 1221 1230 * Adds any networks from the given IDs to the cache that do not already exist in cache. 1222 1231 * 1223 1232 * @since 4.6.0 1233 * @since 4.9.0 Introduced the `$update_meta_cache` parameter. 1224 1234 * @access private 1225 1235 * 1226 1236 * @see update_network_cache() 1227 1237 * @global wpdb $wpdb WordPress database abstraction object. 1228 1238 * 1229 1239 * @param array $network_ids Array of network IDs. 1240 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 1230 1241 */ 1231 function _prime_network_caches( $network_ids ) {1242 function _prime_network_caches( $network_ids, $update_meta_cache = true ) { 1232 1243 global $wpdb; 1233 1244 1234 1245 $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); 1235 1246 if ( !empty( $non_cached_ids ) ) { 1236 1247 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); 1237 1248 1238 update_network_cache( $fresh_networks );1249 update_network_cache( $fresh_networks, $update_meta_cache ); 1239 1250 } 1240 1251 } 1241 1252 -
src/wp-includes/option.php
232 232 * 233 233 * @since 3.0.0 234 234 * 235 * @global wpdb $wpdb WordPress database abstraction object.236 *237 235 * @param int $network_id Optional site ID for which to query the options. Defaults to the current site. 238 236 */ 239 237 function wp_load_core_site_options( $network_id = null ) { 240 global $wpdb;241 238 242 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) 239 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) { 243 240 return; 241 } 244 242 245 if ( empty( $network_id) )243 if ( empty( $network_id ) ) { 246 244 $network_id = get_current_network_id(); 247 248 $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' );249 250 $core_options_in = "'" . implode("', '", $core_options) . "'";251 $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 ) );252 253 foreach ( $options as $option ) {254 $key = $option->meta_key;255 $cache_key = "{$network_id}:$key";256 $option->meta_value = maybe_unserialize( $option->meta_value );257 258 wp_cache_set( $cache_key, $option->meta_value, 'site-options' );259 245 } 246 247 update_meta_cache( 'site', $network_id ); 260 248 } 261 249 262 250 /** … … 1215 1203 return $pre; 1216 1204 } 1217 1205 1218 // prevent non-existent options from triggering multiple queries1219 $notoptions_key = "$network_id:notoptions";1220 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1221 1222 if ( isset( $notoptions[ $option ] ) ) {1223 1224 /**1225 * Filters a specific default network option.1226 *1227 * The dynamic portion of the hook name, `$option`, refers to the option name.1228 *1229 * @since 3.4.01230 * @since 4.4.0 The `$option` parameter was added.1231 * @since 4.7.0 The `$network_id` parameter was added.1232 *1233 * @param mixed $default The value to return if the site option does not exist1234 * in the database.1235 * @param string $option Option name.1236 * @param int $network_id ID of the network.1237 */1238 return apply_filters( "default_site_option_{$option}", $default, $option, $network_id );1239 }1240 1206 1241 1207 if ( ! is_multisite() ) { 1242 1208 /** This filter is documented in wp-includes/option.php */ 1243 1209 $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1244 $value = get_option( $option, $default );1210 $value = get_option( $option, $default ); 1245 1211 } else { 1246 $cache_key = "$network_id:$option"; 1247 $value = wp_cache_get( $cache_key, 'site-options' ); 1248 1249 if ( ! isset( $value ) || false === $value ) { 1250 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1251 1252 // Has to be get_row instead of get_var because of funkiness with 0, false, null values 1253 if ( is_object( $row ) ) { 1254 $value = $row->meta_value; 1255 $value = maybe_unserialize( $value ); 1256 wp_cache_set( $cache_key, $value, 'site-options' ); 1257 } else { 1258 if ( ! is_array( $notoptions ) ) { 1259 $notoptions = array(); 1260 } 1261 $notoptions[ $option ] = true; 1262 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1263 1264 /** This filter is documented in wp-includes/option.php */ 1265 $value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1266 } 1212 $meta = get_metadata( 'site', $network_id, $option ); 1213 if ( is_array( $meta ) && ! empty( $meta ) ) { 1214 $value = array_shift( $meta ); 1215 $value = maybe_unserialize( $value ); 1216 } else { 1217 $value = apply_filters( 'default_site_option_' . $option, $default, $option ); 1267 1218 } 1268 1219 } 1269 1220 … … 1332 1283 */ 1333 1284 $value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id ); 1334 1285 1335 $notoptions_key = "$network_id:notoptions";1336 1337 1286 if ( ! is_multisite() ) { 1338 1287 $result = add_option( $option, $value, '', 'no' ); 1339 1288 } else { 1340 $cache_key = "$network_id:$option"; 1341 1342 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 1343 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1344 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1345 if ( false !== get_network_option( $network_id, $option, false ) ) { 1346 return false; 1347 } 1348 } 1349 1350 $value = sanitize_option( $option, $value ); 1351 1352 $serialized_value = maybe_serialize( $value ); 1353 $result = $wpdb->insert( $wpdb->sitemeta, array( 'site_id' => $network_id, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); 1354 1355 if ( ! $result ) { 1356 return false; 1357 } 1358 1359 wp_cache_set( $cache_key, $value, 'site-options' ); 1360 1361 // This option exists now 1362 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh 1363 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1364 unset( $notoptions[ $option ] ); 1365 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1366 } 1289 $value = sanitize_option( $option, $value ); 1290 $value = maybe_serialize( $value ); 1291 $result = add_metadata( 'site', $network_id, $option, $value, true ); 1367 1292 } 1368 1293 1369 1294 if ( $result ) { … … 1445 1370 if ( ! is_multisite() ) { 1446 1371 $result = delete_option( $option ); 1447 1372 } else { 1448 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1449 if ( is_null( $row ) || ! $row->meta_id ) { 1450 return false; 1451 } 1452 $cache_key = "$network_id:$option"; 1453 wp_cache_delete( $cache_key, 'site-options' ); 1454 1455 $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) ); 1373 $result = delete_metadata( 'site', $network_id, $option, '' ); 1456 1374 } 1457 1375 1458 1376 if ( $result ) { … … 1545 1463 return add_network_option( $network_id, $option, $value ); 1546 1464 } 1547 1465 1548 $notoptions_key = "$network_id:notoptions";1549 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1550 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {1551 unset( $notoptions[ $option ] );1552 wp_cache_set( $notoptions_key, $notoptions, 'site-options' );1553 }1554 1555 1466 if ( ! is_multisite() ) { 1556 1467 $result = update_option( $option, $value, 'no' ); 1557 1468 } else { 1558 $value = sanitize_option( $option, $value ); 1559 1560 $serialized_value = maybe_serialize( $value ); 1561 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) ); 1562 1563 if ( $result ) { 1564 $cache_key = "$network_id:$option"; 1565 wp_cache_set( $cache_key, $value, 'site-options' ); 1566 } 1469 $value = sanitize_option( $option, $value ); 1470 $value = maybe_serialize( $value ); 1471 $result = update_metadata( 'site', $network_id, $option, $value ); 1567 1472 } 1568 1473 1569 1474 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' ); … … 142 144 // Load most of WordPress. 143 145 require( ABSPATH . WPINC . '/class-wp-walker.php' ); 144 146 require( ABSPATH . WPINC . '/class-wp-ajax-response.php' ); 145 require( ABSPATH . WPINC . '/formatting.php' ); 147 146 148 require( ABSPATH . WPINC . '/capabilities.php' ); 147 149 require( ABSPATH . WPINC . '/class-wp-roles.php' ); 148 150 require( ABSPATH . WPINC . '/class-wp-role.php' ); … … 157 159 require( ABSPATH . WPINC . '/class-wp-user-query.php' ); 158 160 require( ABSPATH . WPINC . '/class-wp-session-tokens.php' ); 159 161 require( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' ); 160 require( ABSPATH . WPINC . '/meta.php' );161 162 require( ABSPATH . WPINC . '/class-wp-meta-query.php' ); 162 163 require( ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php' ); 163 164 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
144 144 //$this->assertFalse( get_option( $key2 ) ); // check get_option() 145 145 } 146 146 147 /**148 * @group multisite149 */150 function test_site_notoptions() {151 $network_id = get_current_network_id();152 $notoptions_key = "{$network_id}:notoptions";153 154 $_notoptions = wp_cache_get( 'notoptions', 'site-options' );155 $this->assertEmpty( $_notoptions );156 $_notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );157 $this->assertEmpty( $_notoptions1 );158 159 get_site_option( 'burrito' );160 161 $notoptions = wp_cache_get( 'notoptions', 'site-options' );162 $this->assertEmpty( $notoptions );163 $notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );164 $this->assertNotEmpty( $notoptions1 );165 }166 167 147 function test_users_can_register_signup_filter() { 168 148 169 149 $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