WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Settings API - defaults and resets (7 posts)

  1. helgatheviking
    Member
    Posted 3 years ago #

    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.

    Thanks!

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    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).

  3. helgatheviking
    Member
    Posted 3 years ago #

    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.

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  5. helgatheviking
    Member
    Posted 3 years ago #

    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

    http://codex.wordpress.org/Settings_API

  6. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Perhaps this might help a bit?

    http://www.chipbennett.net/2011/02/17/incorporating-the-settings-api-in-wordpress-themes/

    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.

  7. helgatheviking
    Member
    Posted 3 years ago #

    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)

    http://wptheming.com/2011/02/options-framework-plugin/

Topic Closed

This topic has been closed to new replies.

About this Topic