From 4446e597a7935808a2d04a422f498c7dafed3e62 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 12 Nov 2020 14:36:10 +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. Built from https://develop.svn.wordpress.org/trunk@49565 git-svn-id: http://core.svn.wordpress.org/trunk@49303 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-feed-cache.php | 8 ++++++++ wp-includes/feed.php | 12 ++++++++++-- wp-includes/version.php | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-feed-cache.php b/wp-includes/class-wp-feed-cache.php index 2564dffb80..b3d03ab422 100644 --- a/wp-includes/class-wp-feed-cache.php +++ b/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/wp-includes/feed.php b/wp-includes/feed.php index 0b84cc10a5..265a9a45b2 100644 --- a/wp-includes/feed.php +++ b/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 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index d5541f9711..6c26c65a64 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-beta3-49564'; +$wp_version = '5.6-beta3-49565'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.