wppaste
WordPress

_wp_ajax_delete_comment_response( int $comment_id, int $delta = -1 )

Since
2.7.0
Source
wp-admin/includes/ajax-actions.php:460
Sends back current comment total and new page links if they need to be updated.

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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
175–216

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 244.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()one call below _wp_ajax_delete_comment_response()
  • optionoption read or writeget_option()one call below _wp_ajax_delete_comment_response()
  • cacheobject cachewp_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.

WhenInstructionsCalls it makes
!isset($value)175–179time(), 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–183time(), 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–183time(), 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–187time(), 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–190time(), 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–189time(), 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–194time(), 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–193time(), 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–199time(), 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–196time(), 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–203time(), 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–200time(), 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–206time(), 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–205time(), 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–210time(), 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–209time(), 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–212time(), 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–216time(), 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

PHPCompiledExecutedBranchesNotes
8.6-dev243175–216221 fewer instruction than PHP 8.5
8.5244175–21622
8.4244175–21622
8.3244175–21622
8.2244175–21622
8.1244175–216226 fewer instructions than PHP 7.4
7.4250175–21922

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

Used by · 2

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.