WP_Network::get_instance() WordPress Method

The WP_Network::get_instance() method is used to retrieve the network object. This can be used to access information and options related to the network.

WP_Network::get_instance( int $network_id ) #

Retrieve a network from the database by its ID.


Parameters

$network_id

(int)(Required)The ID of the network to retrieve.


Top ↑

Return

(WP_Network|false) The network's object if found. False if not.


Top ↑

Source

File: wp-includes/class-wp-network.php

	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 );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.4.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.