wppaste
WordPress

wp_dashboard_right_now()

Since
2.7.0
Source
wp-admin/includes/dashboard.php:300
Dashboard widget that displays some basic stats about the site.

Description

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

Compatibility

WordPress
since 2.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Performance profile

How much work a call to wp_dashboard_right_now() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
34–129

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 192.

Plugin surface
5 hooks

Third-party callbacks on 'dashboard_glance_items', 'privacy_on_link_title', 'privacy_on_link_text' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()called directly
  • cacheobject cachewp_cache_get()one call below wp_dashboard_right_now()
  • serializeserialisationmaybe_unserialize()one call below wp_dashboard_right_now()

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 10 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_dashboard_right_now() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
is_network_admin()34–46wp_count_comments(), apply_filters(), update_right_now_message(), is_network_admin(), ob_start(), do_action(), do_action(), ob_get_clean()
!is_network_admin() && is_user_admin()37–49wp_count_comments(), apply_filters(), update_right_now_message(), is_network_admin(), is_user_admin(), ob_start(), do_action(), do_action(), ob_get_clean()
!is_network_admin() && !is_user_admin() && !current_user_can()41–53wp_count_comments(), apply_filters(), update_right_now_message(), is_network_admin(), is_user_admin(), current_user_can(), ob_start(), do_action(), do_action(), ob_get_clean()
!is_network_admin() && !is_user_admin() && current_user_can() && get_option()45–57wp_count_comments(), apply_filters(), update_right_now_message(), is_network_admin(), is_user_admin(), current_user_can(), get_option(), ob_start(), do_action(), do_action(), ob_get_clean()
!is_network_admin() && !is_user_admin() && current_user_can() && !get_option()69–82wp_count_comments(), apply_filters(), update_right_now_message(), is_network_admin(), is_user_admin(), current_user_can(), get_option(), apply_filters(), __(), apply_filters(), ob_start(), do_action(), do_action(), ob_get_clean()
$num_comm && is_network_admin()82–93wp_count_comments(), _n(), number_format_i18n(), sprintf(), number_format_i18n(), _n(), sprintf(), apply_filters(), update_right_now_message(), is_network_admin(), ob_start(), do_action(), do_action(), ob_get_clean()
$num_comm && !is_network_admin() && is_user_admin()85–96wp_count_comments(), _n(), number_format_i18n(), sprintf(), number_format_i18n(), _n(), sprintf(), apply_filters(), update_right_now_message(), is_network_admin(), is_user_admin(), ob_start(), do_action(), do_action(), ob_get_clean()
$num_comm && !is_network_admin() && !is_user_admin() && !current_user_can()89–100wp_count_comments(), _n(), number_format_i18n(), sprintf(), number_format_i18n(), _n(), sprintf(), apply_filters(), update_right_now_message(), is_network_admin(), is_user_admin(), current_user_can(), ob_start(), do_action(), do_action(), ob_get_clean()
$num_comm && !is_network_admin() && !is_user_admin() && current_user_can() && get_option()93–104wp_count_comments(), _n(), number_format_i18n(), sprintf(), number_format_i18n(), _n(), sprintf(), apply_filters(), update_right_now_message(), is_network_admin(), is_user_admin(), current_user_can(), get_option(), ob_start(), do_action(), do_action(), ob_get_clean()
$num_comm && !is_network_admin() && !is_user_admin() && current_user_can() && !get_option()117–129wp_count_comments(), _n(), number_format_i18n(), sprintf(), number_format_i18n(), _n(), sprintf(), apply_filters(), update_right_now_message(), is_network_admin(), is_user_admin(), current_user_can(), get_option(), apply_filters(), __(), apply_filters(), ob_start(), do_action(), do_action(), ob_get_clean()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev19234–12918
8.519234–12918
8.419234–129183 fewer instructions than PHP 8.3
8.319534–13218
8.219534–13218
8.119534–132181 fewer instruction than PHP 7.4
7.419634–13318

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 5

