wp_ajax_delete_comment() WordPress Function
The wp_ajax_delete_comment() function allows a user to delete a comment via the WordPress admin dashboard. This function is triggered when the user clicks on the "Trash" link next to a comment.
wp_ajax_delete_comment() #
Ajax handler for deleting a comment.
Source
File: wp-admin/includes/ajax-actions.php
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | 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 ); } |
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |