Are there any scripts, classes, and/or functions built-in to WP for a plugin to export/import its saved data from wp_options?

In WordPress, are there any supported ‘script plugins’, Classes, and/or a WordPress function that will allow a plugin to use to export/import its own data from the database to a txt/json file? A way to assist in handling data for a back-up feature in a plugin.

Original the code I have worked on a localhost, but not when I went live, and for various reasons. Initially when this was posted, as Oli had pointed out in his answer, “You cannot do AJAX file uploads. They’re not supported but you can fake it.” How can I upload files asynchronously with jQuery?. Since then, some more answers have been added.

Read More

Most of the issues surface when using a form and an ajax function. Especially when a file ($_FILE) is involved. To explain, I’m trying to take the following route HTTP->JS->PHP(AJAX)->JS(AJAX)->PHP(iFrame) instead of HTTP->JS->PHP(iFrame) by canceling the form submit so that ajax can take over and then have an iFrame created and targeted (btw, is this a design flaw?).

Basically I’m in search of something, preferably WordPress supported (script/class/function), to handle data between JS to PHP and PHP to JS.

Related posts

Leave a Reply

1 comment

  1. The only native import/export facility is the one under Tools in the admin. And even that needs an extension (plugin) for importing from different formats.

    It’s pretty straightforward to build one yourself. Something along the lines of:

    $options = get_my_options();
    header( 'Content-disposition: attachment; filename=my_export.txt' );
    header( 'Content-Type: text/plain' );
    echo json_encode( $options );
    exit;
    

    And conversely:

    if ( ! empty( $_FILES['my_import']['tmp_name'] ) ) {
       if ( $import = file_get_contents( $_FILES['my_import']['tmp_name'] ) ) {
           if ( $options =@ json_decode( $import ) ) {
               save_my_options( $options );
           }
       }
    }