Ticket #41936: 41936.2.diff
| File 41936.2.diff, 6.0 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/class-wp-network.php
150 150 case 'blog_id': 151 151 return $this->get_main_site_id(); 152 152 case 'site_id': 153 return ( int) $this->get_main_site_id();153 return (string) $this->get_main_site_id(); 154 154 } 155 155 156 156 return null; … … 208 208 * properties. 209 209 * 210 210 * @since 4.9.0 211 * @see get_main_site_id()212 211 * 213 212 * @return string Main site ID as numeric string, for compatibility reasons. 214 213 */ 215 private function get_main_site_id() { 216 if ( empty( $this->blog_id ) ) { 217 $this->blog_id = (string) get_main_site_id( $this->id ); 214 public function get_main_site_id() { 215 /** 216 * Filters the main site ID. 217 * 218 * Returning anything other than null will effectively short-circuit the function, returning 219 * the result parsed as an integer immediately. 220 * 221 * @since 4.9.0 222 * 223 * @param int|null $main_site_id If anything other than null is returned, it is interpreted as the main site ID. 224 * @param int $this_id The ID of the network for which the main site was detected. 225 */ 226 $main_site_id = apply_filters( 'pre_get_main_site_id', null, $this->id ); 227 if ( null !== $main_site_id ) { 228 $this->blog_id = (int) $main_site_id; 218 229 } 230 if ( ! empty( $this->blog_id ) ) { 231 return $this->blog_id; 232 } 219 233 234 if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && $this->domain === DOMAIN_CURRENT_SITE && $this->path === PATH_CURRENT_SITE ) 235 || ( defined( 'SITE_ID_CURRENT_SITE' ) && $this->id == SITE_ID_CURRENT_SITE ) ) { 236 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) { 237 $this->blog_id = (int) BLOG_ID_CURRENT_SITE; 238 239 return $this->blog_id; 240 } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated. 241 $this->blog_id = (int) BLOGID_CURRENT_SITE; 242 243 return $this->blog_id; 244 } 245 } 246 247 $site = get_site(); 248 if ( $site->domain === $this->domain && $site->path === $this->path ) { 249 $main_site_id = $site->id; 250 } else { 251 $main_site_id = wp_cache_get( 'network:' . $this->id . ':main_site', 'site-options' ); 252 if ( false === $main_site_id ) { 253 $_sites = get_sites( array( 254 'fields' => 'ids', 255 'number' => 1, 256 'domain' => $this->domain, 257 'path' => $this->path, 258 'network_id' => $this->id, 259 ) ); 260 $main_site_id = ! empty( $_sites ) ? array_shift( $_sites ) : 0; 261 262 wp_cache_add( 'network:' . $this->id . ':main_site', $main_site_id, 'site-options' ); 263 } 264 } 265 266 $this->blog_id = (int) $main_site_id; 267 268 220 269 return $this->blog_id; 221 270 } 222 271 -
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 /** … … 4423 4423 */ 4424 4424 function get_main_site_id( $network_id = null ) { 4425 4425 if ( ! is_multisite() ) { 4426 return 1;4426 return get_current_blog_id(); 4427 4427 } 4428 4428 4429 4429 $network = get_network( $network_id ); … … 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
422 422 } 423 423 424 424 // Figure out the current network's main site. 425 if ( empty( $current_site->blog_id ) ) { 426 $current_site->blog_id = get_main_site_id( $current_site->id ); 427 } 425 $current_site->get_main_site_id(); 428 426 429 427 return true; 430 428 } -
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() {
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)