wp_ajax_dim_comment

Ajax handler to dim a comment.

Description

wp_ajax_dim_comment(); 

Usage

  1. if ( !function_exists( 'wp_ajax_dim_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_dim_comment(); 
  7.  

Defined (1)

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

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_dim_comment() { 
  2. $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 
  3.  
  4. if ( !$comment = get_comment( $id ) ) { 
  5. $x = new WP_Ajax_Response( array( 
  6. 'what' => 'comment',  
  7. 'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id)) 
  8. ) ); 
  9. $x->send(); 
  10.  
  11. if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) ) 
  12. wp_die( -1 ); 
  13.  
  14. $current = wp_get_comment_status( $comment ); 
  15. if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) 
  16. wp_die( time() ); 
  17.  
  18. check_ajax_referer( "approve-comment_$id" ); 
  19. if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { 
  20. $result = wp_set_comment_status( $comment, 'approve', true ); 
  21. } else { 
  22. $result = wp_set_comment_status( $comment, 'hold', true ); 
  23.  
  24. if ( is_wp_error($result) ) { 
  25. $x = new WP_Ajax_Response( array( 
  26. 'what' => 'comment',  
  27. 'id' => $result 
  28. ) ); 
  29. $x->send(); 
  30.  
  31. // Decide if we need to send back '1' or a more complicated response including page links and comment counts 
  32. _wp_ajax_delete_comment_response( $comment->comment_ID ); 
  33. wp_die( 0 );