get_network( WP_Network|int|null $network = null ): WP_Network|null
- Since
- 4.6.0
- Source
wp-includes/ms-network.php:23
Description
Network data will be cached and returned after being passed through a filter.
If the provided network is empty, the current network global will be used.
Compatibility
- WordPress
- since 4.6.0
- PHP
- 7.4–8.6-dev
- 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), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$networkWP_Network|int|nulloptional- Network to retrieve. Default is the current network.Default:
null
Return value
WP_Network|null- The network object or null if not found.
Performance profile
How much work a call to get_network() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 10–23
- Plugin surface
- 1 hook
- Called by
- 31
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 30.
Third-party callbacks on 'get_network' run inside this call, and their cost is not bounded by anything here.
31 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_network() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 10–18 | none |
!($network instanceof) && !is_object($network) | 14–17 | ::WP_Network() |
| always | 15–23 | apply_filters() |
!($network instanceof) && !is_object($network) | 19–22 | ::WP_Network(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 30 instructions, 10–23 executed per call, 5 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while get_network() runs, in this order:
Uses · 3
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Network::__construct()Creates a new WP_Network object.
- WP_Network::get_instance()Retrieves a network from the database by its ID.
Used by · 31
- WP_MS_Users_List_Table::column_blogs()Handles the sites column output.
- WP_Network_Query::get_networks()Gets a list of networks matching the query vars.
- add_new_user_to_blog()Adds a newly created user to the appropriate blog
- fix_phpmailer_messageid()Corrects From host on outgoing mail to match the site domain.
- get_current_network_id()Retrieves the current network ID.
- get_dashboard_blog()Get the "dashboard blog", the blog where users without a blog edit their profile data.
- get_id_from_blogname()Retrieves a site's ID given its (subdomain or directory) slug.
- get_main_network_id()Gets the main network ID.
- get_main_site_id()Gets the main site ID.
- get_oembed_response_data_for_url()Retrieves the oEmbed response data for a given URL.
- install_blog()Install an empty blog.
- ms_allowed_http_request_hosts()Adds any domain in a multisite installation for safe HTTP requests to the allowed list.
Show all 31
- ms_cookie_constants()Defines Multisite cookie constants.
- ms_site_check()Checks status of current blog.
- network_home_url()Retrieves the home URL for the current network.
- network_site_url()Retrieves the site URL for the current network.
- populate_network()Populate network settings.
- redirect_this_site()Ensures that the current site's domain is listed in the allowed redirect host list.
- retrieve_password()Handles sending a password retrieval email to a user.
- show_blog_form()Generates and displays the Sign-up and Create Site forms.
- signup_another_blog()Shows a form for returning users to sign up for another site.
- signup_user()Shows a form for a visitor to sign up for a new user account.
- wp_admin_bar_site_menu()Adds the "Site Name" menu.
- wp_get_network()Retrieves an object containing information about the requested network.
- wp_initialize_site()Runs the initialization routine for a given site.
- wp_install_defaults()Creates the initial content for a newly-installed site.
- wpmu_delete_blog()Deletes a site.
- wpmu_new_site_admin_notification()Notifies the Multisite network administrator that a new site was created.
- wpmu_validate_blog_signup()Processes new site registrations.
- wpmu_welcome_notification()Notifies the site administrator that their site activation was successful.
- wpmu_welcome_user_notification()Notifies a user that their account activation has been successful.
Source code
function get_network( $network = null ) { global $current_site; if ( empty( $network ) && isset( $current_site ) ) { $network = $current_site; } if ( $network instanceof WP_Network ) { $_network = $network; } elseif ( is_object( $network ) ) { $_network = new WP_Network( $network ); } else { $_network = WP_Network::get_instance( $network ); } if ( ! $_network ) { return null; } /** * Fires after a network is retrieved. * * @since 4.6.0 * * @param WP_Network $_network Network data. */ $_network = apply_filters( 'get_network', $_network ); return $_network;}Changelog
Introduced in 4.6.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 7.0.4 tag, from
src/wp-includes/ms-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.