5 hooks fire while wp_dashboard_right_now() runs, in this order:

  1. apply_filters( dashboard_glance_items )filterline 361 (+61 into the body)

    Filters the array of extra elements to list in the 'At a Glance' dashboard widget.

  2. apply_filters( privacy_on_link_title )filterline 388 (+88 into the body)

    Filters the link title attribute for the 'Search engines discouraged' message displayed in the 'At a Glance' dashboard widget.

  3. apply_filters( privacy_on_link_text )filterline 400 (+100 into the body)

    Filters the link label for the 'Search engines discouraged' message displayed in the 'At a Glance' dashboard widget.

  4. do_action( rightnow_end )actionline 422 (+122 into the body)

    Fires at the end of the 'At a Glance' dashboard widget.

  5. do_action( activity_box_end )actionline 431 (+131 into the body)

    Fires at the end of the 'At a Glance' dashboard widget.

Uses · 13

  • wp_count_posts()Counts number of posts of a post type and if user has permissions to view.
  • _n()Translates and retrieves the singular or plural form based on the supplied number.
  • number_format_i18n()Converts float number to format based on the locale.
  • get_post_type_object()Retrieves a post type object by name.
  • current_user_can()Returns whether the current user has the specified capability.
  • wp_count_comments()Retrieves the total comment counts for the whole site or a single post.
  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • update_right_now_message()Displays WordPress version and active theme in the 'At a Glance' dashboard widget.
  • is_network_admin()Determines whether the current request is for the network administrative interface.
  • is_user_admin()Determines whether the current request is for a user admin screen.
  • get_option()Retrieves an option value based on an option name.
  • __()Retrieves the translation of $text.
Show all 13
  • do_action()Calls the callback functions that have been added to an action hook.

Source code

function wp_dashboard_right_now() {	?>	<div class="main">	<ul>	<?php	// Posts and Pages.	foreach ( array( 'post', 'page' ) as $post_type ) {		$num_posts = wp_count_posts( $post_type ); 		if ( $num_posts && $num_posts->publish ) {			if ( 'post' === $post_type ) {				/* translators: %s: Number of posts. */				$text = _n( '%s Post', '%s Posts', $num_posts->publish );			} else {				/* translators: %s: Number of pages. */				$text = _n( '%s Page', '%s Pages', $num_posts->publish );			} 			$text             = sprintf( $text, number_format_i18n( $num_posts->publish ) );			$post_type_object = get_post_type_object( $post_type ); 			if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {				printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );			} else {				printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );			}		}	} 	// Comments.	$num_comm = wp_count_comments(); 	if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) {		/* translators: %s: Number of comments. */		$text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) );		?>		<li class="comment-count">			<a href="edit-comments.php"><?php echo $text; ?></a>		</li>		<?php		$moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated );		/* translators: %s: Number of comments. */		$text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n );		?>		<li class="comment-mod-count<?php echo ! $num_comm->moderated ? ' hidden' : ''; ?>">			<a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a>		</li>		<?php	} 	/**	 * Filters the array of extra elements to list in the 'At a Glance'	 * dashboard widget.	 *	 * Prior to 3.8.0, the widget was named 'Right Now'. Each element	 * is wrapped in list-item tags on output.	 *	 * @since 3.8.0	 *	 * @param string[] $items Array of extra 'At a Glance' widget items.	 */	$elements = apply_filters( 'dashboard_glance_items', array() ); 	if ( $elements ) {		echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";	} 	?>	</ul>	<?php	update_right_now_message(); 	// Check if search engines are asked not to index this site.	if ( ! is_network_admin() && ! is_user_admin()		&& current_user_can( 'manage_options' ) && ! get_option( 'blog_public' )	) { 		/**		 * Filters the link title attribute for the 'Search engines discouraged'		 * message displayed in the 'At a Glance' dashboard widget.

Changelog

Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-admin/includes/dashboard.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.