Feeds: Fix backward compatibility of fetch_feed().
In [https://github.com/simplepie/simplepie/pull/795 simplepie/simplepie#795] handling of multiple feed requests was deprecated, triggering the message `Fetching multiple feeds with single SimplePie instance is deprecated since SimplePie 1.9.0, create one SimplePie instance per feed and use SimplePie::merge_items to get a single list of items.` This updates `fetch_feed()` to handle multiple requests using seperate SimplePie instances in order to retain backward compatibility. A PHP 8.5 deprecation was throwing notices in the event an empty URL was passed to `fetch_feed()`, `Using null as an array offset is deprecated, use an empty string instead`. This includes a workaround pending the release of a SimplePie version including [https://github.com/simplepie/simplepie/pull/949 simplepie/simplepie#949]. Fixes #64136. Props audrasjb, jorbin, muryam, oglekler, ozgursar, presskopp, swissspidy, westonruter, wildworks, peterwilsoncc. Built from https://develop.svn.wordpress.org/trunk@61551 git-svn-id: http://core.svn.wordpress.org/trunk@60862 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -832,7 +832,6 @@ function fetch_feed( $url ) {
|
||||
|
||||
$feed->get_registry()->register( SimplePie\File::class, 'WP_SimplePie_File', true );
|
||||
|
||||
$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 ) );
|
||||
|
||||
@@ -846,6 +845,60 @@ function fetch_feed( $url ) {
|
||||
*/
|
||||
do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
|
||||
|
||||
if ( empty( $url ) ) {
|
||||
/*
|
||||
* @todo: Set $url to empty string once supported by SimplePie.
|
||||
*
|
||||
* The early return without proceeding is to work around a PHP 8.5
|
||||
* deprecation issue resolved in https://github.com/simplepie/simplepie/pull/949
|
||||
*
|
||||
* To avoid the duplicate code, this block can be replaced with `$url = '';` once SimplePie
|
||||
* is upgraded to a version that includes the fix.
|
||||
*/
|
||||
$feed->init();
|
||||
$feed->set_output_encoding( get_bloginfo( 'charset' ) );
|
||||
|
||||
if ( $feed->error() ) {
|
||||
return new WP_Error( 'simplepie-error', $feed->error() );
|
||||
}
|
||||
|
||||
return $feed;
|
||||
} elseif ( is_array( $url ) && count( $url ) === 1 ) {
|
||||
$url = array_shift( $url );
|
||||
} elseif ( is_array( $url ) ) {
|
||||
$feeds = array();
|
||||
$simplepie_errors = array();
|
||||
foreach ( $url as $feed_url ) {
|
||||
$simplepie_instance = clone $feed;
|
||||
$simplepie_instance->set_feed_url( $feed_url );
|
||||
$simplepie_instance->init();
|
||||
$simplepie_instance->set_output_encoding( get_bloginfo( 'charset' ) );
|
||||
|
||||
if ( $simplepie_instance->error() ) {
|
||||
$simplepie_errors[] = sprintf(
|
||||
/* translators: %1$s is the feed URL, %2$s is the error message. */
|
||||
__( 'Error fetching feed %1$s: %2$s' ),
|
||||
esc_url( $feed_url ),
|
||||
$simplepie_instance->error()
|
||||
);
|
||||
unset( $simplepie_instance );
|
||||
continue;
|
||||
}
|
||||
|
||||
$feeds[] = $simplepie_instance;
|
||||
unset( $simplepie_instance );
|
||||
}
|
||||
|
||||
if ( ! empty( $simplepie_errors ) ) {
|
||||
return new WP_Error( 'simplepie-error', $simplepie_errors );
|
||||
}
|
||||
|
||||
$feed->init();
|
||||
$feed->data['items'] = SimplePie\SimplePie::merge_items( $feeds );
|
||||
return $feed;
|
||||
}
|
||||
|
||||
$feed->set_feed_url( $url );
|
||||
$feed->init();
|
||||
$feed->set_output_encoding( get_bloginfo( 'charset' ) );
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '7.0-alpha-61546';
|
||||
$wp_version = '7.0-alpha-61551';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user