Ticket #41936: 41936.diff
File 41936.diff, 5.8 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-network.php
148 148 case 'id': 149 149 return (int) $this->id; 150 150 case 'blog_id': 151 return $this->get_main_site_id();152 151 case 'site_id': 153 152 return (int) $this->get_main_site_id(); 154 153 } … … 208 207 * properties. 209 208 * 210 209 * @since 4.9.0 211 * @see get_main_site_id()212 210 * 213 211 * @return string Main site ID as numeric string, for compatibility reasons. 214 212 */ 215 private function get_main_site_id() { 216 if ( empty( $this->blog_id ) ) { 217 $this->blog_id = (string) get_main_site_id( $this->id ); 213 public function get_main_site_id() { 214 /** 215 * Filters the main site ID. 216 * 217 * Returning anything other than null will effectively short-circuit the function, returning 218 * the result parsed as an integer immediately. 219 * 220 * @since 4.9.0 221 * 222 * @param int|null $main_site_id If anything other than null is returned, it is interpreted as the main site ID. 223 * @param int $this_id The ID of the network for which the main site was detected. 224 */ 225 $main_site_id = apply_filters( 'pre_get_main_site_id', null, $this->id ); 226 if ( null !== $main_site_id ) { 227 $this->blog_id = (int) $main_site_id; 228 229 return $this->blog_id; 218 230 } 231 if ( ! empty( $this->blog_id ) ) { 232 return $this->blog_id; 233 } 234 219 235 236 if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && $this->domain === DOMAIN_CURRENT_SITE && $this->path === PATH_CURRENT_SITE ) 237 || ( defined( 'SITE_ID_CURRENT_SITE' ) && $this->id == SITE_ID_CURRENT_SITE ) ) { 238 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) { 239 $this->blog_id = BLOG_ID_CURRENT_SITE; 240 241 return $this->blog_id; 242 } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated. 243 $this->blog_id = BLOGID_CURRENT_SITE; 244 245 return $this->blog_id; 246 } 247 } 248 249 $site = get_site(); 250 if ( $site->domain === $this->domain && $site->path === $this->path ) { 251 $main_site_id = $site->id; 252 } else { 253 $main_site_id = wp_cache_get( 'network:' . $this->id . ':main_site', 'site-options' ); 254 if ( false === $main_site_id ) { 255 $_sites = get_sites( array( 256 'fields' => 'ids', 257 'number' => 1, 258 'domain' => $this->domain, 259 'path' => $this->path, 260 'network_id' => $this->id, 261 ) ); 262 $main_site_id = ! empty( $_sites ) ? array_shift( $_sites ) : 0; 263 264 wp_cache_add( 'network:' . $this->id . ':main_site', $main_site_id, 'site-options' ); 265 } 266 } 267 268 $this->blog_id = (int) $main_site_id; 269 270 220 271 return $this->blog_id; 221 272 } 222 273 -
src/wp-includes/functions.php
4408 4408 } 4409 4409 4410 4410 $site_id = (int) $site_id; 4411 4412 return $site_id === get_ main_site_id( $network_id );4411 //var_dump($site_id,get_network( $network_id )->site_id, ""); 4412 return $site_id === get_network( $network_id )->site_id; 4413 4413 } 4414 4414 4415 4415 /** … … 4431 4431 return 0; 4432 4432 } 4433 4433 4434 /** 4435 * Filters the main site ID. 4436 * 4437 * Returning anything other than null will effectively short-circuit the function, returning 4438 * the result parsed as an integer immediately. 4439 * 4440 * @since 4.9.0 4441 * 4442 * @param int|null $main_site_id If anything other than null is returned, it is interpreted as the main site ID. 4443 * @param int $network_id The ID of the network for which the main site was detected. 4444 */ 4445 $main_site_id = apply_filters( 'pre_get_main_site_id', null, $network->id ); 4446 if ( null !== $main_site_id ) { 4447 return (int) $main_site_id; 4448 } 4449 4450 if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && $network->domain === DOMAIN_CURRENT_SITE && $network->path === PATH_CURRENT_SITE ) 4451 || ( defined( 'SITE_ID_CURRENT_SITE' ) && $network->id == SITE_ID_CURRENT_SITE ) ) { 4452 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) { 4453 return BLOG_ID_CURRENT_SITE; 4454 } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated. 4455 return BLOGID_CURRENT_SITE; 4456 } 4457 } 4458 4459 $site = get_site(); 4460 if ( $site->domain === $network->domain && $site->path === $network->path ) { 4461 $main_site_id = (int) $site->id; 4462 } else { 4463 $main_site_id = wp_cache_get( 'network:' . $network->id . ':main_site', 'site-options' ); 4464 if ( false === $main_site_id ) { 4465 $_sites = get_sites( array( 4466 'fields' => 'ids', 4467 'number' => 1, 4468 'domain' => $network->domain, 4469 'path' => $network->path, 4470 'network_id' => $network->id, 4471 ) ); 4472 $main_site_id = ! empty( $_sites ) ? array_shift( $_sites ) : 0; 4473 4474 wp_cache_add( 'network:' . $network->id . ':main_site', $main_site_id, 'site-options' ); 4475 } 4476 } 4477 4478 return (int) $main_site_id; 4434 return $network->site_id; 4479 4435 } 4480 4436 4481 4437 /** -
src/wp-includes/ms-load.php
423 423 } 424 424 425 425 // Figure out the current network's main site. 426 if ( empty( $current_site->blog_id ) ) { 427 $current_site->blog_id = get_main_site_id( $current_site->id ); 428 } 426 $current_site->get_main_site_id(); 429 427 430 428 return true; 431 429 } -
tests/phpunit/tests/multisite/site.php
14 14 protected static $site_ids; 15 15 16 16 function setUp() { 17 global $wpdb ;17 global $wpdb, $current_site; 18 18 parent::setUp(); 19 19 $this->suppress = $wpdb->suppress_errors(); 20 $current_site->site_id = 0; 21 $current_site->blog_id = 0; 20 22 } 21 23 22 24 function tearDown() {