From e8e031d2dd62fca3a4bcfcdfd4e01d839cb88b47 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 12 Nov 2020 14:34:33 +0000 Subject: [PATCH] Feeds: Register transient feed cache handler using the recommended method for SimplePie 1.3 or later. This fixes a "Non-static method cannot be called statically" fatal error when calling `fetch_feed()` on PHP 8. Follow-up to [21644], [21652], [22366], [22599]. Props dd32, afragen, Senning, markoheijnen, ComputerGuru, useStrict, Ipstenu, nacin, l3rady, HoaSi, NathanAtmoz, fabifott, jfoulquier, thefarlilacfield, subscriptiongroup, rogerlos, Mte90, mopsyd, dossy, stulab, MadtownLems, roikles, justlevine, joostdevalk, OptimizingMatters, hellofromTonya, bph, ayeshrajans, SergeyBiryukov. Fixes #29204. git-svn-id: https://develop.svn.wordpress.org/trunk@49565 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-feed-cache.php | 8 ++++++++ src/wp-includes/feed.php | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-feed-cache.php b/src/wp-includes/class-wp-feed-cache.php index 2564dffb80..b3d03ab422 100644 --- a/src/wp-includes/class-wp-feed-cache.php +++ b/src/wp-includes/class-wp-feed-cache.php @@ -5,8 +5,16 @@ * @package WordPress * @subpackage Feed * @since 4.7.0 + * @deprecated 5.6.0 */ +_deprecated_file( + basename( __FILE__ ), + '5.6.0', + '', + __( 'This file is only loaded for backward compatibility with SimplePie 1.2.x. Please consider switching to a recent SimplePie version.' ) +); + /** * Core class used to implement a feed cache. * diff --git a/src/wp-includes/feed.php b/src/wp-includes/feed.php index 0b84cc10a5..265a9a45b2 100644 --- a/src/wp-includes/feed.php +++ b/src/wp-includes/feed.php @@ -789,7 +789,6 @@ function fetch_feed( $url ) { require_once ABSPATH . WPINC . '/class-simplepie.php'; } - require_once ABSPATH . WPINC . '/class-wp-feed-cache.php'; require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php'; require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php'; require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.php'; @@ -801,7 +800,16 @@ function fetch_feed( $url ) { // constructor sets it before we have a chance to set the sanitization class. $feed->sanitize = new WP_SimplePie_Sanitize_KSES(); - $feed->set_cache_class( 'WP_Feed_Cache' ); + // Register the cache handler using the recommended method for SimplePie 1.3 or later. + if ( method_exists( 'SimplePie_Cache', 'register' ) ) { + SimplePie_Cache::register( 'wp_transient', 'WP_Feed_Cache_Transient' ); + $feed->set_cache_location( 'wp_transient' ); + } else { + // Back-compat for SimplePie 1.2.x. + require_once ABSPATH . WPINC . '/class-wp-feed-cache.php'; + $feed->set_cache_class( 'WP_Feed_Cache' ); + } + $feed->set_file_class( 'WP_SimplePie_File' ); $feed->set_feed_url( $url );