[FIX] Last.fm for WordPress – “Warning: gzinflate() [function.gzinflate]: data error…”

When I first tried the Last.fm for WordPress plugin with this WordPress 2.8.4 installation, I received the following error :

Warning: gzinflate() [function.gzinflate]: data error in /hermes/web07/b2563/blah/blah/wp/wp-includes/http.php on line 1787

The WordPress plugin page mentions that the plugin is compatible up to WordPress 2.7.

After checking out the code in the plugin file (/wp-content/plugins/lastfm-for-wordpress/lastfm.php), I was able to determine that there was something wrong with the fetch_rss() function. Using that function caused the above warning to be displayed. WordPress Function Reference mentions that the function has been deprecated, but it should still work to enable backwards compatibility. The suggestion given on that page was to use the fetch_feed, which seems pretty straightforward. But I chose to do some more digging.

I googled the problem to try and figure out what was wrong. The most common solution I found recommended editing the http.php file (/wp/wp-includes/http.php) and altering line 1787. I think it was also accepted as a bug in WordPress and will be rectified in WordPress 2.9 (out now). But anyway, one thing I’ve learnt from my previous WordPress updates — Never alter code in core files. I lost all my “custom modifications” when I upgraded to 2.8. I’ve learnt to write maintainable code the hard way. :P

It’ll take a few weeks for me to make up my mind to update WP. Until then, the mod should work just fine.

To sum up the mods I’ve made to the original plugin file for it to work with my WordPress 2.8 installtion -

  • Changed fetch_rss() implementation to the new fetch_feed() implementation. Uses the SimplePie and FeedCache functionality for retrieval and parsing and automatic caching, instead of MagpieRSS and RSSCache.
  • Commented out MagpieRSS settings variables.
  • Removed line 131.

$songs = fetch_rss(‘http://ws.audioscrobbler.com/1.0/user/’.$username.’/recenttracks.rss’);

Download here or See full plugin code.

NO WARRANTY OR SUPPORT PROVIDED. USE AT YOUR OWN RISK.

CREDIT TO ORIGINAL PLUGIN AUTHOR : Ricardo González

UPDATE: I still see the gzinflate error occasionally.