wp_widget_rss_output( string|array|object $rss, array $args = array() )
- Since
- 2.5.0
- Source
wp-includes/widgets.php:1599
Compatibility
- WordPress
- since 2.5.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
$rssstring|array|object- RSS url.
$argsarrayoptional- Widget arguments.Default:
array()
Performance profile
How much work a call to wp_widget_rss_output() 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
- Scales with input
- Instructions
- 9–55
- Plugin surface
- None
- Called by
- 3
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 237.
Nothing here hands control to plugin code.
3 places 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 - hookthird-party callbacks
apply_filters()one call below wp_widget_rss_output() - cacheobject cache
wp_cache_get()one call below wp_widget_rss_output() - serializeserialisation
maybe_unserialize()one call below wp_widget_rss_output()
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 · 11 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_widget_rss_output() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_string($rss) && !is_object($rss) | 9–11 | none |
!is_string($rss) && is_object($rss) && is_wp_error() && !is_admin() && !current_user_can() | 20–22 | is_wp_error(), is_admin(), current_user_can() |
is_wp_error() && !is_admin() && !current_user_can() | 21–28 | fetch_feed(), is_wp_error(), is_admin(), current_user_can() |
!is_string($rss) && is_object($rss) && is_wp_error() && is_admin() | 29–31 | is_wp_error(), is_admin(), __(), ->get_error_message(), esc_html() |
is_wp_error() && is_admin() | 30–37 | fetch_feed(), is_wp_error(), is_admin(), __(), ->get_error_message(), esc_html() |
!is_string($rss) && is_object($rss) && is_wp_error() && !is_admin() && current_user_can() | 33–35 | is_wp_error(), is_admin(), current_user_can(), __(), ->get_error_message(), esc_html() |
is_wp_error() && !is_admin() && current_user_can() | 34–41 | fetch_feed(), is_wp_error(), is_admin(), current_user_can(), __(), ->get_error_message(), esc_html() |
!is_string($rss) && is_object($rss) && !is_wp_error() && !->get_item_quantity() | 42–46 | is_wp_error(), wp_parse_args(), ->get_item_quantity(), __(), ->__destruct() |
!is_wp_error() && !->get_item_quantity() | 43–52 | fetch_feed(), is_wp_error(), wp_parse_args(), ->get_item_quantity(), __(), ->__destruct() |
!is_string($rss) && is_object($rss) && !is_wp_error() && ->get_item_quantity() | 44–49 | is_wp_error(), wp_parse_args(), ->get_item_quantity(), ->get_items(), ->__destruct() |
!is_wp_error() && ->get_item_quantity() | 45–55 | fetch_feed(), is_wp_error(), wp_parse_args(), ->get_item_quantity(), ->get_items(), ->__destruct() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 237 | 9–55 | 23 | |
| 8.5 | 237 | 9–55 | 23 | |
| 8.4 | 237 | 9–55 | 23 | 8 fewer instructions than PHP 8.3 |
| 8.3 | 245 | 9–55 | 23 | |
| 8.2 | 245 | 9–55 | 23 | |
| 8.1 | 245 | 9–55 | 23 | |
| 7.4 | 245 | 9–55 | 23 |
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 · 13
- fetch_feed()Builds SimplePie object based on RSS or Atom feed from URL.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- is_admin()Determines whether the current request is for an administrative interface page.
- current_user_can()Returns whether the current user has the specified capability.
- __()Retrieves the translation of $text.
- esc_html()Escaping for HTML blocks.
- wp_parse_args()Merges user defined arguments into defaults array.
- esc_url()Checks and cleans a URL.
- get_option()Retrieves an option value based on an option name.
- esc_attr()Escaping for HTML attributes.
- wp_trim_words()Trims text to a certain number of words.
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
Show all 13
- date_i18n()Retrieves the date in localized format, based on a sum of Unix timestamp and timezone offset in seconds.
Used by · 3
- WP_Widget_RSS::widget()Outputs the content for the current RSS widget instance.
- wp_dashboard_primary_output()Displays the WordPress events and news feeds.
- wp_dashboard_rss_output()Display generic dashboard RSS widget feed.
Source code
function wp_widget_rss_output( $rss, $args = array() ) { if ( is_string( $rss ) ) { $rss = fetch_feed( $rss ); } elseif ( is_array( $rss ) && isset( $rss['url'] ) ) { $args = $rss; $rss = fetch_feed( $rss['url'] ); } elseif ( ! is_object( $rss ) ) { return; } if ( is_wp_error( $rss ) ) { if ( is_admin() || current_user_can( 'manage_options' ) ) { echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</p>'; } return; } $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0, ); $args = wp_parse_args( $args, $default_args ); $items = (int) $args['items']; if ( $items < 1 || 20 < $items ) { $items = 10; } $show_summary = (int) $args['show_summary']; $show_author = (int) $args['show_author']; $show_date = (int) $args['show_date']; if ( ! $rss->get_item_quantity() ) { echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>'; $rss->__destruct(); unset( $rss ); return; } echo '<ul>'; foreach ( $rss->get_items( 0, $items ) as $item ) { $link = $item->get_link(); while ( ! empty( $link ) && stristr( $link, 'http' ) !== $link ) { $link = substr( $link, 1 ); } $link = esc_url( strip_tags( $link ) ); $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); if ( empty( $title ) ) { $title = __( 'Untitled' ); } $desc = html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) ); $summary = ''; if ( $show_summary ) { $summary = $desc; // Change existing [...] to […]. if ( str_ends_with( $summary, '[...]' ) ) { $summary = substr( $summary, 0, -5 ) . '[…]'; } $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>'; } $date = ''; if ( $show_date ) { $date = $item->get_date( 'U' ); if ( $date ) { $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>'; } } $author = ''; if ( $show_author ) { $author = $item->get_author();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.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/widgets.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.