WP_Posts_List_Table::get_views(): array
- Source
wp-admin/includes/class-wp-posts-list-table.php:289
Compatibility
- WordPress
- core
- 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_Posts_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
- Moderate
- Scaling
- Scales with input
- Instructions
- 7–196
- Plugin surface
- None
- Called by
- 0
Only touches the object cache, via wp_cache_get().
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 255.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- cacheobject cache
wp_cache_get()one call below WP_Posts_List_Table::get_views() - hookthird-party callbacks
apply_filters()one call below WP_Posts_List_Table::get_views()
Further down the call graph this can also reach query, option, 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 · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Posts_List_Table::get_views() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($locked_post_status) | 7 | none |
empty($locked_post_status) && empty($value) | 70–79 | wp_count_posts(), array_sum(), get_current_user_id(), get_post_stati(), _nx(), number_format_i18n(), sprintf(), add_query_arg(), esc_url(), ->is_base_request(), get_post_stati(), ->get_views_links() |
empty($locked_post_status) && $total_posts !== false && empty($value) | 113–127 | wp_count_posts(), array_sum(), get_current_user_id(), get_post_stati(), _nx(), number_format_i18n(), sprintf(), add_query_arg(), esc_url(), _nx(), number_format_i18n(), sprintf(), add_query_arg(), esc_url(), ->is_base_request(), get_post_stati(), ->get_views_links() |
empty($locked_post_status) && !empty($value) | 137–148 | wp_count_posts(), array_sum(), get_current_user_id(), get_post_stati(), _nx(), number_format_i18n(), sprintf(), add_query_arg(), esc_url(), ->is_base_request(), get_post_stati(), _nx(), number_format_i18n(), sprintf(), add_query_arg(), esc_url(), array_keys(), array_search(), array_slice(), array_slice(), array_merge(), ->get_views_links() |
empty($locked_post_status) && $total_posts !== false && !empty($value) | 180–196 | wp_count_posts(), array_sum(), get_current_user_id(), get_post_stati(), _nx(), number_format_i18n(), sprintf(), add_query_arg(), esc_url(), _nx(), number_format_i18n(), sprintf(), add_query_arg(), esc_url(), ->is_base_request(), get_post_stati(), _nx(), number_format_i18n(), sprintf(), add_query_arg(), esc_url(), array_keys(), array_search(), array_slice(), array_slice(), array_merge(), ->get_views_links() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 255 | 7–196 | 18 | |
| 8.5 | 255 | 7–196 | 18 | |
| 8.4 | 255 | 7–196 | 18 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 258 | 7–196 | 18 | |
| 8.2 | 258 | 7–196 | 18 | |
| 8.1 | 258 | 7–196 | 18 | |
| 7.4 | 258 | 7–196 | 18 |
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 · 10
- wp_count_posts()Counts number of posts of a post type and if user has permissions to view.
- get_current_user_id()Gets the current user's ID.
- get_post_stati()Gets a list of post statuses.
- _nx()Translates and retrieves the singular or plural form based on the supplied number, with gettext context.
- number_format_i18n()Converts float number to format based on the locale.
- esc_url()Checks and cleans a URL.
- add_query_arg()Retrieves a modified URL query string.
- translate_nooped_plural()Translates and returns the singular or plural form of a string that's been registered with _n_noop() or _nx_noop().
- WP_Posts_List_Table::is_base_request()Determines if the current view is the "All" view.
- WP_Posts_List_Table::get_views_links()
Source code
protected function get_views() { global $locked_post_status, $avail_post_stati; $post_type = $this->screen->post_type; if ( ! empty( $locked_post_status ) ) { return array(); } $status_links = array(); $num_posts = wp_count_posts( $post_type, 'readable' ); $total_posts = array_sum( (array) $num_posts ); $class = ''; $current_user_id = get_current_user_id(); $all_args = array( 'post_type' => $post_type ); $mine = ''; // Subtract post types that are not included in the admin all list. foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) { $total_posts -= $num_posts->$state; } if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) { if ( isset( $_GET['author'] ) && ( $current_user_id === (int) $_GET['author'] ) ) { $class = 'current'; } $mine_args = array( 'post_type' => $post_type, 'author' => $current_user_id, ); $mine_inner_html = sprintf( /* translators: %s: Number of posts. */ _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ); $mine = array( 'url' => esc_url( add_query_arg( $mine_args, 'edit.php' ) ), 'label' => $mine_inner_html, 'current' => isset( $_GET['author'] ) && ( $current_user_id === (int) $_GET['author'] ), ); $all_args['all_posts'] = 1; $class = ''; } $all_inner_html = sprintf( /* translators: %s: Number of posts. */ _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ); $status_links['all'] = array( 'url' => esc_url( add_query_arg( $all_args, 'edit.php' ) ), 'label' => $all_inner_html, 'current' => empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ), ); if ( $mine ) { $status_links['mine'] = $mine; } foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) { $class = ''; $status_name = $status->name;Changelog
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 6.7.7 tag, from
src/wp-admin/includes/class-wp-posts-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.