WP_Comments_List_Table::prepare_items()
- Source
wp-admin/includes/class-wp-comments-list-table.php:86
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_Comments_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
- Constant
- Instructions
- 111–164
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_comments().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 196.
Third-party callbacks on 'comments_list_table_query_args' 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 - querycontent query
get_comments()called directly
Further down the call graph this can also reach serialize, cache, option 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_Comments_List_Table::prepare_items() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($value) && !isset($value) && $comment_status && !is_array($_comments) | 111–133 | get_user_setting(), ->get_per_page(), wp_doing_ajax(), ->get_pagenum(), apply_filters(), get_comments(), array_merge(), get_comments(), total_items() |
empty($value) && $comment_status && !is_array($_comments) | 118–138 | get_user_setting(), sanitize_key(), ->get_per_page(), wp_doing_ajax(), ->get_pagenum(), apply_filters(), get_comments(), array_merge(), get_comments(), total_items() |
empty($value) && !isset($value) && $comment_status && is_array($_comments) | 137–159 | get_user_setting(), ->get_per_page(), wp_doing_ajax(), ->get_pagenum(), apply_filters(), get_comments(), array_slice(), array_slice(), wp_list_pluck(), array_unique(), get_pending_comments_num(), array_merge(), get_comments(), total_items() |
empty($value) && $comment_status && is_array($_comments) | 144–164 | get_user_setting(), sanitize_key(), ->get_per_page(), wp_doing_ajax(), ->get_pagenum(), apply_filters(), get_comments(), array_slice(), array_slice(), wp_list_pluck(), array_unique(), get_pending_comments_num(), array_merge(), get_comments(), total_items() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 195 | 111–163 | 17 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 196 | 111–164 | 17 | |
| 8.4 | 196 | 111–164 | 17 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 199 | 113–165 | 17 | |
| 8.2 | 199 | 113–165 | 17 | |
| 8.1 | 199 | 113–165 | 17 | 6 fewer instructions than PHP 7.4 |
| 7.4 | 205 | 113–169 | 17 |
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_Comments_List_Table::prepare_items() runs, in this order:
- apply_filters( comments_list_table_query_args )filterline 168 (+82 into the body)
Filters the arguments for the comment query in the comments list table.
Uses · 11
- set_user_setting()Adds or updates user interface setting.
- get_user_setting()Retrieves user interface setting value based on setting name.
- sanitize_key()Sanitizes a string key.
- wp_doing_ajax()Determines whether the current request is a WordPress Ajax request.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_comments()Retrieves a list of comments.
- wp_list_pluck()Plucks a certain field out of each object or array in an array.
- get_pending_comments_num()Gets the number of pending comments on a post or posts.
- WP_Comments_List_Table::get_per_page()
- WP_Comments_List_Table::get_pagenum()
- WP_Comments_List_Table::set_pagination_args()
Source code
public function prepare_items() { global $mode, $post_id, $comment_status, $comment_type, $search; 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' ); } $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ), true ) ) { $comment_status = 'all'; } $comment_type = ''; if ( ! empty( $_REQUEST['comment_type'] ) && 'note' !== $_REQUEST['comment_type'] ) { $comment_type = $_REQUEST['comment_type']; } $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : ''; $post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_key( $_REQUEST['post_type'] ) : ''; $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : ''; $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : ''; $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : ''; $comments_per_page = $this->get_per_page( $comment_status ); $doing_ajax = wp_doing_ajax(); if ( isset( $_REQUEST['number'] ) ) { $number = (int) $_REQUEST['number']; } else { $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra. } $page = $this->get_pagenum(); if ( isset( $_REQUEST['start'] ) ) { $start = $_REQUEST['start']; } else { $start = ( $page - 1 ) * $comments_per_page; } if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) { $start += $_REQUEST['offset']; } $status_map = array( 'mine' => '', 'moderated' => 'hold', 'approved' => 'approve', 'all' => '', ); $args = array( 'status' => isset( $status_map[ $comment_status ] ) ? $status_map[ $comment_status ] : $comment_status, 'search' => $search, 'user_id' => $user_id, 'offset' => $start, 'number' => $number, 'post_id' => $post_id, 'type' => $comment_type, 'type__not_in' => array( 'note' ), 'orderby' => $orderby, 'order' => $order, 'post_type' => $post_type, 'update_comment_post_cache' => true, ); /** * Filters the arguments for the comment query in the comments list table. * * @since 5.1.0 *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.9.7 tag, from
src/wp-admin/includes/class-wp-comments-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.