_wp_ajax_delete_comment_response( int $comment_id, int $delta = -1 )
- Since
- 2.7.0
- Source
wp-admin/includes/ajax-actions.php:460
Description
Contrary to normal success Ajax response ("1"), die with time() on success.
Compatibility
- WordPress
- since 2.7.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
$comment_idint- Comment ID.
$deltaintoptional- Change in the number of total comments. Default -1.Default:
-1
Performance profile
How much work a call to _wp_ajax_delete_comment_response() 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
- Constant
- Instructions
- 175–216
- Plugin surface
- None
- Called by
- 2
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 244.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below _wp_ajax_delete_comment_response() - optionoption read or write
get_option()one call below _wp_ajax_delete_comment_response() - cacheobject cache
wp_cache_get()one call below _wp_ajax_delete_comment_response()
Further down the call graph this can also reach query, 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 · 18 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _wp_ajax_delete_comment_response() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($value) | 175–179 | time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && !isset($parsed) && !empty($type) | 179–183 | time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), parse_url(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) | 179–183 | time(), get_comment(), get_comment_link(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && !isset($parsed) && !empty($type) | 183–187 | time(), get_comment(), get_comment_link(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), parse_url(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && !isset($parsed) && empty($type) | 185–190 | time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), parse_url(), wp_count_comments(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && !isset($parsed) && !empty($type) | 185–189 | time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), parse_url(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && !isset($parsed) && empty($type) | 189–194 | time(), get_comment(), get_comment_link(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), parse_url(), wp_count_comments(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && !isset($parsed) && !empty($type) | 189–193 | time(), get_comment(), get_comment_link(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), parse_url(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && isset($parsed) && !empty($type) | 190–199 | time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), parse_url(), parse_str(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && !isset($parsed) && empty($type) | 191–196 | time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), parse_url(), wp_count_comments(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && isset($parsed) && !empty($type) | 194–203 | time(), get_comment(), get_comment_link(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), parse_url(), parse_str(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && !isset($parsed) && empty($type) | 195–200 | time(), get_comment(), get_comment_link(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), parse_url(), wp_count_comments(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
6 further outcomes, up to 216 instructions
!isset($value) && isset($parsed) && empty($type) | 196–206 | time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), parse_url(), parse_str(), wp_count_comments(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && isset($parsed) && !empty($type) | 196–205 | time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), parse_url(), parse_str(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && isset($parsed) && empty($type) | 200–210 | time(), get_comment(), get_comment_link(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), parse_url(), parse_str(), wp_count_comments(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && isset($parsed) && !empty($type) | 200–209 | time(), get_comment(), get_comment_link(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), parse_url(), parse_str(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && isset($parsed) && empty($type) | 202–212 | time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), parse_url(), parse_str(), wp_count_comments(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
!isset($value) && isset($parsed) && empty($type) | 206–216 | time(), get_comment(), get_comment_link(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), _n(), number_format_i18n(), sprintf(), status(), ->send(), mt_rand(), parse_url(), parse_str(), wp_count_comments(), time(), get_comment(), wp_count_comments(), _n(), number_format_i18n(), sprintf(), ceil(), ceil(), number_format_i18n(), _n(), number_format_i18n(), sprintf(), status(), ->send() |
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 | 243 | 175–216 | 22 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 244 | 175–216 | 22 | |
| 8.4 | 244 | 175–216 | 22 | |
| 8.3 | 244 | 175–216 | 22 | |
| 8.2 | 244 | 175–216 | 22 | |
| 8.1 | 244 | 175–216 | 22 | 6 fewer instructions than PHP 7.4 |
| 7.4 | 250 | 175–219 | 22 |
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
- sanitize_url()Sanitizes a URL for database or redirect usage.
- get_comment()Retrieves comment data given a comment ID or comment object.
- get_comment_link()Retrieves the link to a given comment.
- wp_count_comments()Retrieves the total comment counts for the whole site or a single post.
- _n()Translates and retrieves the singular or plural form based on the supplied number.
- number_format_i18n()Converts float number to format based on the locale.
- WP_Ajax_Response::__construct()Constructor - Passes args to WP_Ajax_Response::add().
Used by · 2
- wp_ajax_delete_comment()Handles deleting a comment via AJAX.
- wp_ajax_dim_comment()Handles dimming a comment via AJAX.
Source code
function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { $total = isset( $_POST['_total'] ) ? (int) $_POST['_total'] : 0; $per_page = isset( $_POST['_per_page'] ) ? (int) $_POST['_per_page'] : 0; $page = isset( $_POST['_page'] ) ? (int) $_POST['_page'] : 0; $url = isset( $_POST['_url'] ) ? sanitize_url( $_POST['_url'] ) : ''; // JS didn't send us everything we need to know. Just die with success message. if ( ! $total || ! $per_page || ! $page || ! $url ) { $time = time(); $comment = get_comment( $comment_id ); $comment_status = ''; $comment_link = ''; if ( $comment ) { $comment_status = $comment->comment_approved; } if ( 1 === (int) $comment_status ) { $comment_link = get_comment_link( $comment ); } $counts = wp_count_comments(); $response = new WP_Ajax_Response( array( 'what' => 'comment', // Here for completeness - not used. 'id' => $comment_id, 'supplemental' => array( 'status' => $comment_status, 'postId' => $comment ? $comment->comment_post_ID : '', 'time' => $time, 'in_moderation' => $counts->moderated, 'i18n_comments_text' => sprintf( /* translators: %s: Number of comments. */ _n( '%s Comment', '%s Comments', $counts->approved ), number_format_i18n( $counts->approved ) ), 'i18n_moderation_text' => sprintf( /* translators: %s: Number of comments. */ _n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ), number_format_i18n( $counts->moderated ) ), 'comment_link' => $comment_link, ), ) ); $response->send(); } $total += $delta; if ( $total < 0 ) { $total = 0; } // Only do the expensive stuff on a page-break, and about 1 other time per page. if ( 0 === $total % $per_page || 1 === mt_rand( 1, $per_page ) ) { $post_id = 0; // What type of comment count are we looking for? $status = 'all'; $parsed = parse_url( $url ); if ( isset( $parsed['query'] ) ) { parse_str( $parsed['query'], $query_vars ); if ( ! empty( $query_vars['comment_status'] ) ) { $status = $query_vars['comment_status']; } if ( ! empty( $query_vars['p'] ) ) { $post_id = (int) $query_vars['p']; } if ( ! empty( $query_vars['comment_type'] ) ) { $type = $query_vars['comment_type']; } } if ( empty( $type ) ) { // Only use the comment count if not filtering by a comment_type.Changelog
Introduced in 2.7.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 7.0.4 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.