Make WordPress Core


Ignore:
Timestamp:
06/09/2016 08:33:35 PM (8 years ago)
Author:
jeremyfelt
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/load.php

    r37626 r37670  
    809809
    810810/**
     811 * Retrieves the current network ID.
     812 *
     813 * @since 4.6.0
     814 *
     815 * @global WP_Network $current_site The current network.
     816 *
     817 * @return int The ID of the current network.
     818 */
     819function get_current_network_id() {
     820    if ( ! is_multisite() ) {
     821        return 1;
     822    }
     823
     824    $current_site = get_current_site();
     825
     826    if ( ! isset( $current_site->id ) ) {
     827        return get_main_network_id();
     828    }
     829
     830    return absint( $current_site->id );
     831}
     832
     833/**
    811834 * Attempt an early load of translations.
    812835 *
Note: See TracChangeset for help on using the changeset viewer.