[theme-reviewers] Themes are required to save options in a single array
Sayontan Sinha
sayontan at gmail.com
Mon Feb 6 21:39:10 UTC 2012
I have done this in my theme, where all options pages write to the same
array using the Settings API. However it is not a piece of code that I
would want to write from scratch again - it is just not worth the trouble.
You can take a look at Chip's tutorial on this topic. That does a very good
job of handling a fairly complex scenario. I have a comment on that post
that says how you can handle multiple options pages:
http://www.chipbennett.net/2011/02/17/incorporating-the-settings-api-in-wordpress-themes/comment-page-1/#comment-17260.
The problem is this: you have 2 forms and you are, at any point of time
submitting only one of them. So "Form 2" fields will be missing when you
are submitting "Form 1" and vice versa, which blanks out the options
pertaining to the form that is not being submitted. To tackle this, I made
use of the fact that I already know what my fields are in the back-end. If
I am getting the input for Form 1, I simply populate the registered setting
with all the option values corresponding to the fields in Form 2. That way
the array I am trying to save is always complete.
Sayontan.
On Mon, Feb 6, 2012 at 1: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
> restructuring my admin pages using a javascript show/hide script for
> 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
> do.
>
> 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
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>
--
Sayontan Sinha
http://mynethome.net | http://mynethome.net/blog
--
Beating Australia in Cricket is like killing a celebrity. The death gets
more coverage than the crime.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20120206/e0e80b2d/attachment.htm>
More information about the theme-reviewers
mailing list