I came across a bug today with a RSS feed plugin we use for one of our WordPress-powered client sites. The bug is with Simple Feed List (v 1.4,  by David Artiss), and occurs when the feed link supplied  is either dead or unreachable. When either one of these two cases occur, the plugin fails and causes the rest of the page to stop executing. In other words, no error checking is in place to ensure that it fails gracefully.

Simple Feed List is a useful plugin that allows you to display news headlines (with a number of options) from an RSS feed.

The fix is simple enough – you simply need to add logic to the plugin to ensure that the link being opened is in fact valid and reachable. In the PHP file for the plugin, simple-feed-list.php, the following code block currently exists which handles the opening and reading of the URL (RSS link) that has been fed to it.

// Fetch in the contents of the XML file
$handle = fopen($feed_url,"rb");
$array = '';

while (!feof($handle)) {
	$array .= fread($handle,8192);
}

fclose($handle);

// Check that the file is in RSS format
if ((strpos($array,"<rss")===false)&&($check_failure==0)) {
	echo "<li style=\"color: #f00; font-weight: bold;\">Feed not available.</li>\n";
	$check_failure=1;
}

Modify this by wrapping the code block above in an IF statement that verifies that the URL being opened was in fact successful; otherwise, return an error statement and return gracefully.

if ($check_failure==0) {

	if(@ $handle = fopen($feed_url,"rb")) {
		// Fetch in the contents of the XML file
		$handle = fopen($feed_url,"rb");
		$array = '';

		while (!feof($handle)) {
			$array .= fread($handle,8192);
		}

		fclose($handle);

		// Check that the file is in RSS format
		if ((strpos($array,"<rss")===false)&&($check_failure==0)) {
			echo "<li style=\"color: #f00; font-weight: bold;\">Feed not available.</li>\n";
			$check_failure=1;
		}
	} else {
		echo "<li style=\"color: #f00; font-weight: bold;\">Feed not available.</li>\n";
		$check_failure=1;
	}
}

So there you have it, an easy fix for an otherwise nasty little bug that can otherwise cause a bit of mayhem (in our case it was one of the first plugins executed on the page, so when it failed it meant the rest of the page did not render!)