[theme-reviewers] Using file_get_contents() to import themesettings

Philip M. Hofer (Frumph) philip at frumph.net
Mon May 23 22:12:31 UTC 2011


I use fopen to write to a file for IPN purposes for the buyprint option in 
comicpress, since i'm now unable to upload the latest comicpress due to 
that, i'm probably going to have to either remove the buyprint functionality 
from comicpress or remove comicpress from the repo ;/

basically it writes transaction histories

- Phil



----- Original Message ----- 
From: "Otto" <otto at ottodestruct.com>
To: <theme-reviewers at lists.wordpress.org>
Sent: Monday, May 23, 2011 2:58 PM
Subject: Re: [theme-reviewers] Using file_get_contents() to import 
themesettings


> On Mon, May 23, 2011 at 4:42 PM, Syahir Hakim <khairulsyahir at gmail.com> 
> wrote:
>> Me and the other developer for the theme intend to use 
>> file_get_contents()
>> to read in the json-encoded exported theme settings files when it is
>> uploaded, but as I understand there's a blanket ban on the usage of file
>> operations functions. The file will be handled using the 
>> wp_handle_upload()
>> function, and it doesn't need to be retained after the contents are read.
>
> If you're using the normal upload handlers to deal with it, then you
> don't need to use file_get_contents, necessarily. You have two or
> three options:
>
> 1. The WP_Filesystem_Direct object contains a wrapper around the
> file_get_contents() function called get_contents(). You can use that,
> if you like. Maybe not the best way, but it works.
>
> 2. The file() function is not banned. It reads in a file as an array
> of lines. Kinda handy. Similar to file_get_contents(), but not used by
> as much malware.
>
> 3. WP_Filesystem stuff, as described in the tutorial Emil linked to.
>
>> And since json_encode() and json_decode() functions are only available 
>> since
>> PHP 5.2.1
>
> WordPress includes a compatibility layer. The json_encode and
> json_decode functions will be available in recent versions of
> WordPress (2.7 or 2.8 and up, I think) regardless of the PHP version.
> You don't need to test for them, they'll just be there.
>
>
> -Otto
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers 



More information about the theme-reviewers mailing list