I already have a theme options page that saves to wp_options > kittens_options.
I’m looking for a simple way to incorporate an import/export textarea of those options on my options page.
I’ve searched Google for several hours now and haven’t been able to find any useful tutorials. If anyone knows off the top of their head let me know.
Thanks
CODE I’M WORKING WITH SO FAR
<?php
function kittens_transport_page() {
global $themename, $shortname;
$kittens = get_option( 'kittens_options' );
$currentsettings = "";
if ( isset( $_POST['import'] ) && trim($_POST['kittens_import_settings']) != "" ) {
$currentsettings = $_POST['kittens_import_settings'];
} elseif ( isset( $kittens ) && ( $kittens != "" ) ) {
$currentsettings = base64_encode( serialize( $kittens ) );
}
}
?>
<div id="import-export">
<h2>Import & Export Theme Options</h2>
<form method="post" action="#">
<label class="description">Import Options</label>
<textarea rows="8" cols="40" id="kittens_import_settings" name="kittens_import_settings" class="large-text"></textarea><br />
<input type="submit" value="Import" id="import" name="import" class="button-primary" onClick="return confirm('Are you sure you want to import these settings?')" /> <?php if ( isset( $_POST['import'] ) && $_POST['kittens_import_settings'] != "" ) { echo "Settings Imported Successfully"; } ?>
</form>
<br />
<br />
<label class="description">Export Options</label>
<textarea rows="8" cols="40" id="kittens_export_settings" name="kittens_export_settings" class="large-text" readonly="readonly"><?php echo $currentsettings; ?></textarea>
<?php
function kittens_import_settings(){
global $shortname;
if ( isset( $_POST['import'] ) && trim($_POST['kittens_import_settings']) != "" ) {
if(isset($_POST['kittens_import_settings']) && current_user_can('edit_themes')){
$imported_settings = unserialize(base64_decode($_POST['kittens_import_settings']));
update_option($shortname . '_settings', $imported_settings);
}
}
}
?>
maybe you can write 2 functions for your options
theme page)
all of theses functions can be in your functions.php of the theme
here is an example of function to write a ini (txt) file
You can use write_ini_file to send the values to a file, parse_ini_file to read them back in 🙂
Your code is messy, but seems ok.
The only thing you need to do is to decode the
$_POST
‘ed data on import, so instead of:update_option( $shortname . '_settings', $_POST['kittens_import_settings'] );
use: