wp_ajax_get_comments( string $action )
- Since
- 3.1.0
- Source
wp-admin/includes/ajax-actions.php:1244
Compatibility
- WordPress
- since 3.1.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
$actionstring- Action to perform.
Performance profile
How much work a call to wp_ajax_get_comments() 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
- 45–69
- Plugin surface
- None
- Called by
- 0
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 86.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below wp_ajax_get_comments()
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 · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_ajax_get_comments() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($post_id) && current_user_can() && ->has_items() | 45–50 | check_ajax_referer(), _get_list_table(), current_user_can(), ->prepare_items(), ->has_items(), ob_start(), ob_get_clean(), comments(), ->send() |
!empty($post_id) && current_user_can() && !->has_items() | 48–53 | check_ajax_referer(), _get_list_table(), current_user_can(), ->prepare_items(), ->has_items(), wp_die(), ob_start(), ob_get_clean(), comments(), ->send() |
!empty($post_id) && !current_user_can() && ->has_items() | 48–53 | check_ajax_referer(), _get_list_table(), current_user_can(), wp_die(), ->prepare_items(), ->has_items(), ob_start(), ob_get_clean(), comments(), ->send() |
empty($post_id) && current_user_can() && ->has_items() | 48–53 | check_ajax_referer(), wp_die(), _get_list_table(), current_user_can(), ->prepare_items(), ->has_items(), ob_start(), ob_get_clean(), comments(), ->send() |
!empty($post_id) && !current_user_can() && !->has_items() | 51–56 | check_ajax_referer(), _get_list_table(), current_user_can(), wp_die(), ->prepare_items(), ->has_items(), wp_die(), ob_start(), ob_get_clean(), comments(), ->send() |
empty($post_id) && current_user_can() && !->has_items() | 51–56 | check_ajax_referer(), wp_die(), _get_list_table(), current_user_can(), ->prepare_items(), ->has_items(), wp_die(), ob_start(), ob_get_clean(), comments(), ->send() |
empty($post_id) && !current_user_can() && ->has_items() | 51–56 | check_ajax_referer(), wp_die(), _get_list_table(), current_user_can(), wp_die(), ->prepare_items(), ->has_items(), ob_start(), ob_get_clean(), comments(), ->send() |
empty($post_id) && !current_user_can() && !->has_items() | 54–59 | check_ajax_referer(), wp_die(), _get_list_table(), current_user_can(), wp_die(), ->prepare_items(), ->has_items(), wp_die(), ob_start(), ob_get_clean(), comments(), ->send() |
!empty($value) && current_user_can() && ->has_items() | 57–60 | check_ajax_referer(), absint(), _get_list_table(), current_user_can(), ->prepare_items(), ->has_items(), ob_start(), ob_get_clean(), comments(), ->send() |
!empty($value) && current_user_can() && !->has_items() | 60–63 | check_ajax_referer(), absint(), _get_list_table(), current_user_can(), ->prepare_items(), ->has_items(), wp_die(), ob_start(), ob_get_clean(), comments(), ->send() |
!empty($value) && !current_user_can() && ->has_items() | 60–63 | check_ajax_referer(), absint(), _get_list_table(), current_user_can(), wp_die(), ->prepare_items(), ->has_items(), ob_start(), ob_get_clean(), comments(), ->send() |
empty($post_id) && !empty($value) && current_user_can() && ->has_items() | 60–63 | check_ajax_referer(), absint(), wp_die(), _get_list_table(), current_user_can(), ->prepare_items(), ->has_items(), ob_start(), ob_get_clean(), comments(), ->send() |
4 further outcomes, up to 69 instructions
!empty($value) && !current_user_can() && !->has_items() | 63–66 | check_ajax_referer(), absint(), _get_list_table(), current_user_can(), wp_die(), ->prepare_items(), ->has_items(), wp_die(), ob_start(), ob_get_clean(), comments(), ->send() |
empty($post_id) && !empty($value) && current_user_can() && !->has_items() | 63–66 | check_ajax_referer(), absint(), wp_die(), _get_list_table(), current_user_can(), ->prepare_items(), ->has_items(), wp_die(), ob_start(), ob_get_clean(), comments(), ->send() |
empty($post_id) && !empty($value) && !current_user_can() && ->has_items() | 63–66 | check_ajax_referer(), absint(), wp_die(), _get_list_table(), current_user_can(), wp_die(), ->prepare_items(), ->has_items(), ob_start(), ob_get_clean(), comments(), ->send() |
empty($post_id) && !empty($value) && !current_user_can() && !->has_items() | 66–69 | check_ajax_referer(), absint(), wp_die(), _get_list_table(), current_user_can(), wp_die(), ->prepare_items(), ->has_items(), wp_die(), ob_start(), ob_get_clean(), comments(), ->send() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 86 instructions, 45–69 executed per call, 11 branches. The work does not change between versions.
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 · 7
- check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
- absint()Converts a value to non-negative integer.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- _get_list_table()Fetches an instance of a WP_List_Table class.
- current_user_can()Returns whether the current user has the specified capability.
- get_comment()Retrieves comment data given a comment ID or comment object.
- WP_Ajax_Response::__construct()Constructor - Passes args to WP_Ajax_Response::add().
Source code
function wp_ajax_get_comments( $action ) { global $post_id; if ( empty( $action ) ) { $action = 'get-comments'; } check_ajax_referer( $action ); if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) { $id = absint( $_REQUEST['p'] ); if ( ! empty( $id ) ) { $post_id = $id; } } if ( empty( $post_id ) ) { wp_die( -1 ); } $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( -1 ); } $wp_list_table->prepare_items(); if ( ! $wp_list_table->has_items() ) { wp_die( 1 ); } $x = new WP_Ajax_Response(); ob_start(); foreach ( $wp_list_table->items as $comment ) { if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) { continue; } get_comment( $comment ); $wp_list_table->single_row( $comment ); } $comment_list_item = ob_get_clean(); $x->add( array( 'what' => 'comments', 'data' => $comment_list_item, ) ); $x->send();}Changelog
Introduced in 3.1.0. 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/ajax-actions.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.