On this page
get_site( WP_Site|int|null $site = null ): WP_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.
Parameters
$siteWP_Site|int|null Optional-
Site to retrieve. Default is the current site.
Default:
null
Return
WP_Site|null The site object or null if not found.
Source
File: wp-includes/ms-site.php. View all references
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;
}
Hooks
- apply_filters( 'get_site',
WP_Site $_site ) -
Fires after a site is retrieved.
Related
Uses
| Uses | Description |
|---|---|
| WP_Site::__construct() wp-includes/class-wp-site.php | Creates a new WP_Site object. |
| WP_Site::get_instance() wp-includes/class-wp-site.php | Retrieves a site from the database by its ID. |
| get_current_blog_id() wp-includes/load.php | Retrieve the current site ID. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| wpmu_new_site_admin_notification() wp-includes/ms-functions.php | Notifies the Multisite network administrator that a new site was created. |
| wp_initialize_site() wp-includes/ms-site.php | Runs the initialization routine for a given site. |
| wp_uninitialize_site() wp-includes/ms-site.php | Runs the uninitialization routine for a given site. |
| wp_insert_site() wp-includes/ms-site.php | Inserts a new site into the database. |
| wp_update_site() wp-includes/ms-site.php | Updates a site in the database. |
| wp_delete_site() wp-includes/ms-site.php | Deletes a site from the database. |
| WP_Network::get_main_site_id() wp-includes/class-wp-network.php | Returns the main site ID for the network. |
| WP_REST_Users_Controller::create_item() wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php | Creates a single user. |
| WP_Site_Query::get_sites() wp-includes/class-wp-site-query.php | Retrieves a list of sites matching the query vars. |
| wpmu_delete_blog() wp-admin/includes/ms.php | Delete a site. |
| is_user_member_of_blog() wp-includes/user.php | Finds out whether a user is a member of a given blog. |
| wp_get_sites() wp-includes/ms-deprecated.php | Return an array of sites for a network or networks. |
| get_active_blog_for_user() wp-includes/ms-functions.php | Gets one of a user’s active blogs. |
| add_user_to_blog() wp-includes/ms-functions.php | Adds a user to a blog, along with specifying the user’s role. |
| ms_site_check() wp-includes/ms-load.php | Checks status of current blog. |
| get_dashboard_blog() wp-includes/ms-deprecated.php | Get the “dashboard blog”, the blog where users without a blog edit their profile data. |
| get_blog_status() wp-includes/ms-blogs.php | Get a blog details field. |
| clean_blog_cache() wp-includes/ms-site.php | Clean the blog cache |
| get_blogaddress_by_id() wp-includes/ms-blogs.php | Get a full blog URL, given a blog ID. |
| wp_xmlrpc_server::_multisite_getUsersBlogs() wp-includes/class-wp-xmlrpc-server.php | Private function for retrieving a users blogs for multisite setups |
Changelog
| Version | Description |
|---|---|
| 4.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_site