
A styled version of the Simple Flickr Photos plugin
We recently implemented Onur Kocatas’ Simple Flickr Photos plugin, that displays a nice little widget of your Flickr photo stream. After testing everything on our development box, when we moved to our testing / staging site on a shared hosting environment, we started throwing errors like this lovely piece of work here:
Warning: file_get_contents() [function.file-get-contents.html]: URL file-access is
disabled in the server configuration in
/wp-content/plugins/simple-flickr-plugin.3.0/simpleflickrphotos.php on line 106
After a little digging, it appears that file_get_contents() has a dependency to the allow_url_fopen php.ini setting. If you are throwing this error and you have access to editing your php.ini file, just do a quick search for ‘fopen’ and set the allow_url_fopen to ‘ON’.
For those of us schmucks in shared hosting situations, this will not do. However, WordPress has been providing an alternative to file_get_contents() for some time, called wp_remote_fopen(). This helper function, defined as part of the WP_Http class replaces the lower-level fopen(0 or cUrl() calls that may or may not be supported on a given server. In fact, as of this writing, there are at least 5 different transports that are tested and may be automatically selected by the WP_Http class. This, along with some robust error checking (the methods will return a WP_Error instance which can be checked with is_wp_error()), makes this the only reliable solution for remote gets.
Updating the plugin to work is trivial, as of the version I’m using (billed as 3.0, but internally actually named 2.9.9.7.1 – seriously – how many decimals do you need in a versioning scheme?).
Replace this line on line 106 of simpleflickrphotos.php:
$html = file_get_contents($url);
with this:
$html = wp_remote_fopen($url);
I would have sent a request or a fork to the author to get his plugin updated (he should really be using built-in WordPress functions whenever possible), but have you seen his “plugin support site”? I’m not even going to do him the favour of providing a link here. Let’s just say, if you want a site dedicated to photos from Turkey… well, don’t go there. Just. Don’t go there. Period.
I sympathize with the guy. I mean, who wants to create a separate support site for a free plugin? It’s just begging for more work than you want. Which is why I haven’t released a plugin to the community yet. Ah well. Hope this fix helps someone out. Of course, once you manually make this fix, you have to be careful that the plugin is not updated, otherwise you’ll have to do it all over again, unless the author implements this fix in a future version (2.9.9.7.1.4.23.6.5.7 perhaps?)
Read More