_wp_dashboard_recent_comments_row

Outputs a row for the Recent Comments widget.

Description

_wp_dashboard_recent_comments_row( (WP_Comment) &$comment, (bool) $show_date = true ); 

Parameters (2)

0. $comment (WP_Comment) => &$comment
The current comment.
1. $show_date — Optional. (bool) => true
Whether to display the date.

Usage

  1. if ( !function_exists( '_wp_dashboard_recent_comments_row' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/dashboard.php'; 
  3.  
  4. // The current comment. 
  5. $comment = &$comment; 
  6.  
  7. // Optional. Whether to display the date. 
  8. $show_date = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _wp_dashboard_recent_comments_row($comment, $show_date); 
  12.  

Defined (1)

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

/wp-admin/includes/dashboard.php  
  1. function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { 
  2. $GLOBALS['comment'] = clone $comment; 
  3.  
  4. if ( $comment->comment_post_ID > 0 ) { 
  5.  
  6. $comment_post_title = _draft_or_post_title( $comment->comment_post_ID ); 
  7. $comment_post_url = get_the_permalink( $comment->comment_post_ID ); 
  8. $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>"; 
  9. } else { 
  10. $comment_post_link = ''; 
  11.  
  12. $actions_string = ''; 
  13. if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) { 
  14. // Pre-order it: Approve | Reply | Edit | Spam | Trash. 
  15. $actions = array( 
  16. 'approve' => '', 'unapprove' => '',  
  17. 'reply' => '',  
  18. 'edit' => '',  
  19. 'spam' => '',  
  20. 'trash' => '', 'delete' => '',  
  21. 'view' => '',  
  22. ); 
  23.  
  24. $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); 
  25. $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) ); 
  26.  
  27. $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" ); 
  28. $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" ); 
  29. $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" ); 
  30. $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" ); 
  31. $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" ); 
  32.  
  33. $actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; 
  34. $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; 
  35. $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>". __( 'Edit' ) . '</a>'; 
  36. $actions['reply'] = '<a onclick="window.commentReply && commentReply.open(\'' . $comment->comment_ID . '\', \''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" aria-label="' . esc_attr__( 'Reply to this comment' ) . '" href="#">' . __( 'Reply' ) . '</a>'; 
  37. $actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' aria-label='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /** translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>'; 
  38.  
  39. if ( ! EMPTY_TRASH_DAYS ) { 
  40. $actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' aria-label='" . esc_attr__( 'Delete this comment permanently' ) . "'>" . __( 'Delete Permanently' ) . '</a>'; 
  41. } else { 
  42. $actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' aria-label='" . esc_attr__( 'Move this comment to the Trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>'; 
  43.  
  44. $actions['view'] = '<a class="comment-link" href="' . esc_url( get_comment_link( $comment ) ) . '" aria-label="' . esc_attr__( 'View this comment' ) . '">' . __( 'View' ) . '</a>'; 
  45.  
  46. /** 
  47. * Filters the action links displayed for each comment in the 'Recent Comments' 
  48. * dashboard widget. 
  49. * @since 2.6.0 
  50. * @param array $actions An array of comment actions. Default actions include: 
  51. * 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',  
  52. * 'Delete', and 'Trash'. 
  53. * @param WP_Comment $comment The comment object. 
  54. */ 
  55. $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment ); 
  56.  
  57. $i = 0; 
  58. foreach ( $actions as $action => $link ) { 
  59. ++$i; 
  60. ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | '; 
  61.  
  62. // Reply and quickedit need a hide-if-no-js span 
  63. if ( 'reply' == $action || 'quickedit' == $action ) { 
  64. $action .= ' hide-if-no-js'; 
  65.  
  66. if ( 'view' === $action && '1' !== $comment->comment_approved ) { 
  67. $action .= ' hidden'; 
  68. $actions_string .= "<span class='$action'>$sep$link</span>"; 
  69. ?> 
  70.  
  71. <li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>> 
  72.  
  73. <?php echo get_avatar( $comment, 50, 'mystery' ); ?> 
  74.  
  75. <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?> 
  76.  
  77. <div class="dashboard-comment-wrap has-row-actions"> 
  78. <p class="comment-meta"> 
  79. <?php 
  80. // Comments might not have a post they relate to, e.g. programmatically created ones. 
  81. if ( $comment_post_link ) { 
  82. printf( 
  83. /** translators: 1: comment author, 2: post link, 3: notification if the comment is pending */ 
  84. __( 'From %1$s on %2$s %3$s' ),  
  85. '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',  
  86. $comment_post_link,  
  87. '<span class="approve">' . __( '[Pending]' ) . '</span>' 
  88. ); 
  89. } else { 
  90. printf( 
  91. /** translators: 1: comment author, 2: notification if the comment is pending */ 
  92. __( 'From %1$s %2$s' ),  
  93. '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',  
  94. '<span class="approve">' . __( '[Pending]' ) . '</span>' 
  95. ); 
  96. ?> 
  97. </p> 
  98.  
  99. <?php 
  100. else : 
  101. switch ( $comment->comment_type ) { 
  102. case 'pingback' : 
  103. $type = __( 'Pingback' ); 
  104. break; 
  105. case 'trackback' : 
  106. $type = __( 'Trackback' ); 
  107. break; 
  108. default : 
  109. $type = ucwords( $comment->comment_type ); 
  110. $type = esc_html( $type ); 
  111. ?> 
  112. <div class="dashboard-comment-wrap has-row-actions"> 
  113. <p class="comment-meta"> 
  114. <?php 
  115. // Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones. 
  116. if ( $comment_post_link ) { 
  117. printf( 
  118. /** translators: 1: type of comment, 2: post link, 3: notification if the comment is pending */ 
  119. _x( '%1$s on %2$s %3$s', 'dashboard' ),  
  120. "<strong>$type</strong>",  
  121. $comment_post_link,  
  122. '<span class="approve">' . __( '[Pending]' ) . '</span>' 
  123. ); 
  124. } else { 
  125. printf( 
  126. /** translators: 1: type of comment, 2: notification if the comment is pending */ 
  127. _x( '%1$s %2$s', 'dashboard' ),  
  128. "<strong>$type</strong>",  
  129. '<span class="approve">' . __( '[Pending]' ) . '</span>' 
  130. ); 
  131. ?> 
  132. </p> 
  133. <p class="comment-author"><?php comment_author_link( $comment ); ?></p> 
  134.  
  135. <?php endif; // comment_type ?> 
  136. <blockquote><p><?php comment_excerpt( $comment ); ?></p></blockquote> 
  137. <?php if ( $actions_string ) : ?> 
  138. <p class="row-actions"><?php echo $actions_string; ?></p> 
  139. <?php endif; ?> 
  140. </div> 
  141. </li> 
  142. <?php 
  143. $GLOBALS['comment'] = null;