Multisite: Introduce `get_current_network_id()`
Similar to `get_current_blog_id`, this can be used to get the ID of the `$current_site` global. If not available, it will fallback to the main network ID. In single site, this will return 1. Props spacedmonkey, flixos90. Fixes #33900. git-svn-id: https://develop.svn.wordpress.org/trunk@37670 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8f79db7e54
commit
15a12ce4f0
|
@ -4255,9 +4255,11 @@ function get_main_network_id() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$current_site = get_current_site();
|
||||||
|
|
||||||
if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
|
if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
|
||||||
$main_network_id = PRIMARY_NETWORK_ID;
|
$main_network_id = PRIMARY_NETWORK_ID;
|
||||||
} elseif ( 1 === (int) get_current_site()->id ) {
|
} elseif ( isset( $current_site->id ) && 1 === (int) $current_site->id ) {
|
||||||
// If the current network has an ID of 1, assume it is the main network.
|
// If the current network has an ID of 1, assume it is the main network.
|
||||||
$main_network_id = 1;
|
$main_network_id = 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -807,6 +807,29 @@ function get_current_blog_id() {
|
||||||
return absint($blog_id);
|
return absint($blog_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the current network ID.
|
||||||
|
*
|
||||||
|
* @since 4.6.0
|
||||||
|
*
|
||||||
|
* @global WP_Network $current_site The current network.
|
||||||
|
*
|
||||||
|
* @return int The ID of the current network.
|
||||||
|
*/
|
||||||
|
function get_current_network_id() {
|
||||||
|
if ( ! is_multisite() ) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current_site = get_current_site();
|
||||||
|
|
||||||
|
if ( ! isset( $current_site->id ) ) {
|
||||||
|
return get_main_network_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
return absint( $current_site->id );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt an early load of translations.
|
* Attempt an early load of translations.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue