WP_MS_Sites_List_Table::site_states( array $site )
- Since
- 5.3.0
- Source
wp-admin/includes/class-wp-ms-sites-list-table.php:645
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.
Parameters
$sitearray
Performance profile
How much work a call to WP_MS_Sites_List_Table::site_states() 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
- 35–54
- Plugin surface
- 1 hook
- Called by
- 1
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 79.
Third-party callbacks on 'display_site_states' 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
apply_filters()called directly
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 · 4 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::site_states() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_main_site() && !isset($value) | 35–42 | ::WP_Site(), is_main_site(), reset(), apply_filters() |
is_main_site() && !isset($value) | 40–47 | ::WP_Site(), is_main_site(), __(), reset(), apply_filters() |
!is_main_site() && isset($value) | 42–49 | ::WP_Site(), is_main_site(), reset(), wp_unslash(), apply_filters() |
is_main_site() && isset($value) | 47–54 | ::WP_Site(), is_main_site(), __(), reset(), wp_unslash(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 78 | 35–53 | 10 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 79 | 35–54 | 10 | |
| 8.4 | 79 | 35–54 | 10 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 81 | 35–56 | 10 | |
| 8.2 | 81 | 35–56 | 10 | |
| 8.1 | 81 | 35–56 | 10 | |
| 7.4 | 81 | 35–56 | 10 |
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 WP_MS_Sites_List_Table::site_states() runs, in this order:
- apply_filters( display_site_states )filterline 673 (+28 into the body)
Filters the default site display states for items in the Sites list table.
Uses · 5
- is_main_site()Determines whether a site is the main site of the current network.
- __()Retrieves the translation of $text.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Site::get_instance()Retrieves a site from the database by its ID.
Used by · 1
- WP_MS_Sites_List_Table::column_blogname()Handles the site name column output.
Source code
protected function site_states( $site ) { $site_states = array(); // $site is still an array, so get the object. $_site = WP_Site::get_instance( $site['blog_id'] ); if ( is_main_site( $_site->id ) ) { $site_states['main'] = __( 'Main' ); } reset( $this->status_list ); $site_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : ''; foreach ( $this->status_list as $status => $col ) { if ( '1' === $_site->{$status} && $site_status !== $status ) { $site_states[ $col[0] ] = $col[1]; } } /** * Filters the default site display states for items in the Sites list table. * * @since 5.3.0 * * @param string[] $site_states An array of site states. Default 'Main', * 'Archived', 'Mature', 'Spam', 'Flagged for Deletion'. * @param WP_Site $site The current site object. */ $site_states = apply_filters( 'display_site_states', $site_states, $_site ); if ( ! empty( $site_states ) ) { $state_count = count( $site_states ); $i = 0; echo ' — '; foreach ( $site_states as $state ) { ++$i; $separator = ( $i < $state_count ) ? ', ' : ''; echo "<span class='post-state'>{$state}{$separator}</span>"; } } }Changelog
Introduced in 5.3.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$site retyped from array to untyped.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.