WP_Posts_List_Table::prepare_items()
- Source
wp-admin/includes/class-wp-posts-list-table.php:154
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.
Performance profile
How much work a call to WP_Posts_List_Table::prepare_items() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 54–109
- Plugin surface
- 1 hook
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 130.
Third-party callbacks on 'edit_posts_per_page' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()one call below WP_Posts_List_Table::prepare_items() - cacheobject cache
wp_cache_get()one call below WP_Posts_List_Table::prepare_items()
Further down the call graph this can also reach 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 · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Posts_List_Table::prepare_items() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($value) | 54–62 | get_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), total_items() |
!empty($value) | 60–69 | set_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), total_items() |
empty($value) && !$wp_query | 60–66 | get_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), total_items() |
!empty($value) && !$wp_query | 66–73 | set_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), total_items() |
empty($value) && !$wp_query && isset($value) | 74–85 | get_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_count_posts(), total_items() |
!empty($value) && !$wp_query && isset($value) | 80–92 | set_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_count_posts(), total_items() |
empty($value) && !$wp_query && !isset($value) | 80–95 | get_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_count_posts(), array_sum(), get_post_stati(), total_items() |
empty($value) && !$wp_query && isset($value) | 81–95 | get_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_count_posts(), get_current_user_id(), total_items() |
!empty($value) && !$wp_query && !isset($value) | 86–102 | set_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_count_posts(), array_sum(), get_post_stati(), total_items() |
!empty($value) && !$wp_query && isset($value) | 87–102 | set_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_count_posts(), get_current_user_id(), total_items() |
empty($value) && !$wp_query && isset($value) | 87–102 | get_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_count_posts(), get_current_user_id(), array_sum(), get_post_stati(), total_items() |
!empty($value) && !$wp_query && isset($value) | 93–109 | set_user_setting(), wp_edit_posts_query(), is_post_type_hierarchical(), ->set_hierarchical_display(), ->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_count_posts(), get_current_user_id(), array_sum(), get_post_stati(), total_items() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 130 | 54–109 | 15 | |
| 8.5 | 130 | 54–109 | 15 | |
| 8.4 | 130 | 54–109 | 15 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 133 | 54–112 | 15 | |
| 8.2 | 133 | 54–112 | 15 | |
| 8.1 | 133 | 54–112 | 15 | |
| 7.4 | 133 | 54–112 | 15 |
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_Posts_List_Table::prepare_items() runs, in this order:
- apply_filters( edit_posts_per_page )filterline 176 (+22 into the body)
Filters the number of posts displayed per page when specifically listing "posts".
Uses · 12
- set_user_setting()Adds or updates user interface setting.
- get_user_setting()Retrieves user interface setting value based on setting name.
- wp_edit_posts_query()Runs the query to fetch the posts for listing on the edit posts page.
- is_post_type_hierarchical()Determines whether the post type is hierarchical.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- 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.
- WP_Posts_List_Table::set_hierarchical_display()Sets whether the table layout should be hierarchical or not.
- WP_Posts_List_Table::get_items_per_page()
- WP_Posts_List_Table::get_pagenum()
- WP_Posts_List_Table::set_pagination_args()
Source code
public function prepare_items() { global $mode, $avail_post_stati, $wp_query, $per_page; if ( ! empty( $_REQUEST['mode'] ) ) { $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list'; set_user_setting( 'posts_list_mode', $mode ); } else { $mode = get_user_setting( 'posts_list_mode', 'list' ); } // Is going to call wp(). $avail_post_stati = wp_edit_posts_query(); $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] ); $post_type = $this->screen->post_type; $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' ); /** This filter is documented in wp-admin/includes/post.php */ $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type ); if ( $this->hierarchical_display ) { $total_items = $wp_query->post_count; } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) { $total_items = $wp_query->found_posts; } else { $post_counts = (array) wp_count_posts( $post_type, 'readable' ); if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati, true ) ) { $total_items = $post_counts[ $_REQUEST['post_status'] ]; } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) { $total_items = $this->sticky_posts_count; } elseif ( isset( $_GET['author'] ) && get_current_user_id() === (int) $_GET['author'] ) { $total_items = $this->user_posts_count; } else { $total_items = array_sum( $post_counts ); // 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_items -= $post_counts[ $state ]; } } } $this->is_trash = isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status']; $this->set_pagination_args( array( 'total_items' => $total_items, 'per_page' => $per_page, ) ); }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 7.0.4 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.