From f1aaf6d359215b799246c13ae14b85c1e5d170d9 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Wed, 29 Aug 2012 00:25:52 +0000 Subject: [PATCH] Stabilize how WordPress hooks into SimplePie to implement transient caching. Since a plugin can load a previous (< 1.3) version of SimplePie before we do, we need to be compatible with our old method of overriding SimplePie_Cache::create(). SimplePie_Cache::create() was converted to static in 1.3 (as it was called), requiring that we create two different definitions of WP_Feed_Cache (extends SimplePie_Cache). Instead, we can use 1.3's new object registry, and leave the old WP_Feed_Cache to SimplePie 1.2 versions. see #21183. git-svn-id: http://core.svn.wordpress.org/trunk@21652 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-feed.php | 24 ++++++++++++++---------- wp-includes/feed.php | 12 ++++++++++-- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/wp-includes/class-feed.php b/wp-includes/class-feed.php index bd4ed7563f..126255eb28 100644 --- a/wp-includes/class-feed.php +++ b/wp-includes/class-feed.php @@ -3,17 +3,21 @@ if ( !class_exists('SimplePie') ) require_once (ABSPATH . WPINC . '/class-simplepie.php'); -class WP_Feed_Cache extends SimplePie_Cache { - /** - * Create a new SimplePie_Cache object - * - * @static - * @access public - */ - public static function create($location, $filename, $extension) { - return new WP_Feed_Cache_Transient($location, $filename, $extension); +if ( version_compare( SIMPLEPIE_VERSION, '1.3-dev', '>' ) ) : + SimplePie_Cache::register( 'wp-transient', 'WP_Feed_Cache_Transient' ); +else : + class WP_Feed_Cache extends SimplePie_Cache { + /** + * Create a new SimplePie_Cache object + * + * @static + * @access public + */ + function create($location, $filename, $extension) { + return new WP_Feed_Cache_Transient($location, $filename, $extension); + } } -} +endif; class WP_Feed_Cache_Transient { var $name; diff --git a/wp-includes/feed.php b/wp-includes/feed.php index 1665cf59ba..e5b96ab122 100644 --- a/wp-includes/feed.php +++ b/wp-includes/feed.php @@ -532,9 +532,17 @@ function fetch_feed($url) { require_once (ABSPATH . WPINC . '/class-feed.php'); $feed = new SimplePie(); + + if ( version_compare( SIMPLEPIE_VERSION, '1.3-dev', '>' ) ) { + $feed->set_cache_location( 'wp-transient' ); + $feed->registry->register( 'Cache', 'WP_Feed_Cache_Transient' ); + $feed->registry->register( 'File', 'WP_SimplePie_File' ); + } else { + $feed->set_cache_class( 'WP_Feed_Cache' ); + $feed->set_file_class( 'WP_SimplePie_File' ); + } + $feed->set_feed_url($url); - $feed->set_cache_class('WP_Feed_Cache'); - $feed->set_file_class('WP_SimplePie_File'); $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 43200, $url)); do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) ); $feed->init();