Ticket #25344: 25344.8.patch
| File 25344.8.patch, 21.6 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/class-wp-network-query.php
119 119 * @type array $path__not_in Array of paths to exclude affiliated networks for. Default empty. 120 120 * @type string $search Search term(s) to retrieve matching networks for. Default empty. 121 121 * @type bool $update_network_cache Whether to prime the cache for found networks. Default true. 122 * @type bool $update_network_meta_cache Whether to update the network meta cache. Default true. 122 123 * } 123 124 */ 124 125 public function __construct( $query = '' ) { … … 140 141 'path__not_in' => '', 141 142 'search' => '', 142 143 'update_network_cache' => true, 144 'update_network_meta_cache' => true, 143 145 ); 144 146 145 147 if ( ! empty( $query ) ) { … … 248 250 } 249 251 250 252 if ( $this->query_vars['update_network_cache'] ) { 251 _prime_network_caches( $network_ids );253 _prime_network_caches( $network_ids, $this->query_vars['update_network_meta_cache'] ); 252 254 } 253 255 254 256 // Fetch full network objects from the primed cache. -
src/wp-includes/meta.php
34 34 return false; 35 35 } 36 36 37 $object_id = absint( $object_id );37 $object_id = intval( $object_id ); 38 38 if ( ! $object_id ) { 39 39 return false; 40 40 } … … 147 147 return false; 148 148 } 149 149 150 $object_id = absint( $object_id );150 $object_id = intval( $object_id ); 151 151 if ( ! $object_id ) { 152 152 return false; 153 153 } … … 311 311 return false; 312 312 } 313 313 314 $object_id = absint( $object_id );314 $object_id = intval( $object_id ); 315 315 if ( ! $object_id && ! $delete_all ) { 316 316 return false; 317 317 } … … 463 463 return false; 464 464 } 465 465 466 $object_id = absint( $object_id );466 $object_id = intval( $object_id ); 467 467 if ( ! $object_id ) { 468 468 return false; 469 469 } … … 530 530 return false; 531 531 } 532 532 533 $object_id = absint( $object_id );533 $object_id = intval( $object_id ); 534 534 if ( ! $object_id ) { 535 535 return false; 536 536 } -
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 } … … 1192 1192 * cache using the network group with the key using the ID of the networks. 1193 1193 * 1194 1194 * @since 4.6.0 1195 * @since 4.8.0 Introduced the `$update_meta_cache` parameter. 1195 1196 * 1196 * @param array $networks Array of network row objects. 1197 * @param array $networks Array of network row objects. 1198 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 1197 1199 */ 1198 function update_network_cache( $networks ) {1200 function update_network_cache( $networks, $update_meta_cache = true ) { 1199 1201 foreach ( (array) $networks as $network ) { 1200 1202 wp_cache_add( $network->id, $network, 'networks' ); 1201 1203 } 1204 1205 if ( $update_meta_cache ) { 1206 update_networkmeta_cache( wp_list_pluck( $networks, 'id' ) ); 1207 } 1202 1208 } 1203 1209 1204 1210 /** 1205 1211 * Adds any networks from the given IDs to the cache that do not already exist in cache. 1206 1212 * 1207 1213 * @since 4.6.0 1214 * @since 4.8.0 Introduced the `$update_meta_cache` parameter. 1208 1215 * @access private 1209 1216 * 1210 1217 * @see update_network_cache() 1211 1218 * @global wpdb $wpdb WordPress database abstraction object. 1212 1219 * 1213 * @param array $network_ids Array of network IDs. 1220 * @param array $network_ids Array of network IDs. 1221 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 1214 1222 */ 1215 function _prime_network_caches( $network_ids ) {1223 function _prime_network_caches( $network_ids, $update_meta_cache = true ) { 1216 1224 global $wpdb; 1217 1225 1218 1226 $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); 1219 if ( ! empty( $non_cached_ids ) ) {1220 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->siteWHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );1227 if ( ! empty( $non_cached_ids ) ) { 1228 $fresh_networks = $wpdb->get_results( sprintf( "SELECT * FROM {$wpdb->site} WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); 1221 1229 1222 update_network_cache( $fresh_networks );1230 update_network_cache( $fresh_networks, $update_meta_cache ); 1223 1231 } 1224 1232 } 1225 1233 -
src/wp-includes/ms-functions.php
2517 2517 */ 2518 2518 return apply_filters( 'subdirectory_reserved_names', $names ); 2519 2519 } 2520 2521 /** 2522 * Add metadata to a network. 2523 * 2524 * @since 4.8.0 2525 * 2526 * @param int $id Network ID. 2527 * @param string $meta_key Metadata name. 2528 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 2529 * @param bool $unique Optional. Whether the same key should not be added. 2530 * Default false. 2531 * @return int|false Meta ID on success, false on failure. 2532 */ 2533 function add_network_meta( $id, $meta_key, $meta_value, $unique = false ) { 2534 return add_metadata( 'site', $id, $meta_key, $meta_value, $unique ); 2535 } 2536 2537 /** 2538 * Remove from a network, metadata matching key and/or value. 2539 * 2540 * You can match based on the key, or key and value. Removing based on key and 2541 * value, will keep from removing duplicate metadata with the same key. It also 2542 * allows removing all metadata matching key, if needed. 2543 * 2544 * @since 4.8.0 2545 * 2546 * @param int $id Network ID. 2547 * @param string $meta_key Metadata name. 2548 * @param mixed $meta_value Optional. Metadata value. Must be serializable if 2549 * non-scalar. Default empty. 2550 * @return bool True on success, false on failure. 2551 */ 2552 function delete_network_meta( $id, $meta_key, $meta_value = '' ) { 2553 return delete_metadata( 'site', $id, $meta_key, $meta_value ); 2554 } 2555 2556 /** 2557 * Retrieve from a network, metadata value by key. 2558 * 2559 * @since 4.8.0 2560 * 2561 * @param int $id Network ID. 2562 * @param string $meta_key Optional. The meta key to retrieve. By default, returns 2563 * data for all keys. Default empty. 2564 * @param bool $single Optional. Whether to return a single value. Default false. 2565 * @return mixed Will be an array if $single is false. Will be value of meta data 2566 * field if $single is true. 2567 */ 2568 function get_network_meta( $id, $meta_key = '', $single = false ) { 2569 return get_metadata( 'site', $id, $meta_key, $single ); 2570 } 2571 2572 /** 2573 * Update metadata for a network ID, and/or key, and/or value. 2574 * 2575 * Use the $prev_value parameter to differentiate between meta fields with the 2576 * same key and network ID. 2577 * 2578 * If the meta field for the network does not exist, it will be added. 2579 * 2580 * @since 4.8.0 2581 * 2582 * @param int $id Network ID. 2583 * @param string $meta_key Metadata key. 2584 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 2585 * @param mixed $prev_value Optional. Previous value to check before removing. 2586 * Default empty. 2587 * @return int|bool Meta ID if the key didn't exist, true on successful update, 2588 * false on failure. 2589 */ 2590 function update_network_meta( $id, $meta_key, $meta_value, $prev_value = '' ) { 2591 return update_metadata( 'site', $id, $meta_key, $meta_value, $prev_value ); 2592 } 2593 2594 /** 2595 * Updates metadata cache for list of network IDs. 2596 * 2597 * Performs SQL query to retrieve the metadata for the network IDs and updates the 2598 * metadata cache for the posts. Therefore, the functions, which call this 2599 * function, do not need to perform SQL queries on their own. 2600 * 2601 * @since 4.8.0 2602 * 2603 * @param array $network_ids List of network IDs. 2604 * @return array|false Returns false if there is nothing to update or an array 2605 * of metadata. 2606 */ 2607 function update_networkmeta_cache( $network_ids) { 2608 return update_meta_cache( 'site', $network_ids ); 2609 } -
src/wp-includes/option.php
207 207 * 208 208 * @global wpdb $wpdb WordPress database abstraction object. 209 209 * 210 * @param int $ site_id Optional siteID for which to query the options. Defaults to the current site.210 * @param int $network_id Optional network ID for which to query the options. Defaults to the current site. 211 211 */ 212 function wp_load_core_site_options( $ site_id = null ) {212 function wp_load_core_site_options( $network_id = null ) { 213 213 global $wpdb; 214 214 215 215 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) 216 216 return; 217 217 218 if ( empty($site_id) ) 219 $site_id = $wpdb->siteid; 220 221 $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' ); 222 223 $core_options_in = "'" . implode("', '", $core_options) . "'"; 224 $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", $site_id) ); 225 226 foreach ( $options as $option ) { 227 $key = $option->meta_key; 228 $cache_key = "{$site_id}:$key"; 229 $option->meta_value = maybe_unserialize( $option->meta_value ); 230 231 wp_cache_set( $cache_key, $option->meta_value, 'site-options' ); 218 if ( empty( $network_id ) ) { 219 $network_id = $wpdb->siteid; 232 220 } 221 222 update_networkmeta_cache( $network_id ); 233 223 } 234 224 235 225 /** … … 1091 1081 * @return mixed Value set for the option. 1092 1082 */ 1093 1083 function get_network_option( $network_id, $option, $default = false ) { 1094 global $wpdb;1095 1084 1096 1085 if ( $network_id && ! is_numeric( $network_id ) ) { 1097 1086 return false; … … 1127 1116 return $pre; 1128 1117 } 1129 1118 1130 // prevent non-existent options from triggering multiple queries 1131 $notoptions_key = "$network_id:notoptions"; 1132 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1133 1134 if ( isset( $notoptions[ $option ] ) ) { 1135 1136 /** 1137 * Filters a specific default network option. 1138 * 1139 * The dynamic portion of the hook name, `$option`, refers to the option name. 1140 * 1141 * @since 3.4.0 1142 * @since 4.4.0 The `$option` parameter was added. 1143 * @since 4.7.0 The `$network_id` parameter was added. 1144 * 1145 * @param mixed $default The value to return if the site option does not exist 1146 * in the database. 1147 * @param string $option Option name. 1148 * @param int $network_id ID of the network. 1149 */ 1150 return apply_filters( "default_site_option_{$option}", $default, $option, $network_id ); 1151 } 1119 /** 1120 * Filters a specific default network option. 1121 * 1122 * The dynamic portion of the hook name, `$option`, refers to the option name. 1123 * 1124 * @since 3.4.0 1125 * @since 4.4.0 The `$option` parameter was added. 1126 * @since 4.7.0 The `$network_id` parameter was added. 1127 * 1128 * @param mixed $default The value to return if the site option does not exist 1129 * in the database. 1130 * @param string $option Option name. 1131 * @param int $network_id ID of the network. 1132 */ 1133 $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1152 1134 1153 1135 if ( ! is_multisite() ) { 1154 /** This filter is documented in wp-includes/option.php */1155 $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );1156 1136 $value = get_option( $option, $default ); 1157 1137 } else { 1158 $cache_key = "$network_id:$option"; 1159 $value = wp_cache_get( $cache_key, 'site-options' ); 1160 1161 if ( ! isset( $value ) || false === $value ) { 1162 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1163 1164 // Has to be get_row instead of get_var because of funkiness with 0, false, null values 1165 if ( is_object( $row ) ) { 1166 $value = $row->meta_value; 1167 $value = maybe_unserialize( $value ); 1168 wp_cache_set( $cache_key, $value, 'site-options' ); 1169 } else { 1170 if ( ! is_array( $notoptions ) ) { 1171 $notoptions = array(); 1172 } 1173 $notoptions[ $option ] = true; 1174 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1175 1176 /** This filter is documented in wp-includes/option.php */ 1177 $value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1178 } 1138 $meta = get_network_meta( $network_id, $option ); 1139 if ( is_array( $meta ) && ! empty( $meta ) ) { 1140 $value = array_shift( $meta ); 1141 } else { 1142 $value = $default; 1179 1143 } 1180 1144 } 1181 1145 … … 1213 1177 * @return bool False if option was not added and true if option was added. 1214 1178 */ 1215 1179 function add_network_option( $network_id, $option, $value ) { 1216 global $wpdb;1217 1180 1218 1181 if ( $network_id && ! is_numeric( $network_id ) ) { 1219 1182 return false; … … 1244 1207 */ 1245 1208 $value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id ); 1246 1209 1247 $notoptions_key = "$network_id:notoptions";1248 1249 1210 if ( ! is_multisite() ) { 1250 1211 $result = add_option( $option, $value, '', 'no' ); 1251 1212 } else { 1252 $cache_key = "$network_id:$option"; 1253 1254 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 1255 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1256 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1257 if ( false !== get_network_option( $network_id, $option, false ) ) { 1258 return false; 1259 } 1260 } 1261 1262 $value = sanitize_option( $option, $value ); 1263 1264 $serialized_value = maybe_serialize( $value ); 1265 $result = $wpdb->insert( $wpdb->sitemeta, array( 'site_id' => $network_id, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); 1266 1267 if ( ! $result ) { 1268 return false; 1269 } 1270 1271 wp_cache_set( $cache_key, $value, 'site-options' ); 1272 1273 // This option exists now 1274 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh 1275 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1276 unset( $notoptions[ $option ] ); 1277 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1278 } 1213 $value = sanitize_option( $option, $value ); 1214 $result = add_network_meta( $network_id, $option, $value ); 1279 1215 } 1280 1216 1281 1217 if ( $result ) { … … 1327 1263 * @return bool True, if succeed. False, if failure. 1328 1264 */ 1329 1265 function delete_network_option( $network_id, $option ) { 1330 global $wpdb;1331 1266 1332 1267 if ( $network_id && ! is_numeric( $network_id ) ) { 1333 1268 return false; … … 1357 1292 if ( ! is_multisite() ) { 1358 1293 $result = delete_option( $option ); 1359 1294 } else { 1360 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1361 if ( is_null( $row ) || ! $row->meta_id ) { 1362 return false; 1363 } 1364 $cache_key = "$network_id:$option"; 1365 wp_cache_delete( $cache_key, 'site-options' ); 1366 1367 $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) ); 1295 $result = delete_network_meta( $network_id, $option ); 1368 1296 } 1369 1297 1370 1298 if ( $result ) { … … 1415 1343 * @return bool False if value was not updated and true if value was updated. 1416 1344 */ 1417 1345 function update_network_option( $network_id, $option, $value ) { 1418 global $wpdb;1419 1346 1420 1347 if ( $network_id && ! is_numeric( $network_id ) ) { 1421 1348 return false; … … 1457 1384 return add_network_option( $network_id, $option, $value ); 1458 1385 } 1459 1386 1460 $notoptions_key = "$network_id:notoptions";1461 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1462 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {1463 unset( $notoptions[ $option ] );1464 wp_cache_set( $notoptions_key, $notoptions, 'site-options' );1465 }1466 1467 1387 if ( ! is_multisite() ) { 1468 1388 $result = update_option( $option, $value, 'no' ); 1469 1389 } else { 1470 $value = sanitize_option( $option, $value ); 1471 1472 $serialized_value = maybe_serialize( $value ); 1473 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) ); 1474 1475 if ( $result ) { 1476 $cache_key = "$network_id:$option"; 1477 wp_cache_set( $cache_key, $value, 'site-options' ); 1478 } 1390 $value = sanitize_option( $option, $value ); 1391 $result = update_network_meta( $network_id, $option, $value ); 1479 1392 } 1480 1393 1481 1394 if ( $result ) { -
src/wp-settings.php
94 94 95 95 // Load early WordPress files. 96 96 require( ABSPATH . WPINC . '/compat.php' ); 97 require( ABSPATH . WPINC . '/class-wp-list-util.php' );98 97 require( ABSPATH . WPINC . '/functions.php' ); 98 require( ABSPATH . WPINC . '/formatting.php' ); 99 require( ABSPATH . WPINC . '/meta.php' ); 100 require( ABSPATH . WPINC . '/class-wp-list-util.php' ); 99 101 require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' ); 100 102 require( ABSPATH . WPINC . '/class-wp.php' ); 101 103 require( ABSPATH . WPINC . '/class-wp-error.php' ); … … 119 121 if ( is_multisite() ) { 120 122 require( ABSPATH . WPINC . '/class-wp-site-query.php' ); 121 123 require( ABSPATH . WPINC . '/class-wp-network-query.php' ); 124 require( ABSPATH . WPINC . '/ms-functions.php' ); 122 125 require( ABSPATH . WPINC . '/ms-blogs.php' ); 123 126 require( ABSPATH . WPINC . '/ms-settings.php' ); 124 127 } elseif ( ! defined( 'MULTISITE' ) ) { … … 142 145 // Load most of WordPress. 143 146 require( ABSPATH . WPINC . '/class-wp-walker.php' ); 144 147 require( ABSPATH . WPINC . '/class-wp-ajax-response.php' ); 145 require( ABSPATH . WPINC . '/formatting.php' );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' ); … … 244 245 245 246 // Load multisite-specific files. 246 247 if ( is_multisite() ) { 247 require( ABSPATH . WPINC . '/ms-functions.php' );248 248 require( ABSPATH . WPINC . '/ms-default-filters.php' ); 249 249 require( ABSPATH . WPINC . '/ms-deprecated.php' ); 250 250 } -
tests/phpunit/includes/testcase.php
301 301 $wp_object_cache->__remoteset(); 302 302 } 303 303 wp_cache_flush(); 304 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' ) );304 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' ) ); 305 305 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 306 306 } 307 307 -
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
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)