wppaste
WordPress

wp_ajax_delete_comment()

Since
3.1.0
Source
wp-admin/includes/ajax-actions.php:719
Handles deleting a comment via AJAX.

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_delete_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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
45–96

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()one call below wp_ajax_delete_comment()

Further down the call graph this can also reach cache, option, 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 · 80 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_ajax_delete_comment() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
current_user_can() && isset($value) && $status !== "trash"45–48get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), wp_die()
!current_user_can() && isset($value) && $status !== "trash"48–51get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), wp_die()
current_user_can()49–72get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_die(), wp_die()
current_user_can() && isset($value) && $status === "trash"50–53get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_trash_comment(), wp_die()
current_user_can() && isset($value) && $status !== "trash"50–53get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), wp_die()
current_user_can() && isset($value) && $status !== "spam"51–62get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_spam_comment(), wp_die()
current_user_can() && isset($value) && $status !== "trash"51–54get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status === "trash"52–63get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), wp_die()
!current_user_can()52–75get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_die(), wp_die()
!current_user_can() && isset($value) && $status === "trash"53–56get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_trash_comment(), wp_die()
!current_user_can() && isset($value) && $status !== "trash"53–56get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), wp_die()
!current_user_can() && isset($value) && $status !== "spam"54–65get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_spam_comment(), wp_die()
68 further outcomes, up to 96 instructions
!current_user_can() && isset($value) && $status !== "trash"54–57get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can()54–77get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_die(), wp_die()
current_user_can() && isset($value)55–74get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), wp_die()
current_user_can()55–78get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_die(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "trash"55–66get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), wp_die()
current_user_can() && isset($value) && $status === "trash"55–58get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_trash_comment(), wp_die()
current_user_can() && isset($value) && $status === "spam"56–67get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_spam_comment(), wp_die()
current_user_can() && isset($value) && $status !== "spam"56–67get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_spam_comment(), wp_die()
current_user_can() && isset($value) && $status === "trash"56–59get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_trash_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status !== "trash"56–59get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status !== "spam"57–68get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_spam_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status !== "trash"57–68get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_untrash_comment(), wp_die()
current_user_can() && isset($value) && $status === "trash"57–68get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), wp_die()
!current_user_can()57–80get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_die(), wp_die()
current_user_can() && isset($value) && $status === "spam"58–77get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_unspam_comment(), wp_die()
current_user_can() && isset($value) && $status === "trash"58–69get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value)58–77get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), wp_die()
!current_user_can()58–81get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_die(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "trash"58–61get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_trash_comment(), wp_die()
!current_user_can() && isset($value) && $status === "spam"59–70get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_spam_comment(), wp_die()
!current_user_can() && isset($value) && $status !== "spam"59–70get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_spam_comment(), wp_die()
!current_user_can() && isset($value) && $status === "trash"59–62get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_trash_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status !== "trash"59–62get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status !== "spam"60–71get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_spam_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value)60–79get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), wp_die()
!current_user_can() && isset($value) && $status !== "trash"60–71get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_untrash_comment(), wp_die()
current_user_can()60–83get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_die(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "trash"60–71get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), wp_die()
current_user_can() && isset($value)61–80get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "spam"61–80get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_unspam_comment(), wp_die()
!current_user_can() && isset($value) && $status === "trash"61–72get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status === "spam"61–72get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_spam_comment(), wp_die()
current_user_can() && isset($value) && $status === "trash"61–64get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_trash_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status === "spam"62–73get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_spam_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status !== "spam"62–73get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_spam_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status !== "trash"62–73get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_untrash_comment(), wp_die()
current_user_can() && isset($value) && $status !== "spam"63–82get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_unspam_comment(), wp_die()
current_user_can() && isset($value) && $status === "spam"63–82get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_unspam_comment(), wp_die()
current_user_can() && isset($value) && $status !== "trash"63–74get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_untrash_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status === "trash"63–74get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value)63–82get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), wp_die()
!current_user_can()63–86get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_die(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status === "spam"64–83get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_unspam_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value)64–83get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "spam"64–75get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_spam_comment(), wp_die()
!current_user_can() && isset($value) && $status === "trash"64–67get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_trash_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "spam"65–76get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_spam_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status !== "spam"65–76get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_spam_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status !== "trash"65–76get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_untrash_comment(), wp_die()
!current_user_can() && isset($value) && $status !== "spam"66–85get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_unspam_comment(), wp_die()
current_user_can() && isset($value)66–85get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "spam"66–85get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_unspam_comment(), wp_die()
!current_user_can() && isset($value) && $status !== "trash"66–77get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_untrash_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "trash"66–77get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "spam"67–86get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_unspam_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status === "spam"67–78get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_spam_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status !== "spam"68–87get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_unspam_comment(), wp_die()
current_user_can() && isset($value) && $status !== "trash"68–79get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_untrash_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status !== "spam"69–88get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_unspam_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status === "spam"69–88get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_unspam_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value)69–88get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "spam"70–81get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_spam_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status !== "spam"71–90get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_unspam_comment(), wp_die()
!current_user_can() && isset($value) && $status !== "trash"71–82get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_untrash_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status !== "spam"72–91get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_unspam_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status === "spam"72–91get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_unspam_comment(), _wp_ajax_delete_comment_response(), wp_die()
current_user_can() && isset($value) && $status !== "spam"74–93get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_unspam_comment(), _wp_ajax_delete_comment_response(), wp_die()
!current_user_can() && isset($value) && $status !== "spam"77–96get_comment(), time(), wp_die(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), time(), wp_die(), wp_unspam_comment(), _wp_ajax_delete_comment_response(), wp_die()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev15645–9622
8.515645–9622
8.415645–9622
8.315645–9622
8.215645–9622
8.115645–96221 fewer instruction than PHP 7.4
7.415745–9722

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 · 11

