[wp-testers] **OT** Variable definitions in functions.php

Paul Robinson pablorobinson at gmail.com
Mon Mar 22 11:21:49 UTC 2010


No I'm letting the options function take care of storing the array for me.
;)

That's a great idea. I never even considered wrapping it in a function like
that. You officially rock, you've just saved me a lot of heartache with a
client. :)

Another quick question though, how come the overhead on get_option is so
small, doesn't it access the db each time it's called?

On 22 March 2010 10:16, Dion Hulse (dd32) <wordpress at dd32.id.au> wrote:

> Your best bet would be to use a function call.
>
> Ie.
>
> if ( my_theme_option('Something') ) {
> //Do something
> }
>
> in functions.php:
>
> function my_theme_option($option) {
> $options = get_option('my_theme_options');
>
> return isset($options[$option]) ? $options[$option] : false;
> }
>
> Do not be afraid of multiple calls to get_option, the overhead is small.
>
> Also, You shouldnt be doing any form of serialization yourself, the options
> API will take care of storing the array/object. (Not sure if you are doing
> that or not)
>
>
> On Mon, 22 Mar 2010 23:11:20 +1200, Paul Robinson <pablorobinson at gmail.com>
> wrote:
>
>  Hi guys,
>>
>> I know I probably shouldn't post this here, but I tried on the forum &
>> although I got an answer to my original question, no one seems to want to
>> help with the problem it's caused.
>>
>> I'm developing a theme in 3.0 & being newish a theme dev have only just
>> realized that variables defined in functions.php cannot be accessed in all
>> template files like functions can. I store the options for my theme in as
>> a
>> serialized array in the options db & want to make all the options
>> available
>> to the entire theme easily. Has anyone done this or know of an easy way to
>> do it? Or is the only way to define it in funcitons.php and keep
>> globalizing
>> the variable at the top of each theme file?
>>
>> Again sorry for this being off topic, but no one in the forum seems to be
>> able to help.
>>
>> Paul.
>> _______________________________________________
>> wp-testers mailing list
>> wp-testers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-testers
>>
>>
>
> --
> Dion Hulse / dd32
> Contact:
>  e: contact at dd32.id.au
>  Web: http://dd32.id.au/
> _______________________________________________
> wp-testers mailing list
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers
>


More information about the wp-testers mailing list