[theme-reviewers] Note to theme reviewers about settingsinthemes
Otto
otto at ottodestruct.com
Sun Jun 12 22:18:43 UTC 2011
Yes, something like this works too:
$foo = get_option('whatever', 'bar');
$foo will = bar if there is no 'whatever' option. This doesn't work as
well for multi-option options though. If you have one of those, you
can do something like this:
$foo = get_option('theme_options',array()); // default = no options set
$foo = wp_parse_args($foo, array('option_name'=>'default_setting'));
// set the defaults in $foo if they're not already set
But realistically, if you're not using the Settings API, you shouldn't
be using direct options, the theme mods are better for this. Theme
mods have the advantage of being unique to the specific theme
installation.
-Otto
On Sun, Jun 12, 2011 at 5:08 PM, Philip M. Hofer (Frumph)
<philip at frumph.net> wrote:
> There are a ton of us that do not use get_theme_mod and probably never will;
> Myself included. s o if you could answer the other questions if
> get_option()'s second parameter is fired on false return that'd be great.
>
> - Phil
>
>
> -----Original Message----- From: Otto
> Sent: Sunday, June 12, 2011 3:04 PM
> To: theme-reviewers at lists.wordpress.org
> Subject: Re: [theme-reviewers] Note to theme reviewers about
> settingsinthemes
>
> Several ways to solve that, the easiest of which is simply to use an
> isset() before trying to use the variables.
>
> But basically, I just mean it's a bad idea to set defaults into the
> database, ever. This would be a better approach:
>
> $foo = get_theme_mod('my_setting','default_value');
>
> That gets you the default_value if my_setting isn't set.
>
> -Otto
>
>
>
> On Sun, Jun 12, 2011 at 4:57 PM, Emil Uzelac <emil at themeid.com> wrote:
>>
>> I see and understood. Thanks :)
>>
>> Weird thing about this is when defaults are not set and activated in Theme
>> Options, there are some bugs, i.e.
>> Other warnings: 2
>> -- Debug: Undefined index: home_subheadline on line 133 of
>> /wp-content/themes/shell/includes/theme-options.php
>> -- Debug: Undefined index: contact_email on line 238 of
>> /wp-content/themes/shell/includes/theme-options.php
>> And once "Save Options" they go away.
>> I am seeing this with Coraline as well. But when defaults are set this
>> "Undefined index" is not present.
>> Emil
>>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
More information about the theme-reviewers
mailing list