wp_dashboard_right_now

Dashboard widget that displays some basic stats about the site.

Description

wp_dashboard_right_now(); 

Formerly Right Now.. A streamlined At a Glance as of 3.8.


Usage

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

Defined (1)

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

/wp-admin/includes/dashboard.php  
  1. function wp_dashboard_right_now() { 
  2. ?> 
  3. <div class="main"> 
  4. <ul> 
  5. <?php 
  6. // Posts and Pages 
  7. foreach ( array( 'post', 'page' ) as $post_type ) { 
  8. $num_posts = wp_count_posts( $post_type ); 
  9. if ( $num_posts && $num_posts->publish ) { 
  10. if ( 'post' == $post_type ) { 
  11. $text = _n( '%s Post', '%s Posts', $num_posts->publish ); 
  12. } else { 
  13. $text = _n( '%s Page', '%s Pages', $num_posts->publish ); 
  14. $text = sprintf( $text, number_format_i18n( $num_posts->publish ) ); 
  15. $post_type_object = get_post_type_object( $post_type ); 
  16. if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { 
  17. printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text ); 
  18. } else { 
  19. printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text ); 
  20.  
  21. // Comments 
  22. $num_comm = wp_count_comments(); 
  23. if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) { 
  24. $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) ); 
  25. ?> 
  26. <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li> 
  27. <?php 
  28. $moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated ); 
  29. /** translators: Number of comments in moderation */ 
  30. $text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), $moderated_comments_count_i18n ); 
  31. /** translators: Number of comments in moderation */ 
  32. $aria_label = sprintf( _nx( '%s comment in moderation', '%s comments in moderation', $num_comm->moderated, 'comments' ), $moderated_comments_count_i18n ); 
  33. ?> 
  34. <li class="comment-mod-count<?php 
  35. if ( ! $num_comm->moderated ) { 
  36. echo ' hidden'; 
  37. ?>"><a href="edit-comments.php?comment_status=moderated" aria-label="<?php esc_attr_e( $aria_label ); ?>"><?php echo $text; ?></a></li> 
  38. <?php 
  39.  
  40. /** 
  41. * Filters the array of extra elements to list in the 'At a Glance' 
  42. * dashboard widget. 
  43. * Prior to 3.8.0, the widget was named 'Right Now'. Each element 
  44. * is wrapped in list-item tags on output. 
  45. * @since 3.8.0 
  46. * @param array $items Array of extra 'At a Glance' widget items. 
  47. */ 
  48. $elements = apply_filters( 'dashboard_glance_items', array() ); 
  49.  
  50. if ( $elements ) { 
  51. echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n"; 
  52.  
  53. ?> 
  54. </ul> 
  55. <?php 
  56.  
  57. // Check if search engines are asked not to index this site. 
  58. if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '0' == get_option( 'blog_public' ) ) { 
  59.  
  60. /** 
  61. * Filters the link title attribute for the 'Search Engines Discouraged' 
  62. * message displayed in the 'At a Glance' dashboard widget. 
  63. * Prior to 3.8.0, the widget was named 'Right Now'. 
  64. * @since 3.0.0 
  65. * @since 4.5.0 The default for `$title` was updated to an empty string. 
  66. * @param string $title Default attribute text. 
  67. */ 
  68.  
  69. /** 
  70. * Filters the link label for the 'Search Engines Discouraged' message 
  71. * displayed in the 'At a Glance' dashboard widget. 
  72. * Prior to 3.8.0, the widget was named 'Right Now'. 
  73. * @since 3.0.0 
  74. * @param string $content Default text. 
  75. */ 
  76. $content = apply_filters( 'privacy_on_link_text' , __( 'Search Engines Discouraged' ) ); 
  77. $title_attr = '' === $title ? '' : " title='$title'"; 
  78.  
  79. echo "<p><a href='options-reading.php'$title_attr>$content</a></p>"; 
  80. ?> 
  81. </div> 
  82. <?php 
  83. /** 
  84. * activity_box_end has a core action, but only prints content when multisite. 
  85. * Using an output buffer is the only way to really check if anything's displayed here. 
  86. */ 
  87. ob_start(); 
  88.  
  89. /** 
  90. * Fires at the end of the 'At a Glance' dashboard widget. 
  91. * Prior to 3.8.0, the widget was named 'Right Now'. 
  92. * @since 2.5.0 
  93. */ 
  94.  
  95. /** 
  96. * Fires at the end of the 'At a Glance' dashboard widget. 
  97. * Prior to 3.8.0, the widget was named 'Right Now'. 
  98. * @since 2.0.0 
  99. */ 
  100.  
  101. $actions = ob_get_clean(); 
  102.  
  103. if ( !empty( $actions ) ) : ?> 
  104. <div class="sub"> 
  105. <?php echo $actions; ?> 
  106. </div> 
  107. <?php endif;