get_site

Retrieves site data given a site ID or site object.

Description

(WP_Site|null) get_site( (null) $site = null ); 

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

Returns (WP_Site|null)

The site object or null if not found.

Parameters (1)

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

Usage

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

Defined (1)

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

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