[theme-reviewers] Using file_get_contents() to import theme settings
khairulsyahir at gmail.com
Tue May 24 01:20:03 UTC 2011
Went with the WP_Filesystem stuff. And thanks for the compat layer tip!
+6421 0333 649
On 24/5/2011 9:58 AM, Otto wrote:
> 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.
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
More information about the theme-reviewers