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:1166
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
- Scaling
- Constant
- Instructions
- 32–76
- Plugin surface
- None
- Called by
- 1
Reaches the database via get_user_by().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 82.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - transienttransient
get_transient()called directly - hookthird-party callbacks
apply_filters()one call below wp_dashboard_cached_rss_widget() - cacheobject cache
wp_cache_get()one call below wp_dashboard_cached_rss_widget() - serializeserialisation
maybe_unserialize()one call below wp_dashboard_cached_rss_widget() - querycontent query
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
empty($check_urls) && empty($value) | 32 | wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_option() |
!empty($check_urls) | 39–40 | wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_user_locale(), md5(), get_transient() |
!empty($check_urls) && $output === false && !is_callable() | 44 | wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_user_locale(), md5(), get_transient(), is_callable() |
empty($check_urls) | 50–52 | wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_option(), get_user_locale(), md5(), get_transient() |
empty($check_urls) && $output === false && !is_callable() | 55–56 | wp_doing_ajax(), __(), __(), wp_get_admin_notice(), get_option(), get_user_locale(), md5(), get_transient(), is_callable() |
!empty($check_urls) && $output === false && is_callable() | 64 | wp_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–76 | wp_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 82 | 32–76 | 7 | |
| 8.5 | 82 | 32–76 | 7 | |
| 8.4 | 82 | 32–76 | 7 | |
| 8.3 | 82 | 32–76 | 7 | |
| 8.2 | 82 | 32–76 | 7 | |
| 8.1 | 82 | 32–76 | 7 | 1 more instruction than PHP 7.4 |
| 7.4 | 81 | 32–75 | 7 |
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
- wp_doing_ajax()Determines whether the current request is a WordPress Ajax request.
- __()Retrieves the translation of $text.
- wp_get_admin_notice()Creates and returns the markup for an admin notice.
- get_option()Retrieves an option value based on an option name.
- get_user_locale()Retrieves the locale of a user.
- get_transient()Retrieves the value of a transient.
- set_transient()Sets/updates the value of a transient.
Used by · 1
- wp_dashboard_primary()'WordPress Events and News' dashboard widget.
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…' ) . '</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.
Signature, return type and hooks compared across 5 parsed releases.
...$args parameter by adding it to the function signature.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.