Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/wp-includes/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,19 @@ function fetch_feed( $url ) {

$feed->get_registry()->register( SimplePie\File::class, 'WP_SimplePie_File', true );

if ( is_array( $url ) && count( $url ) <= 1 ) {
$url = array_shift( $url );
} elseif ( is_array( $url ) ) {
$feeds = array();
foreach ( (array) $url as $feed_url ) {
$feeds[] = fetch_feed( $feed_url );
}
$items = SimplePie\SimplePie::merge_items( $feeds );
$feed->init();
$feed->data['items'] = $items;
return $feed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we perform an early return, the wp_feed_options hook won't fire. This may require a slightly more complicated fix to handle everything properly...

}

$feed->set_feed_url( $url );
/** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
$feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/tests/feed/fetchFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ public function test_empty_charset_does_not_trigger_fatal_error() {
$this->assertStringContainsString( '<a href="https://learn.wordpress.org/">Learn WordPress</a> is a learning resource providing workshops, quizzes, courses, lesson plans, and discussion groups so that anyone, from beginners to advanced users, can learn to do more with WordPress.', $content );
}

/**
* Ensure fetch_feed() accepts multiple feeds.
*
* The main purpose of this test is to ensure that the SimplePie deprecation warning
* is not thrown when requesting multiple feeds.
*
* Secondly it confirms that the markup of the first two items match as they will
* both be from the same feed URL as the array contains the WordPress News feed twice.
*
* @ticket 64136
*/
public function test_fetch_feed_supports_multiple_feeds() {
$feed = fetch_feed( array( 'https://wordpress.org/news/feed/', 'https://wordpress.org/news/feed/' ) );
$content = array();

foreach ( $feed->get_items( 0, 2 ) as $item ) {
$content[] = $item->get_content();
}

$this->assertEqualHTML( $content[0], $content[1], null, 'The contents of the first two items should be identical.' );
}

/**
* Ensure that fetch_feed() is cached on second and subsequent calls.
*
Expand Down
Loading