rss.php Hack 2

To facilitate testing of the Clean Options plugin, I have placed several RSS feeds in my sidebars by using the WordPress RSS widget. One of these was exhibiting some rather strange behavior. When I first visited my blog after having been away for a while, the feed contents displayed as expected. But upon return within a certain time frame, the contents were not displayed. Unfortunately, the MagpieRSS class was not throwing an error to help me solve the problem using the Error Reporting plugin. I finally discovered that what set this feed apart from the others was that it was a FeedBurner blog.

MagpieRSS was putting the feed contents into the cache OK, but for some reason unknown to me, it failed when trying to get the contents out of the cache. By searching, I found various topics of interest, such as FeedBurner redirects causing problems with Twitter plugins, and several that suggested a fix by turning off MagpieRSS caching by defining MAGPIE_CACHE_ON as false in the WordPress config file. This worked. But is turning off the cache a good idea? Without it the blog must fetch every feed's contents upon every page load. This could slow things down and is not needed for feed content, that unlike tweets, doesn't change that fast. And in my case only one feed of several was having the problem. So I came up with this hack as a solution to cache all the feeds except the FeedBurner feed.

If you look in the wp-includes/rss.php file about 2 fifths of the way down, you will see the fetch_rss function. If you make these changes ( indicates code is part of the previous line)

function fetch_rss ($url) {
	// initialize constants
	init();

	if ( !isset($url) ) {
		// error("fetch_rss called without a url");
		return false;
	}

	// if cache is disabled
//	if ( !MAGPIE_CACHE_ON ) {
	if ( ( !MAGPIE_CACHE_ON )
		 || ( stripos($url, 'feedburner') !== FALSE ) ) {

only FeedBurner feeds will not be cached, thereby maintaining efficiency where possible, while still reliably displaying the contents of the FeedBurner feed.

Post a Comment

Your email is never shared. Required fields are marked *

*
*