[theme-reviewers] Using file_get_contents() to import theme settings
otto at ottodestruct.com
Mon May 23 21:58:38 UTC 2011
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
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.
More information about the theme-reviewers