get_network

Retrieves network data given a network ID or network object.

Description

(WP_Network|null) get_network( (null) $network = null ); 

Network data will be cached and returned after being passed through a filter. If the provided network is empty, the current network global will be used.

Returns (WP_Network|null)

The network object or null if not found.

Parameters (1)

0. $network — Optional. (null) => null
Network to retrieve. Default is the current network.

Usage

  1. if ( !function_exists( 'get_network' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-blogs.php'; 
  3.  
  4. // Optional. Network to retrieve. Default is the current network. 
  5. $network = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_network($network); 
  9.  

Defined (1)

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

/wp-includes/ms-blogs.php  
  1. function get_network( $network = null ) { 
  2. global $current_site; 
  3. if ( empty( $network ) && isset( $current_site ) ) { 
  4. $network = $current_site; 
  5.  
  6. if ( $network instanceof WP_Network ) { 
  7. $_network = $network; 
  8. } elseif ( is_object( $network ) ) { 
  9. $_network = new WP_Network( $network ); 
  10. } else { 
  11. $_network = WP_Network::get_instance( $network ); 
  12.  
  13. if ( ! $_network ) { 
  14. return null; 
  15.  
  16. /** 
  17. * Fires after a network is retrieved. 
  18. * @since 4.6.0 
  19. * @param WP_Network $_network Network data. 
  20. */ 
  21. $_network = apply_filters( 'get_network', $_network ); 
  22.  
  23. return $_network;