I am playing around with the autoload
column of the options
table. I didn’t find much information about how the autoloaded values are used. I tried a print_r($GLOBALS)
and saw that the autoloaded options are stored in $GLOBALS['wp_object_cache']->cache['options']['alloptions']
.
Is there another way to access those variables?
Suppose I need to access an option my_option
, which was set to autoload, multiple times in different templates (eg. once in header.php
, once in footer.php
), which method is recommended?
- Is it okay that I retrieve it from the
$GLOBALS
array(since the value is already here) - Must I use
get_option('my_option')
once and globalize the variable again - Use
get_option('my_option')
each time (which I don’t see the point of doing) - Something else
There is no special case for autoloaded options, they are used in the same way as else regular options, but lets figure out what
autoload
column of theoptions
table means. This column determines do we need to fetch an option at the initialization stage of a request or should we fetch an option only on demand.But when this autoloading happens and what function does it? All autoload options are loaded and cached by
wp_load_alloptions
function, which is called byis_blog_installed
function at the beginning of each HTTP request, handled by WP.Lets summarize: autoloaded option is the same option, but loaded at the beginning of HTTP request processing by WP.
$GLOBALS
directly, useget_option
insteadWhy to use
get_option
function each time is the best option? Because:option_optionname
filter.