wp_ajax_delete_comment

Ajax handler for deleting a comment.

Description

wp_ajax_delete_comment(); 

Usage

  1. if ( !function_exists( 'wp_ajax_delete_comment' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_ajax_delete_comment(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_delete_comment() { 
  2. $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 
  3.  
  4. if ( !$comment = get_comment( $id ) ) 
  5. wp_die( time() ); 
  6. if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) 
  7. wp_die( -1 ); 
  8.  
  9. check_ajax_referer( "delete-comment_$id" ); 
  10. $status = wp_get_comment_status( $comment ); 
  11.  
  12. $delta = -1; 
  13. if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { 
  14. if ( 'trash' == $status ) 
  15. wp_die( time() ); 
  16. $r = wp_trash_comment( $comment ); 
  17. } elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) { 
  18. if ( 'trash' != $status ) 
  19. wp_die( time() ); 
  20. $r = wp_untrash_comment( $comment ); 
  21. if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash 
  22. $delta = 1; 
  23. } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { 
  24. if ( 'spam' == $status ) 
  25. wp_die( time() ); 
  26. $r = wp_spam_comment( $comment ); 
  27. } elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) { 
  28. if ( 'spam' != $status ) 
  29. wp_die( time() ); 
  30. $r = wp_unspam_comment( $comment ); 
  31. if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam 
  32. $delta = 1; 
  33. } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { 
  34. $r = wp_delete_comment( $comment ); 
  35. } else { 
  36. wp_die( -1 ); 
  37.  
  38. if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts 
  39. _wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); 
  40. wp_die( 0 );