mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Multisite: Introduce get_main_site_id().
This function can be used to easily get the main site ID of a given network via the optional `$network_id` parameter, which defaults to the current network. The existing `is_main_site()` now uses the new function internally and now accepts an optional `$network_id` parameter as well. The main purpose of the new function at this point is to ensure that the `WP_Network::$blog_id` property is always set. Magic getters in the class have been adjusted to auto-fill the property when it is accessed and empty. Furthermore the function encapsulates logic that was previously part of `ms_load_current_site_and_network()` and has been replaced with a call to the function now. Props spacedmonkey, jeremyfelt, johnjamesjacoby, flixos90. Fixes #29684. git-svn-id: https://develop.svn.wordpress.org/trunk@41380 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -148,9 +148,9 @@ class WP_Network {
|
||||
case 'id':
|
||||
return (int) $this->id;
|
||||
case 'blog_id':
|
||||
return $this->blog_id;
|
||||
return $this->get_main_site_id();
|
||||
case 'site_id':
|
||||
return (int) $this->blog_id;
|
||||
return (int) $this->get_main_site_id();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -201,6 +201,25 @@ class WP_Network {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the main site ID for the network.
|
||||
*
|
||||
* Internal method used by the magic getter for the 'blog_id' and 'site_id'
|
||||
* properties.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @see get_main_site_id()
|
||||
*
|
||||
* @return string Main site ID as numeric string, for compatibility reasons.
|
||||
*/
|
||||
private function get_main_site_id() {
|
||||
if ( empty( $this->blog_id ) ) {
|
||||
$this->blog_id = (string) get_main_site_id( $this->id );
|
||||
}
|
||||
|
||||
return $this->blog_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the site name assigned to the network if one has not been populated.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user