Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#17756 closed defect (bug) (fixed)

class-feed.php file_get_contents error

Reported by: kmfj1 Owned by: dd32
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.2
Component: Feeds Keywords: has-patch
Focuses: Cc:

Description (last modified by dd32)

I removed my feed URL from the dashboard incoming links through the configuration. When I go back to view Incoming Links I get a file not found error in file_get_contents in class-feed.php on about line 88.

Warning: file_get_contents(http:) [function.file-get-contents]: failed to open stream: Invalid argument in C:\_vhosts\xxx\xxx\wp-includes\class-feed.php on line 88

RSS Error: file_get_contents could not read the file

file_get_contents can't open the non-existent URL (http:), which causes the PHP error. If the script used file_exists before file_get_contents this should fix the issue? This is not a SimplePie issue but the extended class: WP_Feed_Cache

I changed to:


        $this->error = 'the file doesn\'t exist could not read the file'; $this->success = false;

    } else{

        if ( ! $this->body = file_get_contents($url) ) {
        $this->error = 'file_get_contents could not read the file'; $this->success = false;



This fixed the issue?

Attachments (1)

17756.patch (538 bytes) - added by SergeyBiryukov 9 years ago.

Download all attachments as: .zip

Change History (8)

#1 @dd32
9 years ago

  • Component changed from Administration to Cache
  • Description modified (diff)

The reason this is fitting a file_get_contents() call is because it assumes it's a local file. This is because it doesn't recognise that as a URL, as it doesn't match the pattern http(s)?:

Seems worthwhile changing that to something like the following, I'm not sure if we need another string for it, not that these strings are translated anyway

if ( ! file_exists($url) || ( ! $this->body = file_get_contents($url) ) ) {
	$this->error = 'file_get_contents could not read the file';
	$this->success = false;

#2 @kmfj1
9 years ago

It looks like this can be traced back to /wp-admin/includes/dashboard.php, which is sent an empty $url. Line 791 wp_dashboard_incoming_links_output($url) uses an empty $url: $rss = fetch_feed( $url ). Also, fetch_feed($url) in /wp-includes/feed.php doesn't catch the error, and uses SimplePie to fetch the feed on an empty $url.

SimplePie also doesn't catch the error.

The initial call to wp_dashboard_incoming_links_output($url) is from /wp-admin/index-extra.php.

So, I am not sure how best to handle this as far as strings? I am a longtime PHP programmer but a relative Wordpress Newbie.

A simple change to fetch_feed($url) might resolve this, though I am not sure how best to handle the error output new WP_Error('simplepie-error', 'No Feed Input');

Begin with:

require_once (ABSPATH . WPINC . '/class-feed.php');

$feed = new SimplePie();


return new WP_Error('simplepie-error', 'No Feed Input');



#3 @SergeyBiryukov
9 years ago

  • Keywords has-patch added; needs-patch removed

#4 @nacin
8 years ago

  • Component changed from Cache to External Libraries

#5 @SergeyBiryukov
8 years ago

  • Component changed from External Libraries to Feeds

#6 @dd32
8 years ago

  • Milestone changed from Awaiting Review to 3.5

#7 @dd32
8 years ago

  • Owner set to dd32
  • Resolution set to fixed
  • Status changed from new to closed

In 22330:

When reading local feeds from disk, check that the file exists first to avoid a PHP Warning in WP_SimplePie_File. Props SergeyBiryukov. Fixes #17756

Note: See TracTickets for help on using tickets.