wppaste
WordPress

wp_get_sites( array $args = array() ): array[]

Since
3.7.0
Source
wp-includes/ms-deprecated.php:482
Return an array of sites for a network or networks.

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 any

    Retrieve public or non-public sites.
  • $archivedintdefault: null, for any

    Retrieve archived or non-archived sites.
  • $matureintdefault: null, for any

    Retrieve mature or non-mature sites.
  • $spamintdefault: null, for any

    Retrieve spam or non-spam sites.
  • $deletedintdefault: null, for any

    Retrieve deleted or non-deleted sites.
  • $limitintdefault: 100

    Number of sites to limit the query to.
  • $offsetintdefault: 0

    Exclude 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
10–53

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 69.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksdo_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.

WhenInstructionsCalls 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

PHPCompiledExecutedBranchesNotes
8.6-dev6910–536
8.56910–536
8.46910–5362 fewer instructions than PHP 8.3
8.37110–556
8.27110–556
8.17110–556
7.47110–556

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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

4.6.0
Deprecated. Use get_sites()from the docblock
3.7.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 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.