wp_ajax_delete_comment()
- Since
- 3.1.0
- Source
wp-admin/includes/ajax-actions.php:722
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
- Scaling
- Constant
- Instructions
- 45–96
- 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 156.
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
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
current_user_can() && isset($value) && $status !== "trash" | 45–48 | get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), wp_die() |
!current_user_can() && isset($value) && $status !== "trash" | 48–51 | get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_trash_comment(), wp_die() |
current_user_can() | 49–72 | get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_die(), wp_die() |
current_user_can() && isset($value) && $status === "trash" | 50–53 | get_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–53 | get_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–62 | get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_spam_comment(), wp_die() |
current_user_can() && isset($value) && $status !== "trash" | 51–54 | get_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–63 | get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), wp_die() |
!current_user_can() | 52–75 | get_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–56 | get_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–56 | get_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–65 | get_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–57 | get_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–77 | get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_die(), wp_die() |
current_user_can() && isset($value) | 55–74 | get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), wp_die() |
current_user_can() | 55–78 | get_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–66 | get_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–58 | get_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–67 | get_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–67 | get_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–59 | get_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–59 | get_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–68 | get_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–68 | get_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–68 | get_comment(), time(), wp_die(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_untrash_comment(), wp_die() |
!current_user_can() | 57–80 | get_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–77 | get_comment(), current_user_can(), check_ajax_referer(), wp_get_comment_status(), wp_unspam_comment(), wp_die() |
current_user_can() && isset($value) && $status === "trash" | 58–69 | get_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–77 | get_comment(), current_user_can(), wp_die(), check_ajax_referer(), wp_get_comment_status(), wp_delete_comment(), wp_die() |
!current_user_can() | 58–81 | get_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–61 | get_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–70 | get_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–70 | get_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–62 | get_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–62 | get_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–71 | get_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–79 | get_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–71 | get_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–83 | get_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–71 | get_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–80 | get_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–80 | get_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–72 | get_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–72 | get_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–64 | get_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–73 | get_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–73 | get_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–73 | get_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–82 | get_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–82 | get_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–74 | get_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–74 | get_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–82 | get_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–86 | get_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–83 | get_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–83 | get_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–75 | get_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–67 | get_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–76 | get_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–76 | get_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–76 | get_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–85 | get_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–85 | get_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–85 | get_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–77 | get_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–77 | get_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–86 | get_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–78 | get_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–87 | get_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–79 | get_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–88 | get_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–88 | get_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–88 | get_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–81 | get_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–90 | get_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–82 | get_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–91 | get_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–91 | get_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–93 | get_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–96 | get_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 156 | 45–96 | 22 | |
| 8.5 | 156 | 45–96 | 22 | |
| 8.4 | 156 | 45–96 | 22 | |
| 8.3 | 156 | 45–96 | 22 | |
| 8.2 | 156 | 45–96 | 22 | |
| 8.1 | 156 | 45–96 | 22 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 157 | 45–97 | 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 · 11
- get_comment()Retrieves comment data given a comment ID or comment object.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- current_user_can()Returns whether the current user has the specified capability.
- check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
- wp_get_comment_status()Retrieves the status of a comment by comment ID.
- wp_trash_comment()Moves a comment to the Trash
- wp_untrash_comment()Removes a comment from the Trash
- wp_spam_comment()Marks a comment as Spam.
- wp_unspam_comment()Removes a comment from the Spam.
- wp_delete_comment()Trashes or deletes a comment.
- _wp_ajax_delete_comment_response()Sends back current comment total and new page links if they need to be updated.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.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.