WP_Network
- Since
- 4.4.0
- Source
wp-includes/class-wp-network.php:24
Core class used for interacting with a multisite network.
Description
This class is used during load to populate the $current_site global and setup the current network.
This class is most useful in WordPress multi-network installations where the ability to interact with any network of sites is required.
Compatibility
- WordPress
- since 4.4.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 3
Every hook that fires from inside WP_Network, in the order it appears in the class, grouped by the method that fires it.
WP_Network::get_by_path()
- apply_filters( network_by_path_segments_count )filter line 383
- apply_filters( pre_get_network_by_path )filter line 417
Properties · 6
$idintprivate- Network ID.
$domainstringpublic- Domain of the network.
$pathstringpublic- Path of the network.
$blog_idstringprivate- The ID of the network's main site.
$cookie_domainstringpublic- Domain used to set cookies for this network.
$site_namestringpublic- Name of this network.
Methods · 9
- get_instance()Retrieves a network from the database by its ID.
- __construct()Creates a new WP_Network object.
- __get()Getter.
- __isset()Isset-er.
- __set()Setter.
- get_main_site_id()Returns the main site ID for the network.
- _set_site_name()Sets the site name assigned to the network if one has not been populated.
- _set_cookie_domain()Sets the cookie domain based on the network domain if one has not been populated.
- get_by_path()Retrieves the closest matching network for a domain and path.
Source code
#[AllowDynamicProperties]class WP_Network { /** * Network ID. * * @since 4.4.0 * @since 4.6.0 Converted from public to private to explicitly enable more intuitive * access via magic methods. As part of the access change, the type was * also changed from `string` to `int`. * @var int */ private $id; /** * Domain of the network. * * @since 4.4.0 * @var string */ public $domain = ''; /** * Path of the network. * * @since 4.4.0 * @var string */ public $path = ''; /** * The ID of the network's main site. * * Named "blog" vs. "site" for legacy reasons. A main site is mapped to * the network when the network is created. * * A numeric string, for compatibility reasons. * * @since 4.4.0 * @var string */ private $blog_id = '0'; /** * Domain used to set cookies for this network. * * @since 4.4.0 * @var string */ public $cookie_domain = ''; /** * Name of this network. * * Named "site" vs. "network" for legacy reasons. * * @since 4.4.0 * @var string */ public $site_name = ''; /** * Retrieves a network from the database by its ID. * * @since 4.4.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $network_id The ID of the network to retrieve. * @return WP_Network|false The network's object if found. False if not. */ 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' );Changelog
Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-wp-network.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.