[theme-reviewers] Theme Activation Hook

Chip Bennett chip at chipbennett.net
Thu Oct 24 17:28:25 UTC 2013


Interaction with the Theme previewer is one thing, and important. But I'm
primarily concerned with Theme interaction with users' databases.

Interaction with the Settings API is not in any way a hindrance to a Theme
using sane defaults without relying on options being saved explicitly to
the database. All that is required is the Theme defining its own defaults,
and using them in lieu of options in the database.

When you call your Theme options, just use the following:

function themeslug_get_options() {
        // Get the option defaults
        $option_defaults = themeslug_get_option_defaults();
        // Globalize the variable that holds the Theme options
        global $themeslug_options;
        // Parse the stored options with the defaults
        $themeslug_options = wp_parse_args( get_option(
'theme_themeslug_options', array() ), $option_defaults );
        // Return the parsed array
        return $themeslug_options;
}


Wrap your option defaults in a function that can be called. Parse the
defaults against the database. Return the results. Just call this wrapper
function instead of calling get_option() directly. Simple.


On Thu, Oct 24, 2013 at 1:14 PM, Bruce Wampler <weavertheme at gmail.com>wrote:

> I'm hearing two things here:
>
> 1. Theme Previewer must work without relying on any options set in the
> database - whether or not the theme has been activated or not previously.
>
> 2. Eventually, Chip doesn't want anything written to the database unless
> the user explicitly saves options, even if the theme has been activated.
>
> This is two different things, and at least for my themes, presents two
> very different issues. They show the default settings just fine in preview
> without any interaction with the database, and this makes perfect sense.
> But once a theme has been activated, it relies on being able to save the
> default settings as an option to display the options admin pages correctly.
>
> I would hope being able to Preview correctly is the critical issue here?
>
> The latter is a very difficult issue for my themes at least, partly
> because of their interaction with the WP Settings API. Hope I don't need to
> cross that bridge.
>
> Bruce Wampler
>
>
>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20131024/3947b195/attachment.html>


More information about the theme-reviewers mailing list