wp_get_sites( array $args = array() ): array[]
- Since
- 3.7.0
- Source
wp-includes/ms-deprecated.php:482
Compatibility
Deprecated in WordPress 4.6.0. Use get_sites()
- WordPress
- since 3.7.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
$argsarrayoptional- Array of default arguments. Optional.Default:
array()$network_idint|int[]A network ID or array of network IDs. Set to null to retrieve sites from all networks. Defaults to current network ID.$publicintdefault: null, for anyRetrieve public or non-public sites.$archivedintdefault: null, for anyRetrieve archived or non-archived sites.$matureintdefault: null, for anyRetrieve mature or non-mature sites.$spamintdefault: null, for anyRetrieve spam or non-spam sites.$deletedintdefault: null, for anyRetrieve deleted or non-deleted sites.$limitintdefault: 100Number of sites to limit the query to.$offsetintdefault: 0Exclude the first x sites. Used in combination with the $limit parameter.
Return value
array[]- An empty array if the installation is considered "large" via wp_is_large_network(). Otherwise, an associative array of WP_Site data as arrays.
Performance profile
How much work a call to wp_get_sites() 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
- Light
- Scaling
- Scales with input
- Instructions
- 10–53
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 69.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below wp_get_sites()
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_sites() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
wp_is_large_network() | 10 | _deprecated_function(), wp_is_large_network() |
!wp_is_large_network() | 43–53 | _deprecated_function(), wp_is_large_network(), get_current_network_id(), wp_parse_args(), get_sites() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 69 | 10–53 | 6 | |
| 8.5 | 69 | 10–53 | 6 | |
| 8.4 | 69 | 10–53 | 6 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 71 | 10–55 | 6 | |
| 8.2 | 71 | 10–55 | 6 | |
| 8.1 | 71 | 10–55 | 6 | |
| 7.4 | 71 | 10–55 | 6 |
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.
Uses · 6
- _deprecated_function()Marks a function as deprecated and inform when it has been used.
- wp_is_large_network()Determines whether or not we have a large network.
- get_current_network_id()Retrieves the current network ID.
- wp_parse_args()Merges user defined arguments into defaults array.
- get_sites()Retrieves a list of sites matching requested arguments.
- get_site()Retrieves site data given a site ID or site object.
Source code
function wp_get_sites( $args = array() ) { _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' ); if ( wp_is_large_network() ) return array(); $defaults = array( 'network_id' => get_current_network_id(), 'public' => null, 'archived' => null, 'mature' => null, 'spam' => null, 'deleted' => null, 'limit' => 100, 'offset' => 0, ); $args = wp_parse_args( $args, $defaults ); // Backward compatibility. if( is_array( $args['network_id'] ) ){ $args['network__in'] = $args['network_id']; $args['network_id'] = null; } if( is_numeric( $args['limit'] ) ){ $args['number'] = $args['limit']; $args['limit'] = null; } elseif ( ! $args['limit'] ) { $args['number'] = 0; $args['limit'] = null; } // Make sure count is disabled. $args['count'] = false; $_sites = get_sites( $args ); $results = array(); foreach ( $_sites as $_site ) { $_site = get_site( $_site ); $results[] = $_site->to_array(); } return $results;}Changelog
Introduced in 3.7.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-deprecated.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.