Source code

function wp_ajax_delete_comment() {	$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 	$comment = get_comment( $id ); 	if ( ! $comment ) {		wp_die( time() );	} 	if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {		wp_die( -1 );	} 	check_ajax_referer( "delete-comment_$id" );	$status = wp_get_comment_status( $comment );	$delta  = -1; 	if ( isset( $_POST['trash'] ) && '1' === $_POST['trash'] ) {		if ( 'trash' === $status ) {			wp_die( time() );		} 		$r = wp_trash_comment( $comment );	} elseif ( isset( $_POST['untrash'] ) && '1' === $_POST['untrash'] ) {		if ( 'trash' !== $status ) {			wp_die( time() );		} 		$r = wp_untrash_comment( $comment ); 		// Undo trash, not in Trash.		if ( ! isset( $_POST['comment_status'] ) || 'trash' !== $_POST['comment_status'] ) {			$delta = 1;		}	} elseif ( isset( $_POST['spam'] ) && '1' === $_POST['spam'] ) {		if ( 'spam' === $status ) {			wp_die( time() );		} 		$r = wp_spam_comment( $comment );	} elseif ( isset( $_POST['unspam'] ) && '1' === $_POST['unspam'] ) {		if ( 'spam' !== $status ) {			wp_die( time() );		} 		$r = wp_unspam_comment( $comment ); 		// Undo spam, not in spam.		if ( ! isset( $_POST['comment_status'] ) || 'spam' !== $_POST['comment_status'] ) {			$delta = 1;		}	} elseif ( isset( $_POST['delete'] ) && '1' === $_POST['delete'] ) {		$r = wp_delete_comment( $comment );	} else {		wp_die( -1 );	} 	if ( $r ) {		// Decide if we need to send back '1' or a more complicated response including page links and comment counts.		_wp_ajax_delete_comment_response( $comment->comment_ID, $delta );	} 	wp_die( 0 );}

Changelog

Introduced in 3.1.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 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.