function ttw_initopts() { global $ttw_optionsList, $ttw_myoptionsList, $ttw_options, $ttw_adminOpts, $ttw_optionsListDefault; $settingsFound = false; // any options saved? /* first thing, make sure $ttw_optionsList and $ttw_myoptionsList are set to good default values */ $ttw_optionsList = $ttw_optionsListDefault; foreach ($ttw_options as $value) { ttw_defaultopt($value['id']); ttw_setmyopt($value['id'], ttw_getopt($value['id'])); } $opts = get_option('ttw_options'); if ($opts) { $settingsFound = true; $ttw_optionsList = unserialize($opts); } $myopts = get_option('ttw_myoptions'); if (!$myopts) { $ttw_myoptionsList = $ttw_optionsList; } else { $settingsFound = true; $ttw_myoptionsList = unserialize($myopts); } $aopts = get_option('ttw_adminoptions'); if ($aopts) { $settingsFound = true; $ttw_adminOpts = unserialize($aopts); } if ($end = ttw_getopt('ttw_end_opts')) { // old version set - 1.3 upgrade compatibility issue here... ttw_setadminopt('ttw_end_opts', $end); ttw_deleteopt('ttw_end_opts'); ttw_saveopts(); } }
function ttw_save_serialized_theme($contents) { global $ttw_optionsList; if (substr($contents, 0, 10) != "TTW-V01.10") { return ttw_file_fail("Wrong theme file version"); } /* simple check for one of ours */ $restore = array(); $restore = unserialize(substr($contents, 10)); if (!$restore) { return ttw_file_fail("Unserialize failed"); } foreach ($ttw_optionsList as $key => $val) { /* first, clear EVERYTHING in both current and mysaved */ ttw_deleteopt($key); ttw_deletemyopt($key); } st_set_to_defaults(); /* now restore defaults - saved will override changes */ /* now can set the new values from $restore */ foreach ($restore as $rkey => $rval) { if ($rval != '') { ttw_setopt($rkey, $rval); /* and set both sets of values */ ttw_setmyopt($rkey, $rval); } } ttw_setopt('ttw_subtheme', "My Saved Theme"); ttw_saveopts(); /* and write them to db! */ return true; }