On this page
WP_Network::get_instance( int $network_id ): WP_Network|false
Retrieves a network from the database by its ID.
Parameters
$network_idint Required-
The ID of the network to retrieve.
Return
WP_Network|false The network's object if found. False if not.
Source
File: wp-includes/class-wp-network.php. View all references
public static function get_instance( $network_id ) {
global $wpdb;
$network_id = (int) $network_id;
if ( ! $network_id ) {
return false;
}
$_network = wp_cache_get( $network_id, 'networks' );
if ( false === $_network ) {
$_network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->site} WHERE id = %d LIMIT 1", $network_id ) );
if ( empty( $_network ) || is_wp_error( $_network ) ) {
$_network = -1;
}
wp_cache_add( $network_id, $_network, 'networks' );
}
if ( is_numeric( $_network ) ) {
return false;
}
return new WP_Network( $_network );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Network::__construct() wp-includes/class-wp-network.php | Creates a new WP_Network object. |
| wp_cache_add() wp-includes/cache.php | Adds data to the cache, if the cache key doesn’t already exist. |
| wpdb::get_row() wp-includes/class-wpdb.php | Retrieves one row from the database. |
| wp_cache_get() wp-includes/cache.php | Retrieves the cache contents from the cache by key and group. |
| wpdb::prepare() wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| get_network() wp-includes/ms-network.php | Retrieves network data given a network ID or network object. |
| ms_load_current_site_and_network() wp-includes/ms-load.php | Identifies the network and site of a requested domain and path and populates the corresponding network and site global objects as part of the multisite bootstrap process. |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_network/get_instance