Opened 2 years ago
Closed 7 months ago
#17756 closed defect (bug) (fixed)
class-feed.php file_get_contents error
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | Feeds | Version: | 3.2 |
| Severity: | normal | Keywords: | has-patch |
| 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:
if(!file_exists($url)){
$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)
Change History (8)
- Component changed from Administration to Cache
- Description modified (diff)
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();
if(empty($url)){
return new WP_Error('simplepie-error', 'No Feed Input');
}
$feed->set_feed_url($url);
SergeyBiryukov — 21 months ago
comment:3
SergeyBiryukov — 21 months ago
- Keywords has-patch added; needs-patch removed
comment:5
SergeyBiryukov — 8 months ago
- Component changed from External Libraries to Feeds

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; }