I have a theme with around 500 custom options, their code looks like this:
<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
<input type="text" " value="<?php echo get_option('option1'); ?>" />
<input type="text" " value="<?php echo get_option('option2'); ?>" />
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="option1,option2" />
<input type="submit" value="<?php _e('Save Changes') ?>" />
</form>
I guess they’re all stored in wp_options table.
The point is, I’m unable to save this data, every time i export/import WordPress settings these custom options values disappear, changing theme also wipes them out.
How to fix that?
WordPress is built to import and export content. As such, there is no built-in way to import or export settings.
Some theme and plugin authors, however, have built tools into their systems that import/export XML files that their systems can use store options.
A great example is WordPress SEO by Yoast. Not only can you import/export settings from his plugin, but you can import settings from other systems, too. Yoast’s plugin exports an
.ini
file that contains options and settings in the following format:This is just one example. My personal recommendation is that you add a button or other trigger that saves your 500 or so custom options in an XML file. You’ll have to write this yourself, but it should be fairly straight-forward.
You can then import this same XML file, parse it, and restore your options. Once again, something you’ll have to write, but do-able.
If you want to use XML, I recommend you read up on the DOMDocument object that ships with PHP5. It makes creating/reading/manipulating XML documents via PHP pretty easy.