diff --git a/src/wp-includes/feed.php b/src/wp-includes/feed.php index 421bee71730d1..b796843d43e86 100644 --- a/src/wp-includes/feed.php +++ b/src/wp-includes/feed.php @@ -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; + } + $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 ) ); diff --git a/tests/phpunit/tests/feed/fetchFeed.php b/tests/phpunit/tests/feed/fetchFeed.php index 71ed1650e717a..9b191747d3e2f 100644 --- a/tests/phpunit/tests/feed/fetchFeed.php +++ b/tests/phpunit/tests/feed/fetchFeed.php @@ -33,6 +33,28 @@ public function test_empty_charset_does_not_trigger_fatal_error() { $this->assertStringContainsString( 'Learn WordPress 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. *