get_main_network_id

Get the main network ID.

Description

(int) get_main_network_id(); 

Returns (int)

The ID of the main network.


Usage

  1. if ( !function_exists( 'get_main_network_id' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = get_main_network_id(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function get_main_network_id() { 
  2. if ( ! is_multisite() ) { 
  3. return 1; 
  4.  
  5. $current_network = get_network(); 
  6.  
  7. if ( defined( 'PRIMARY_NETWORK_ID' ) ) { 
  8. $main_network_id = PRIMARY_NETWORK_ID; 
  9. } elseif ( isset( $current_network->id ) && 1 === (int) $current_network->id ) { 
  10. // If the current network has an ID of 1, assume it is the main network. 
  11. $main_network_id = 1; 
  12. } else { 
  13. $_networks = get_networks( array( 'fields' => 'ids', 'number' => 1 ) ); 
  14. $main_network_id = array_shift( $_networks ); 
  15.  
  16. /** 
  17. * Filters the main network ID. 
  18. * @since 4.3.0 
  19. * @param int $main_network_id The ID of the main network. 
  20. */ 
  21. return (int) apply_filters( 'get_main_network_id', $main_network_id );