get_site() WordPress Function

The get_site() function is used to get a WordPress Site object by its ID. The function accepts an integer ID as its only parameter. The function returns a WP_Site object on success or false on failure.

get_site( WP_Site|int|null $site = null ) #

Retrieves site data given a site ID or site object.


Description

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.


Top ↑

Parameters

$site

(WP_Site|int|null)(Optional) Site to retrieve. Default is the current site.

Default value: null


Top ↑

Return

(WP_Site|null) The site object or null if not found.


Top ↑

Source

File: wp-includes/ms-site.php

function get_site( $site = null ) {
	if ( empty( $site ) ) {
		$site = get_current_blog_id();
	}

	if ( $site instanceof WP_Site ) {
		$_site = $site;
	} elseif ( is_object( $site ) ) {
		$_site = new WP_Site( $site );
	} else {
		$_site = WP_Site::get_instance( $site );
	}

	if ( ! $_site ) {
		return null;
	}

	/**
	 * Fires after a site is retrieved.
	 *
	 * @since 4.6.0
	 *
	 * @param WP_Site $_site Site data.
	 */
	$_site = apply_filters( 'get_site', $_site );

	return $_site;
}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.