wppaste
WordPress

WP_MS_Sites_List_Table::get_views(): array

Since
5.3.0
Source
wp-admin/includes/class-wp-ms-sites-list-table.php:228
Gets links to filter sites by status.

Compatibility

WordPress
since 5.3.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

Performance profile

How much work a call to WP_MS_Sites_List_Table::get_views() 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 how much data it finds.

Instructions
49–57

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

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 callbacksapply_filters()one call below WP_MS_Sites_List_Table::get_views()

Further down the call graph this can also reach query, option, cache, serialize 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_MS_Sites_List_Table::get_views() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!isset($value)49–50wp_count_sites(), _nx_noop(), _n_noop(), _n_noop(), _n_noop(), _nx_noop(), _n_noop(), ->get_views_links()
isset($value)56–57wp_count_sites(), _nx_noop(), _n_noop(), _n_noop(), _n_noop(), _nx_noop(), _n_noop(), wp_unslash(), ->get_views_links()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10249–5672 fewer instructions than PHP 8.5
8.510449–577
8.410449–5772 fewer instructions than PHP 8.3
8.310649–597
8.210649–597
8.110649–597
7.410649–597

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 · 9

  • wp_count_sites()Counts number of sites grouped by site status.
  • _nx_noop()Registers plural strings with gettext context in POT file, but does not translate them.
  • _n_noop()Registers plural strings in POT file, but does not translate them.
  • wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
  • translate_nooped_plural()Translates and returns the singular or plural form of a string that's been registered with _n_noop() or _nx_noop().
  • number_format_i18n()Converts float number to format based on the locale.
  • add_query_arg()Retrieves a modified URL query string.
  • esc_url()Checks and cleans a URL.
  • WP_MS_Sites_List_Table::get_views_links()

Source code

	protected function get_views() {		$counts = wp_count_sites(); 		$statuses = array(			/* translators: %s: Number of sites. */			'all'      => _nx_noop(				'All <span class="count">(%s)</span>',				'All <span class="count">(%s)</span>',				'sites'			), 			/* translators: %s: Number of sites. */			'public'   => _n_noop(				'Public <span class="count">(%s)</span>',				'Public <span class="count">(%s)</span>'			), 			/* translators: %s: Number of sites. */			'archived' => _n_noop(				'Archived <span class="count">(%s)</span>',				'Archived <span class="count">(%s)</span>'			), 			/* translators: %s: Number of sites. */			'mature'   => _n_noop(				'Mature <span class="count">(%s)</span>',				'Mature <span class="count">(%s)</span>'			), 			/* translators: %s: Number of sites. */			'spam'     => _nx_noop(				'Spam <span class="count">(%s)</span>',				'Spam <span class="count">(%s)</span>',				'sites'			), 			/* translators: %s: Number of sites. */			'deleted'  => _n_noop(				'Flagged for Deletion <span class="count">(%s)</span>',				'Flagged for Deletion <span class="count">(%s)</span>'			),		); 		$view_links       = array();		$requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';		$url              = 'sites.php'; 		foreach ( $statuses as $status => $label_count ) {			if ( (int) $counts[ $status ] > 0 ) {				$label = sprintf(					translate_nooped_plural( $label_count, $counts[ $status ] ),					number_format_i18n( $counts[ $status ] )				); 				$full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url ); 				$view_links[ $status ] = array(					'url'     => esc_url( $full_url ),					'label'   => $label,					'current' => $requested_status === $status || ( '' === $requested_status && 'all' === $status ),				);			}		} 		return $this->get_views_links( $view_links );	}

Changelog

Introduced in 5.3.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.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/class-wp-ms-sites-list-table.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.