Ticket #37181: 37181.1.diff
File 37181.1.diff, 9.9 KB (added by , 8 years ago) |
---|
-
src/wp-includes/load.php
509 509 wp_cache_init(); 510 510 511 511 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 512 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );512 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site_meta' ) ); 513 513 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 514 514 } 515 515 } -
src/wp-includes/ms-blogs.php
814 814 if ( is_array( $global_groups ) ) { 815 815 wp_cache_add_global_groups( $global_groups ); 816 816 } else { 817 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );817 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site_meta' ) ); 818 818 } 819 819 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 820 820 } … … 885 885 if ( is_array( $global_groups ) ) { 886 886 wp_cache_add_global_groups( $global_groups ); 887 887 } else { 888 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );888 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site_meta' ) ); 889 889 } 890 890 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 891 891 } -
src/wp-includes/option.php
202 202 * 203 203 * @global wpdb $wpdb WordPress database abstraction object. 204 204 * 205 * @param int $ site_id Optional site ID for which to query the options. Defaults to the current site.205 * @param int $network_id Optional site ID for which to query the options. Defaults to the current site. 206 206 */ 207 function wp_load_core_site_options( $ site_id = null ) {207 function wp_load_core_site_options( $network_id = null ) { 208 208 global $wpdb; 209 209 210 210 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) 211 211 return; 212 212 213 if ( empty($site_id) ) 214 $site_id = $wpdb->siteid; 213 if ( empty( $network_id ) ) { 214 $network_id = $wpdb->siteid; 215 } 215 216 216 $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' ); 217 218 $core_options_in = "'" . implode("', '", $core_options) . "'"; 219 $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) ); 220 221 foreach ( $options as $option ) { 222 $key = $option->meta_key; 223 $cache_key = "{$site_id}:$key"; 224 $option->meta_value = maybe_unserialize( $option->meta_value ); 225 226 wp_cache_set( $cache_key, $option->meta_value, 'site-options' ); 227 } 217 update_meta_cache( 'site', $network_id ); 228 218 } 229 219 230 220 /** … … 1078 1068 * @return mixed Value set for the option. 1079 1069 */ 1080 1070 function get_network_option( $network_id, $option, $default = false ) { 1081 global $ wpdb, $current_site;1071 global $current_site; 1082 1072 1083 1073 if ( $network_id && ! is_numeric( $network_id ) ) { 1084 1074 return false; … … 1112 1102 return $pre; 1113 1103 } 1114 1104 1115 // prevent non-existent options from triggering multiple queries1116 $notoptions_key = "$network_id:notoptions";1117 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1118 1119 if ( isset( $notoptions[ $option ] ) ) {1120 1121 /**1122 * Filters a specific default network option.1123 *1124 * The dynamic portion of the hook name, `$option`, refers to the option name.1125 *1126 * @since 3.4.01127 * @since 4.4.0 The `$option` parameter was added.1128 *1129 * @param mixed $default The value to return if the site option does not exist1130 * in the database.1131 * @param string $option Option name.1132 */1133 return apply_filters( 'default_site_option_' . $option, $default, $option );1134 }1135 1136 1105 if ( ! is_multisite() ) { 1137 1106 /** This filter is documented in wp-includes/option.php */ 1138 1107 $default = apply_filters( 'default_site_option_' . $option, $default, $option ); 1139 1108 $value = get_option( $option, $default ); 1140 1109 } else { 1141 $cache_key = "$network_id:$option"; 1142 $value = wp_cache_get( $cache_key, 'site-options' ); 1143 1144 if ( ! isset( $value ) || false === $value ) { 1145 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1146 1147 // Has to be get_row instead of get_var because of funkiness with 0, false, null values 1148 if ( is_object( $row ) ) { 1149 $value = $row->meta_value; 1150 $value = maybe_unserialize( $value ); 1151 wp_cache_set( $cache_key, $value, 'site-options' ); 1152 } else { 1153 if ( ! is_array( $notoptions ) ) { 1154 $notoptions = array(); 1155 } 1156 $notoptions[ $option ] = true; 1157 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1158 1159 /** This filter is documented in wp-includes/option.php */ 1160 $value = apply_filters( 'default_site_option_' . $option, $default, $option ); 1161 } 1110 $meta = get_metadata( 'site', $network_id, $option ); 1111 if ( is_array( $meta ) && ! empty( $meta ) ) { 1112 $value = array_shift( $meta ); 1113 } else { 1114 $value = apply_filters( 'default_site_option_' . $option, $default, $option ); 1162 1115 } 1163 1116 } 1164 1117 … … 1195 1148 * @return bool False if option was not added and true if option was added. 1196 1149 */ 1197 1150 function add_network_option( $network_id, $option, $value ) { 1198 global $ wpdb, $current_site;1151 global $current_site; 1199 1152 1200 1153 if ( $network_id && ! is_numeric( $network_id ) ) { 1201 1154 return false; … … 1224 1177 */ 1225 1178 $value = apply_filters( 'pre_add_site_option_' . $option, $value, $option ); 1226 1179 1227 $notoptions_key = "$network_id:notoptions";1228 1229 1180 if ( ! is_multisite() ) { 1230 1181 $result = add_option( $option, $value, '', 'no' ); 1231 1182 } else { 1232 $cache_key = "$network_id:$option"; 1233 1234 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 1235 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1236 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1237 if ( false !== get_network_option( $network_id, $option, false ) ) { 1238 return false; 1239 } 1240 } 1241 1242 $value = sanitize_option( $option, $value ); 1243 1244 $serialized_value = maybe_serialize( $value ); 1245 $result = $wpdb->insert( $wpdb->sitemeta, array( 'site_id' => $network_id, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); 1246 1247 if ( ! $result ) { 1248 return false; 1249 } 1250 1251 wp_cache_set( $cache_key, $value, 'site-options' ); 1252 1253 // This option exists now 1254 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh 1255 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1256 unset( $notoptions[ $option ] ); 1257 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1258 } 1183 $result = add_metadata( 'site', $network_id, $option, $value, true ); 1259 1184 } 1260 1185 1261 1186 if ( $result ) { … … 1304 1229 * @return bool True, if succeed. False, if failure. 1305 1230 */ 1306 1231 function delete_network_option( $network_id, $option ) { 1307 global $ wpdb, $current_site;1232 global $current_site; 1308 1233 1309 1234 if ( $network_id && ! is_numeric( $network_id ) ) { 1310 1235 return false; … … 1332 1257 if ( ! is_multisite() ) { 1333 1258 $result = delete_option( $option ); 1334 1259 } else { 1335 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1336 if ( is_null( $row ) || ! $row->meta_id ) { 1337 return false; 1338 } 1339 $cache_key = "$network_id:$option"; 1340 wp_cache_delete( $cache_key, 'site-options' ); 1341 1342 $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) ); 1260 $result = delete_metadata( 'site', $network_id, $option, true ); 1343 1261 } 1344 1262 1345 1263 if ( $result ) { … … 1427 1345 return add_network_option( $network_id, $option, $value ); 1428 1346 } 1429 1347 1430 $notoptions_key = "$network_id:notoptions";1431 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1432 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {1433 unset( $notoptions[ $option ] );1434 wp_cache_set( $notoptions_key, $notoptions, 'site-options' );1435 }1436 1437 1348 if ( ! is_multisite() ) { 1438 1349 $result = update_option( $option, $value, 'no' ); 1439 1350 } else { 1440 1351 $value = sanitize_option( $option, $value ); 1441 1442 $serialized_value = maybe_serialize( $value ); 1443 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) ); 1444 1445 if ( $result ) { 1446 $cache_key = "$network_id:$option"; 1447 wp_cache_set( $cache_key, $value, 'site-options' ); 1448 } 1352 $result = update_metadata( 'site', $network_id, $option, $value ); 1449 1353 } 1450 1354 1451 1355 if ( $result ) {