Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
You should be able to achieve this by switching to another theme and then switching back.
It just doesn’t work…
And i don’t think this is a good way.
Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
What have your theme’s vendors said about this?
I’m creating my own theme and this offers plenty of options, everything is great but can’t find any way to reset all options.
Is there any way to add a global reset button?
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
To delete your option use the delete_option()
function. More explanation below. 😉
If it’s your own theme then I believe you should be saving your option changes via
http://codex.wordpress.org/Function_Reference/update_option
which you can read via
http://codex.wordpress.org/Function_Reference/get_option
And if you want to delete your option
http://codex.wordpress.org/Function_Reference/delete_option
Have the default settings in your code. That way you test if the option does not exist rather than needlessly creating an option you just check if the option is set. If it’s not then use the defaults.
There’s some really good theme documentation available but I am behind in my reading. I alway find the wrong ones so I’m going to see if this works:
*Paging Chip Bennett! Obligatory Child Theme reference here!*
Inside joke and if I find those links I’ll post them here. 😉
Thank you very much, but my question is about the Theme Customization API
To the best of my knowledge there is no global reset. I have to ask what way are you registering your settings? Default way which is handled by using: theme_mod
or options API? If you are using theme_mod
one way I can think of would be creating a reset settings button.
So it would be something like:
// Removes all theme mods
remove_theme_mods();
// If we haven't already declared them, declare some default settings
$defaults = array(
'links' => 'ddd',
'link_hover' => 'aaa',
'headers' => 'fadccd'
);
// Re-create all the default settings.
foreach ($defaults as $key => $value) {
$wp_customize->add_setting( $key , array( 'default' => $value ) );
}
Keep in mind that is the default way that WordPress handles that and you could potentially use the options API by adding 'type' => 'option'
to the array.