wppaste
WordPress

wp_dashboard_cached_rss_widget( string $widget_id, callable $callback, array $check_urls = array(), mixed $args ): bool

Since
2.5.0, 5.3.0
Source
wp-admin/includes/dashboard.php:1162
Checks to see if all of the feed url in $check_urls are cached.

Description

If $check_urls is empty, look for the rss feed url found in the dashboard widget options of $widget_id. If cached, call $callback, a function that echoes out output for this widget. If not cache, echo a "Loading..." stub which is later replaced by Ajax call (see top of /wp-admin/index.php)

Compatibility

WordPress
since 5.3.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.

Parameters

$widget_idstring
The widget ID.
$callbackcallable
The callback function used to display each feed.
$check_urlsarrayoptional
RSS feeds.Default: array()
$argsmixed
Optional additional parameters to pass to the callback function.

Return value

bool
True on success, false on failure.

Performance profile

How much work a call to wp_dashboard_cached_rss_widget() 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

Reaches the database via get_user_by().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
32–76

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • transienttransientget_transient()called directly
  • hookthird-party callbacksapply_filters()one call below wp_dashboard_cached_rss_widget()
  • cacheobject cachewp_cache_get()one call below wp_dashboard_cached_rss_widget()
  • serializeserialisationmaybe_unserialize()one call below wp_dashboard_cached_rss_widget()
  • querycontent queryget_user_by()one call below wp_dashboard_cached_rss_widget()

What one call costs · 7 distinct outcomes

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

WhenInstructionsCalls it makes
empty($check_urls) && empty($value)32wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_option()
!empty($check_urls)39–40wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_user_locale(), md5(), get_transient()
!empty($check_urls) && $output === false && !is_callable()44wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_user_locale(), md5(), get_transient(), is_callable()
empty($check_urls)50–52wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_option(), get_user_locale(), md5(), get_transient()
empty($check_urls) && $output === false && !is_callable()55–56wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_option(), get_user_locale(), md5(), get_transient(), is_callable()
!empty($check_urls) && $output === false && is_callable()64wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_user_locale(), md5(), get_transient(), is_callable(), array_unshift(), ob_start(), call_user_func_array(), ob_get_flush(), set_transient()
empty($check_urls) && $output === false && is_callable()75–76wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_option(), get_user_locale(), md5(), get_transient(), is_callable(), array_unshift(), ob_start(), call_user_func_array(), ob_get_flush(), set_transient()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8232–767
8.58232–767
8.48232–767
8.38232–767
8.28232–767
8.18232–7671 more instruction than PHP 7.4
7.48132–757

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.

Uses · 7

Used by · 1

Source code

function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) {	$doing_ajax = wp_doing_ajax();	$loading    = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&hellip;' ) . '</p>';	$loading   .= wp_get_admin_notice(		__( 'This widget requires JavaScript.' ),		array(			'type'               => 'error',			'additional_classes' => array( 'inline', 'hide-if-js' ),		)	); 	if ( empty( $check_urls ) ) {		$widgets = get_option( 'dashboard_widget_options' ); 		if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) {			echo $loading;			return false;		} 		$check_urls = array( $widgets[ $widget_id ]['url'] );	} 	$locale    = get_user_locale();	$cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );	$output    = get_transient( $cache_key ); 	if ( false !== $output ) {		echo $output;		return true;	} 	if ( ! $doing_ajax ) {		echo $loading;		return false;	} 	if ( $callback && is_callable( $callback ) ) {		array_unshift( $args, $widget_id, $check_urls );		ob_start();		call_user_func_array( $callback, $args );		// Default lifetime in cache of 12 hours (same as the feeds).		set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS );	} 	return true;}

Changelog

Introduced in 2.5.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.

5.3.0
Formalized the existing and already documented ...$args parameter by adding it to the function signature.from the docblock
2.5.0
Introduced.from the docblock

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.