wp_ajax_edit_comment()
- Since
- 3.1.0
- Source
wp-admin/includes/ajax-actions.php:1463
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.
Performance profile
How much work a call to wp_ajax_edit_comment() 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
- Trivial
- Scaling
- Constant
- Instructions
- 71–106
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
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 109.
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_edit_comment()
Further down the call graph this can also reach query, cache, 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 · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_ajax_edit_comment() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
current_user_can() && !is_wp_error() && !empty($comment) | 71–89 | check_ajax_referer(), current_user_can(), edit_comment(), is_wp_error(), _get_list_table(), get_comment(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
current_user_can() && !is_wp_error() && empty($comment) | 74–92 | check_ajax_referer(), current_user_can(), edit_comment(), is_wp_error(), _get_list_table(), get_comment(), wp_die(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
!current_user_can() && !is_wp_error() && !empty($comment) | 74–92 | check_ajax_referer(), current_user_can(), wp_die(), edit_comment(), is_wp_error(), _get_list_table(), get_comment(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
current_user_can() && is_wp_error() && !empty($comment) | 76–94 | check_ajax_referer(), current_user_can(), edit_comment(), is_wp_error(), ->get_error_message(), wp_die(), _get_list_table(), get_comment(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
current_user_can() && !is_wp_error() && !empty($comment) | 77–95 | check_ajax_referer(), current_user_can(), __(), wp_die(), edit_comment(), is_wp_error(), _get_list_table(), get_comment(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
!current_user_can() && !is_wp_error() && empty($comment) | 77–95 | check_ajax_referer(), current_user_can(), wp_die(), edit_comment(), is_wp_error(), _get_list_table(), get_comment(), wp_die(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
current_user_can() && is_wp_error() && empty($comment) | 79–97 | check_ajax_referer(), current_user_can(), edit_comment(), is_wp_error(), ->get_error_message(), wp_die(), _get_list_table(), get_comment(), wp_die(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
!current_user_can() && is_wp_error() && !empty($comment) | 79–97 | check_ajax_referer(), current_user_can(), wp_die(), edit_comment(), is_wp_error(), ->get_error_message(), wp_die(), _get_list_table(), get_comment(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
current_user_can() && !is_wp_error() && empty($comment) | 80–98 | check_ajax_referer(), current_user_can(), __(), wp_die(), edit_comment(), is_wp_error(), _get_list_table(), get_comment(), wp_die(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
!current_user_can() && !is_wp_error() && !empty($comment) | 80–98 | check_ajax_referer(), current_user_can(), wp_die(), __(), wp_die(), edit_comment(), is_wp_error(), _get_list_table(), get_comment(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
current_user_can() && is_wp_error() && !empty($comment) | 82–100 | check_ajax_referer(), current_user_can(), __(), wp_die(), edit_comment(), is_wp_error(), ->get_error_message(), wp_die(), _get_list_table(), get_comment(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
!current_user_can() && is_wp_error() && empty($comment) | 82–100 | check_ajax_referer(), current_user_can(), wp_die(), edit_comment(), is_wp_error(), ->get_error_message(), wp_die(), _get_list_table(), get_comment(), wp_die(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
4 further outcomes, up to 106 instructions
!current_user_can() && !is_wp_error() && empty($comment) | 83–101 | check_ajax_referer(), current_user_can(), wp_die(), __(), wp_die(), edit_comment(), is_wp_error(), _get_list_table(), get_comment(), wp_die(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
current_user_can() && is_wp_error() && empty($comment) | 85–103 | check_ajax_referer(), current_user_can(), __(), wp_die(), edit_comment(), is_wp_error(), ->get_error_message(), wp_die(), _get_list_table(), get_comment(), wp_die(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
!current_user_can() && is_wp_error() && !empty($comment) | 85–103 | check_ajax_referer(), current_user_can(), wp_die(), __(), wp_die(), edit_comment(), is_wp_error(), ->get_error_message(), wp_die(), _get_list_table(), get_comment(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
!current_user_can() && is_wp_error() && empty($comment) | 88–106 | check_ajax_referer(), current_user_can(), wp_die(), __(), wp_die(), edit_comment(), is_wp_error(), ->get_error_message(), wp_die(), _get_list_table(), get_comment(), wp_die(), ob_start(), ->single_row(), ob_get_clean(), edit_comment(), ->send() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 109 | 71–106 | 10 | |
| 8.5 | 109 | 71–106 | 10 | |
| 8.4 | 109 | 71–106 | 10 | |
| 8.3 | 109 | 71–106 | 10 | |
| 8.2 | 109 | 71–106 | 10 | |
| 8.1 | 109 | 71–106 | 10 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 110 | 71–107 | 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.
Uses · 9
- check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
- current_user_can()Returns whether the current user has the specified capability.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- __()Retrieves the translation of $text.
- edit_comment()Updates a comment with values provided in $_POST.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- _get_list_table()Fetches an instance of a WP_List_Table class.
- 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_edit_comment() { check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ); $comment_id = (int) $_POST['comment_ID']; if ( ! current_user_can( 'edit_comment', $comment_id ) ) { wp_die( -1 ); } if ( '' === $_POST['content'] ) { wp_die( __( 'Please type your comment text.' ) ); } if ( isset( $_POST['status'] ) ) { $_POST['comment_status'] = $_POST['status']; } $updated = edit_comment(); if ( is_wp_error( $updated ) ) { wp_die( $updated->get_error_message() ); } $position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; /* * Checkbox is used to differentiate between the Edit Comments screen (1) * and the Comments section on the Edit Post screen (0). */ $checkbox = ( isset( $_POST['checkbox'] ) && '1' === $_POST['checkbox'] ) ? 1 : 0; $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); $comment = get_comment( $comment_id ); if ( empty( $comment->comment_ID ) ) { wp_die( -1 ); } ob_start(); $wp_list_table->single_row( $comment ); $comment_list_item = ob_get_clean(); $x = new WP_Ajax_Response(); $x->add( array( 'what' => 'edit_comment', 'id' => $comment->comment_ID, 'data' => $comment_list_item, 'position' => $position, ) ); $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.8.8 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.