I’m building an options panel with the Settings API. I have 2 questions
Is there a special settings API method for handling default option values?
Is there a way to reset the options and delete all the saved values? Unregister_setting() doesn’t seem right. Something like a delete_setting()? Of course, I could just use delete_option($name) since the API ultimately puts things in the options table anyway, but then I am probably missing the benefits of automatic security checks.
Is there a way to reset the options and delete all the saved values?
Not in a way that is safe for themes. You wouldn’t want to destroy all saved (custom) settings) when the theme is just deactivated and there’s no on_delete hook for themes (although I have high hopes that something will be added in due course).
thanks for the reply. i don’t want to delete on deactivation or anything, but i’d like to add a reset button to the theme options page. still no?
right now i am thinking that the reset button will trigger delete_option and then i can check for the existance of the option in determining whether i should display defaults or the saved options.
i’d like to add a reset button to the theme options page.
You could simply use such a button to save the defaults but you can’t run a delete via the Settings API for a theme – as far as I know.
funny that 2 months later i google the subject and come back to my own post.
from the codex’s section on the Settings API i don’t see anything that would handle reset or defaults… so i guess i will just stick with using update_option
Perhaps this might help a bit?
I give an example of how to reset defaults, but not for deleting options.
Deleting options is tricky, because you’d have to account for how the template files handle the absence of options values.
thanks! i don’t want/care to delete the options per sé. just reset back to default- which you said you wrote about. i will definitely check that out when i am a little fresher.
also Devin Price is coming up with a plugin that does a similar task. i’ve been following his options for about a year, and paralleling and contributing some ideas, but i think he’s drastically overhauled how he was doing things (modelling off of Woo’s Framework)
- The topic ‘Settings API – defaults and resets’ is closed to new replies.