I have added a theme options panel for my theme. I store the options in an array and serialize it when I store them with update_option().
When the theme options panel is submitted I call a function to validate and call update_option().
Then I call get_option(), and unserialize() to retrieve the new options. Unfortunately, get_option() sometimes fails, not returning a string.
Is there something that I can do to prevent these failures?
This is a sort of pseudo code version of my code:
function themeoptions_retrieve() {
return unserialize(get_option('themeoptions')); // This can fail!
}
function themeoptions_save($theme_options) {
update_option('themeoptions', $theme_options);
}
// This function added by add_theme_page() and add_action().
function themeoptions_page() {
if ($_POST['save']) { themeoptions_update(); }
$theme_options = themeoptions_retrieve();
// Display theme options page.
}
function themeoptions_update() {
$theme_options = themeoptions_retrieve();
// Snip - validate $_POST data and update $theme_options array.
themeoptions_save($theme_options);
}