Import/Export Options Keep Getting Overridden
So I've extended Titan to allow for importing/exporting the options from installation to installation. When it's done, I can put it back up here on Github, but I'm running into a final issue. Basically, I've set it up so that there's new options for import/export panels to be added, and the "save" button gets replaced with an "importsave" action that just takes the text from a textfield called "import" and swaps the entire options listing it in the database using $wpdb.
if ( $_POST['action'] == 'import' ) {
global $wpdb;
$wpdb->query( 'UPDATE wp_options SET option_value = '.json_encode($_POST['theme_import']).' WHERE option_name = "theme_options"' );
}
Everything works smoothly in that the imported json encoded text replaces the theme options in the database... but then if I refresh the page the theme options attempt to save over again as if they're doing a reset or something? And they don't even write over all the settings, the new ones just get appended to the front end of the data. To illustrate...
Before I import new options... theme_options = DEFAULT_OPTIONS After I import new options (but do not refresh the page)... theme_options = NEW_OPTIONS After I refresh the page .... theme_options = DEFAULT OPTIONS + NEW_OPTIONS
I'm looking in the framework code to see where it is that it attempts to write to the database with each page load... but I can't find it. Any help?
Hey @jasonherndon, that is awesome!
What version are you using? In the latest ones in v1.9.x I've removed that auto-saving thing.
Previously, TF checks the database for any changes then updates the entries.. this saves the default values and was meant for handling newly added options or for first time plugin/theme installations. That has been removed since it was causing doubling problems and from what I can gather it can also affect what you are doing now.
That must be it! I was using an older version. I'll update it tonight and give it a shot then. If it works I'll actually fork it and submit it as a pull request. I'm working on it for a client, so I'm sort of in the "let's just get it done" mode, I'm sure that there might be ways you see that it could be changed to better suit your framework/users but at least the basic functionality will be there for you in the PR so you can do with it what you'd like.
Let me know :+1:
Here's my idea on how the export import can be implemented #278