Ticket #37181: 37181.6.diff
File 37181.6.diff, 23.8 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 ) ) { … … 242 245 } 243 246 244 247 if ( $this->query_vars['update_network_cache'] ) { 245 _prime_network_caches( $network_ids );248 _prime_network_caches( $network_ids, $this->query_vars['update_network_meta_cache'] ); 246 249 } 247 250 248 251 // 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
842 842 if ( is_array( $global_groups ) ) { 843 843 wp_cache_add_global_groups( $global_groups ); 844 844 } else { 845 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' ) );845 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' ) ); 846 846 } 847 847 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 848 848 } … … 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 } … … 1170 1170 1171 1171 foreach ( (array) $ids as $id ) { 1172 1172 wp_cache_delete( $id, 'networks' ); 1173 wp_cache_delete( $id, 'site_meta' ); 1173 1174 1174 1175 /** 1175 1176 * Fires immediately after a network has been removed from the object cache. … … 1192 1193 * cache using the network group with the key using the ID of the networks. 1193 1194 * 1194 1195 * @since 4.6.0 1196 * @since 4.9.0 Introduced the `$update_meta_cache` parameter. 1195 1197 * 1196 1198 * @param array $networks Array of network row objects. 1199 * @param bool $update_meta_cache Whether to update sitemeta cache. Default true. 1197 1200 */ 1198 function update_network_cache( $networks ) { 1201 function update_network_cache( $networks, $update_meta_cache = true ) { 1202 $network_ids = array(); 1199 1203 foreach ( (array) $networks as $network ) { 1204 $network_ids[] = $network->id; 1200 1205 wp_cache_add( $network->id, $network, 'networks' ); 1201 1206 } 1207 1208 if ( $update_meta_cache ) { 1209 update_meta_cache( 'site', $network_ids ); 1210 } 1202 1211 } 1203 1212 1204 1213 /** 1205 1214 * Adds any networks from the given IDs to the cache that do not already exist in cache. 1206 1215 * 1207 1216 * @since 4.6.0 1217 * @since 4.9.0 Introduced the `$update_meta_cache` parameter. 1208 1218 * @access private 1209 1219 * 1210 1220 * @see update_network_cache() 1211 1221 * @global wpdb $wpdb WordPress database abstraction object. 1212 1222 * 1213 1223 * @param array $network_ids Array of network IDs. 1224 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 1214 1225 */ 1215 function _prime_network_caches( $network_ids ) {1226 function _prime_network_caches( $network_ids, $update_meta_cache = true ) { 1216 1227 global $wpdb; 1217 1228 1218 1229 $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); 1219 1230 if ( !empty( $non_cached_ids ) ) { 1220 1231 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); 1221 1232 1222 update_network_cache( $fresh_networks );1233 update_network_cache( $fresh_networks, $update_meta_cache ); 1223 1234 } 1224 1235 } 1225 1236 -
src/wp-includes/option.php
212 212 * 213 213 * @since 3.0.0 214 214 * 215 * @global wpdb $wpdb WordPress database abstraction object.216 *217 215 * @param int $network_id Optional site ID for which to query the options. Defaults to the current site. 218 216 */ 219 217 function wp_load_core_site_options( $network_id = null ) { 220 global $wpdb;221 218 222 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) 219 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) { 223 220 return; 221 } 224 222 225 if ( empty( $network_id) )223 if ( empty( $network_id ) ) { 226 224 $network_id = get_current_network_id(); 227 228 $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' );229 230 $core_options_in = "'" . implode("', '", $core_options) . "'";231 $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 ) );232 233 foreach ( $options as $option ) {234 $key = $option->meta_key;235 $cache_key = "{$network_id}:$key";236 $option->meta_value = maybe_unserialize( $option->meta_value );237 238 wp_cache_set( $cache_key, $option->meta_value, 'site-options' );239 225 } 226 227 update_meta_cache( 'site', $network_id ); 240 228 } 241 229 242 230 /** … … 1140 1128 return $pre; 1141 1129 } 1142 1130 1143 // prevent non-existent options from triggering multiple queries1144 $notoptions_key = "$network_id:notoptions";1145 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1146 1147 if ( isset( $notoptions[ $option ] ) ) {1148 1149 /**1150 * Filters a specific default network option.1151 *1152 * The dynamic portion of the hook name, `$option`, refers to the option name.1153 *1154 * @since 3.4.01155 * @since 4.4.0 The `$option` parameter was added.1156 * @since 4.7.0 The `$network_id` parameter was added.1157 *1158 * @param mixed $default The value to return if the site option does not exist1159 * in the database.1160 * @param string $option Option name.1161 * @param int $network_id ID of the network.1162 */1163 return apply_filters( "default_site_option_{$option}", $default, $option, $network_id );1164 }1165 1131 1166 1132 if ( ! is_multisite() ) { 1167 1133 /** This filter is documented in wp-includes/option.php */ 1168 1134 $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1169 $value = get_option( $option, $default );1135 $value = get_option( $option, $default ); 1170 1136 } else { 1171 $cache_key = "$network_id:$option"; 1172 $value = wp_cache_get( $cache_key, 'site-options' ); 1173 1174 if ( ! isset( $value ) || false === $value ) { 1175 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1176 1177 // Has to be get_row instead of get_var because of funkiness with 0, false, null values 1178 if ( is_object( $row ) ) { 1179 $value = $row->meta_value; 1180 $value = maybe_unserialize( $value ); 1181 wp_cache_set( $cache_key, $value, 'site-options' ); 1182 } else { 1183 if ( ! is_array( $notoptions ) ) { 1184 $notoptions = array(); 1185 } 1186 $notoptions[ $option ] = true; 1187 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1188 1189 /** This filter is documented in wp-includes/option.php */ 1190 $value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1191 } 1137 $meta = get_metadata( 'site', $network_id, $option ); 1138 if ( is_array( $meta ) && ! empty( $meta ) ) { 1139 $value = array_shift( $meta ); 1140 $value = maybe_unserialize( $value ); 1141 } else { 1142 $value = apply_filters( 'default_site_option_' . $option, $default, $option ); 1192 1143 } 1193 1144 } 1194 1145 … … 1257 1208 */ 1258 1209 $value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id ); 1259 1210 1260 $notoptions_key = "$network_id:notoptions";1261 1262 1211 if ( ! is_multisite() ) { 1263 1212 $result = add_option( $option, $value, '', 'no' ); 1264 1213 } else { 1265 $cache_key = "$network_id:$option"; 1266 1267 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 1268 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1269 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1270 if ( false !== get_network_option( $network_id, $option, false ) ) { 1271 return false; 1272 } 1273 } 1274 1275 $value = sanitize_option( $option, $value ); 1276 1277 $serialized_value = maybe_serialize( $value ); 1278 $result = $wpdb->insert( $wpdb->sitemeta, array( 'site_id' => $network_id, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); 1279 1280 if ( ! $result ) { 1281 return false; 1282 } 1283 1284 wp_cache_set( $cache_key, $value, 'site-options' ); 1285 1286 // This option exists now 1287 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh 1288 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1289 unset( $notoptions[ $option ] ); 1290 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1291 } 1214 $value = sanitize_option( $option, $value ); 1215 $value = maybe_serialize( $value ); 1216 $result = add_metadata( 'site', $network_id, $option, $value, true ); 1292 1217 } 1293 1218 1294 1219 if ( $result ) { … … 1370 1295 if ( ! is_multisite() ) { 1371 1296 $result = delete_option( $option ); 1372 1297 } else { 1373 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1374 if ( is_null( $row ) || ! $row->meta_id ) { 1375 return false; 1376 } 1377 $cache_key = "$network_id:$option"; 1378 wp_cache_delete( $cache_key, 'site-options' ); 1379 1380 $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) ); 1298 $result = delete_metadata( 'site', $network_id, $option, '' ); 1381 1299 } 1382 1300 1383 1301 if ( $result ) { … … 1470 1388 return add_network_option( $network_id, $option, $value ); 1471 1389 } 1472 1390 1473 $notoptions_key = "$network_id:notoptions";1474 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1475 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {1476 unset( $notoptions[ $option ] );1477 wp_cache_set( $notoptions_key, $notoptions, 'site-options' );1478 }1479 1480 1391 if ( ! is_multisite() ) { 1481 1392 $result = update_option( $option, $value, 'no' ); 1482 1393 } else { 1483 $value = sanitize_option( $option, $value ); 1484 1485 $serialized_value = maybe_serialize( $value ); 1486 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) ); 1487 1488 if ( $result ) { 1489 $cache_key = "$network_id:$option"; 1490 wp_cache_set( $cache_key, $value, 'site-options' ); 1491 } 1394 $value = sanitize_option( $option, $value ); 1395 $value = maybe_serialize( $value ); 1396 $result = update_metadata( 'site', $network_id, $option, $value ); 1492 1397 } 1493 1398 1494 1399 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
323 323 $wp_object_cache->__remoteset(); 324 324 } 325 325 wp_cache_flush(); 326 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' ) );326 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' ) ); 327 327 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 328 328 } 329 329 -
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