WP_Network_Query::get_networks(): array|int
- Since
- 4.6.0
- Source
wp-includes/class-wp-network-query.php:198
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.
Return value
array|int- List of WP_Network objects, a list of network IDs when 'fields' is set to 'ids', or the number of networks when 'count' is passed as a query var.
Performance profile
How much work a call to WP_Network_Query::get_networks() 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
- Moderate
- Scaling
- Scales with input
- Instructions
- 21–121
- Plugin surface
- 3 hooks
- Called by
- 1
Only touches the object cache, via wp_cache_get_last_changed().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 147.
Third-party callbacks on 'pre_get_networks', 'networks_pre_query', 'the_networks' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action_ref_array()called directly - cacheobject cache
wp_cache_get_last_changed()called directly - serializeserialisation
serialize()called directly
What one call costs · 25 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Network_Query::get_networks() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$network_data !== null | 21–26 | ->parse_query() |
$network_data === null && $cache_value !== false | 62–65 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted() |
$network_data === null && $cache_value !== false | 73–76 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), array_map() |
$network_data === null && $cache_value === false | 73–76 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), wp_cache_set_salted() |
$network_data === null && $cache_value !== false | 75 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ceil() |
$network_data === null && $cache_value === false | 75–78 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), ->set_found_networks(), wp_cache_set_salted() |
$network_data === null && $cache_value === false | 84–87 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), wp_cache_set_salted(), array_map() |
$network_data === null && $cache_value !== false | 86 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ceil(), array_map() |
$network_data === null && $cache_value === false | 86 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), wp_cache_set_salted(), ceil() |
$network_data === null && $cache_value === false | 86–89 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), ->set_found_networks(), wp_cache_set_salted(), array_map() |
$network_data === null && $cache_value === false | 88 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), ->set_found_networks(), wp_cache_set_salted(), ceil() |
$network_data === null && $cache_value !== false | 91–95 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), array_map(), array_map() |
13 further outcomes, up to 121 instructions
$network_data === null && $cache_value !== false | 94–98 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), array_map(), _prime_network_caches(), array_map() |
$network_data === null && $cache_value === false | 97 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), wp_cache_set_salted(), ceil(), array_map() |
$network_data === null && $cache_value === false | 99 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), ->set_found_networks(), wp_cache_set_salted(), ceil(), array_map() |
$network_data === null && $cache_value === false | 102–106 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), wp_cache_set_salted(), array_map(), array_map() |
$network_data === null && $cache_value !== false | 104–105 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ceil(), array_map(), array_map() |
$network_data === null && $cache_value === false | 104–108 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), ->set_found_networks(), wp_cache_set_salted(), array_map(), array_map() |
$network_data === null && $cache_value === false | 105–109 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), wp_cache_set_salted(), array_map(), _prime_network_caches(), array_map() |
$network_data === null && $cache_value !== false | 107–108 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ceil(), array_map(), _prime_network_caches(), array_map() |
$network_data === null && $cache_value === false | 107–111 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), ->set_found_networks(), wp_cache_set_salted(), array_map(), _prime_network_caches(), array_map() |
$network_data === null && $cache_value === false | 115–116 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), wp_cache_set_salted(), ceil(), array_map(), array_map() |
$network_data === null && $cache_value === false | 117–118 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), ->set_found_networks(), wp_cache_set_salted(), ceil(), array_map(), array_map() |
$network_data === null && $cache_value === false | 118–119 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), wp_cache_set_salted(), ceil(), array_map(), _prime_network_caches(), array_map() |
$network_data === null && $cache_value === false | 120–121 | ->parse_query(), array_keys(), wp_array_slice_assoc(), serialize(), md5(), wp_cache_get_last_changed(), wp_cache_get_salted(), ->get_network_ids(), ->set_found_networks(), wp_cache_set_salted(), ceil(), array_map(), _prime_network_caches(), array_map() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 147 instructions, 21–121 executed per call, 13 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 · 3
3 hooks fire while WP_Network_Query::get_networks() runs, in this order:
- apply_filters( networks_pre_query )filterline 242 (+44 into the body)
Filters the network data before the query takes place.
Uses · 11
- do_action_ref_array()Calls the callback functions that have been added to an action hook, specifying arguments in an array.
- apply_filters_ref_array()Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
- wp_array_slice_assoc()Extracts a slice of an array, given a list of keys.
- wp_cache_get_last_changed()Gets last changed date for the specified cache group.
- wp_cache_get_salted()Retrieves cached data if valid and unchanged.
- wp_cache_set_salted()Stores salted data in the cache.
- _prime_network_caches()Adds any networks from the given IDs to the cache that do not already exist in cache.
- get_network()Retrieves network data given a network ID or network object.
- WP_Network_Query::parse_query()Parses arguments passed to the network query with default query parameters.
- WP_Network_Query::get_network_ids()Used internally to get a list of network IDs matching the query vars.
- WP_Network_Query::set_found_networks()Populates found_networks and max_num_pages properties for the current query if the limit clause was used.
Used by · 1
- WP_Network_Query::query()Sets up the WordPress query for retrieving networks.
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.1.0 tag, from
src/wp-includes/class-wp-network-query.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.