[theme-reviewers] Themes are required to save options in a single array
otto at ottodestruct.com
Mon Feb 6 21:39:12 UTC 2012
Using the settings API with a single array of options settings, but
multiple pages, can be tricky. You just have to be clever about it.
The trick lies in the validation function.
It's important to remember that whatever the validation function
returns is what gets saved, overwriting whatever was there before. So
if you have two pages, settings from the other page won't be passed
into your validation function, so you have to load them instead.
So for your validation function, load your settings array from the
database. Validate the inputs, and use those to overwrite the values
in that array with the changed valid values. Then return the array.
This method will allow you to have multiple pages and one settings
array and not lose anything.
The *_theme_mod functions are harder to use with the Settings API, and
I don't recommend it at the mo'. That whole thing needs some code
On Mon, Feb 6, 2012 at 3:26 PM, Bruce Wampler <weavertheme at gmail.com> wrote:
> Using SAPI and more than one db option:
> This is a difficult question. In my own theme, I have found there are really
> serious issues with the Settings API when trying to track two sets of
> settings with more than a single HTML form - it tends to reset values back
> to false in a way I've never been able to figure out. I ended up
> settings groups, but wrapping all the settings in what is essentially is a
> single <form>, so all the settings are in one db entry. It was not easy to
> From recent discussions on this group, it looks like it would be worthwhile
> investigating using *_theme_mod functions to keep theme settings instead of
> the general settings. There was a link to an article by Otto on how to use
> the SAPI validation function differently to keep the SAPI features while
> using theme_mod instead.
> I haven't tried this yet, but think that perhaps the only one data base
> entry rules should eventually be replaced with use theme_mod instead - if it
> really can be compatible with SAPI.
> It should be fairly easy to add a check in the theme to provide an automatic
> conversion from the general settings to theme_mod.
> But this is not an easy thing - especially for themes with lots of settings.
> Bruce Wampler
> Weaver II theme
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
More information about the theme-reviewers