wp_ajax_get_comments

Ajax handler for getting comments.

Description

wp_ajax_get_comments( (string) $action ); 

Parameters (1)

0. $action (string)
Action to perform.

Usage

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

Defined (1)

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

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_get_comments( $action ) { 
  2. global $post_id; 
  3. if ( empty( $action ) ) { 
  4. $action = 'get-comments'; 
  5. check_ajax_referer( $action ); 
  6.  
  7. if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) { 
  8. $id = absint( $_REQUEST['p'] ); 
  9. if ( ! empty( $id ) ) { 
  10. $post_id = $id; 
  11.  
  12. if ( empty( $post_id ) ) { 
  13. wp_die( -1 ); 
  14.  
  15. $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); 
  16.  
  17. if ( ! current_user_can( 'edit_post', $post_id ) ) { 
  18. wp_die( -1 ); 
  19.  
  20. $wp_list_table->prepare_items(); 
  21.  
  22. if ( ! $wp_list_table->has_items() ) { 
  23. wp_die( 1 ); 
  24.  
  25. $x = new WP_Ajax_Response(); 
  26. ob_start(); 
  27. foreach ( $wp_list_table->items as $comment ) { 
  28. if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) 
  29. continue; 
  30. get_comment( $comment ); 
  31. $wp_list_table->single_row( $comment ); 
  32. $comment_list_item = ob_get_clean(); 
  33.  
  34. $x->add( array( 
  35. 'what' => 'comments',  
  36. 'data' => $comment_list_item 
  37. ) ); 
  38. $x->send();