wppaste
WordPress

wp_widget_rss_process( array $widget_rss, bool $check_feed = true ): array

Since
2.5.0
Source
wp-includes/widgets.php:1795
Processes RSS feed widget data and optionally retrieve feed items.

Description

The feed widget can not have more than 20 items or it will reset back to the default, which is 10.

The resulting array has the feed title, feed url, feed link (from channel), feed items, error (if any), and whether to show summary, author, and date.
All respectively in the order of the array elements.

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

$widget_rssarray
RSS widget feed data. Expects unescaped data.
$check_feedbooloptional
Whether to check feed for errors. Default true.Default: true

Return value

array

Performance profile

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
49–82

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

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

What it touches

  • hookthird-party callbacksapply_filters()one call below wp_widget_rss_process()

Further down the call graph this can also reach option, cache, serialize, 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 · 3 distinct outcomes

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

WhenInstructionsCalls it makes
always49–55strip_tags(), sanitize_url(), strip_tags(), compact()
is_wp_error()61–67strip_tags(), sanitize_url(), strip_tags(), fetch_feed(), is_wp_error(), ->get_error_message(), compact()
!is_wp_error() && $link === false76–82strip_tags(), sanitize_url(), strip_tags(), fetch_feed(), is_wp_error(), ->get_permalink(), strip_tags(), esc_url(), stristr(), ->__destruct(), compact()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8849–829
8.58849–829
8.48849–8295 fewer instructions than PHP 8.3
8.39351–849
8.29351–849
8.19351–849
7.49351–849

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 · 4

Used by · 2

Source code

function wp_widget_rss_process( $widget_rss, $check_feed = true ) {	$items = (int) $widget_rss['items'];	if ( $items < 1 || 20 < $items ) {		$items = 10;	}	$url          = sanitize_url( strip_tags( $widget_rss['url'] ) );	$title        = trim( strip_tags( $widget_rss['title'] ?? '' ) );	$show_summary = (int) ( $widget_rss['show_summary'] ?? 0 );	$show_author  = (int) ( $widget_rss['show_author'] ?? 0 );	$show_date    = (int) ( $widget_rss['show_date'] ?? 0 );	$error        = false;	$link         = ''; 	if ( $check_feed ) {		$rss = fetch_feed( $url ); 		if ( is_wp_error( $rss ) ) {			$error = $rss->get_error_message();		} else {			$link = esc_url( strip_tags( $rss->get_permalink() ) );			while ( stristr( $link, 'http' ) !== $link ) {				$link = substr( $link, 1 );			} 			$rss->__destruct();			unset( $rss );		}	} 	return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );}

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.

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.