[wp-hackers] Options and caching

DD32 wordpress at dd32.id.au
Wed Jan 30 10:26:18 GMT 2008

This code works fine for me(While yours did too)

if ( false === get_option("myoption") ){
	var_dump(get_option("myoption")); //false
var_dump(get_option("myoption")); //defaultvalue
delete_option("myoption");//cleanup for next test run

I've got the Object cache enabled, Or, what is left of it in trunk.

I've looked through the functions and i cant see why it'd not work..
I suggest using add_option rather than update_option, as that reduces the ammount of code which is run(Which decreases the possibility of something going wrong).

Note: get_option() return boolean false when the option doesnt exist, PHP evaluates "" and false as the same thing (When using ==), so thats not likely to be a problem unless you try to store a empty string in that option.

On Wed, 30 Jan 2008 20:50:14 +1100, James Davis <james at freecharity.org.uk> wrote:

> Some users of a plugin I write aren't correctly retrieving option
> values. A little Googling suggests this may be related to caching of
> previous get_option() calls. I have a niggling feeling that I might be
> misusing the _option() calls in one way or another. What I'm doing on
> installation is...
> if (get_option("myoption")=="")
> 	update_option("myoption","defaultvalue");
> and later...
> get_option("myoption");
> returns "".
> Any ideas?
> James

More information about the wp-hackers mailing list