So what is the best way to create an export and import feature, I tried serialize()
and urlencode()
on an array of options to be used in a url like so:
export.php?data=(long string)
, and use $_GET method in export.php file which forces download using headers, but that’s not a good idea because the array is very large.
so what is the best way to do export and import theme options ?
I’m just about done adding my own
admin panel class
an Import/ Export functionality and I’ve come to a point where i feel the best way to export data would be as a base64 encoded serialize array, and this is way,serialize data alone is somewhat human readable and i wonted to avoid that (theme options have stored files,images url , paths and other sensitive data), hence the base64 encoding.
Now i agree this makes a mess of a data but a simple single line string comes out which is very easy to copy paste without making mistakes (like removing lines, brackets, parentheses …).
As for the size of
$_GET
depends on used browser. Some support 2000 character,some more. I have a rule of thumb to use
$_POST
method, if send data has more than255 character.
Example , say $options is an array of theme options then export is done like this
and the import code is:
this is actually the code i use in my plugin Shortcodes UI for the import export functionality.
Update
As for downloading the export dump, you don’t have to create a more the one request meaning that you can export to a file with a single request, ex:
So all i have to do is add a call to
create_export_download_link(true);
in my theme options panel and it will create a link like this :obviously you will need to change it up a bit to match your needs but you should get the idea.