wp_dashboard_recent_comments

Show Comments section.

Description

wp_dashboard_recent_comments( (int) $total_items = 5 ); 

Parameters (1)

0. $total_items — Optional. (int) => 5
Number of comments to query. Default 5.

Usage

  1. if ( !function_exists( 'wp_dashboard_recent_comments' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/dashboard.php'; 
  3.  
  4. // Optional. Number of comments to query. Default 5. 
  5. $total_items = 5; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_dashboard_recent_comments($total_items); 
  9.  

Defined (1)

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

/wp-admin/includes/dashboard.php  
  1. function wp_dashboard_recent_comments( $total_items = 5 ) { 
  2. // Select all comment types and filter out spam later for better query performance. 
  3. $comments = array(); 
  4.  
  5. $comments_query = array( 
  6. 'number' => $total_items * 5,  
  7. 'offset' => 0 
  8. ); 
  9. if ( ! current_user_can( 'edit_posts' ) ) 
  10. $comments_query['status'] = 'approve'; 
  11.  
  12. while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) { 
  13. if ( ! is_array( $possible ) ) { 
  14. break; 
  15. foreach ( $possible as $comment ) { 
  16. if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) 
  17. continue; 
  18. $comments[] = $comment; 
  19. if ( count( $comments ) == $total_items ) 
  20. break 2; 
  21. $comments_query['offset'] += $comments_query['number']; 
  22. $comments_query['number'] = $total_items * 10; 
  23.  
  24. if ( $comments ) { 
  25. echo '<div id="latest-comments" class="activity-block">'; 
  26. echo '<h3>' . __( 'Recent Comments' ) . '</h3>'; 
  27.  
  28. echo '<ul id="the-comment-list" data-wp-lists="list:comment">'; 
  29. foreach ( $comments as $comment ) 
  30. echo '</ul>'; 
  31.  
  32. if ( current_user_can( 'edit_posts' ) ) { 
  33. echo '<h3 class="screen-reader-text">' . __( 'View more comments' ) . '</h3>'; 
  34.  
  35. wp_comment_reply( -1, false, 'dashboard', false ); 
  36.  
  37. echo '</div>'; 
  38. } else { 
  39. return false; 
  40. return true;