You appear to be a bot. Output may be restricted
Description
Return option from the options table and cache result.
Applies genesis_pre_get_option_$key
and genesis_options
filters.
Values pulled from the database are cached on each request, so a second request for the same value won't cause a second DB interaction.
Usage
$mixed = genesis_get_option( $key, $setting, $use_cache );
Parameters
- $key
- ( string ) required – Option name.
- $setting
- ( string ) optional – Optional. Settings field name. Eventually defaults to
GENESIS_SETTINGS_FIELD
if not passed as an argument. - $use_cache
- ( bool ) optional default: 1 – Optional. Whether to use the Genesis cache value or not. Default is true.
Returns
mixed The value of the $key
in the database, or the return from genesis_pre_get_option_{$key}
short circuit filter if not `null`.
Source
File name: genesis/lib/functions/options.php
Lines:
1 to 60 of 60
function genesis_get_option( $key, $setting = null, $use_cache = true ) { // The default is set here, so it doesn't have to be repeated in the function arguments for genesis_option() too. $setting = $setting ?: GENESIS_SETTINGS_FIELD; // Allow child theme to short circuit this function. $pre = apply_filters( "genesis_pre_get_option_{$key}", null, $setting ); if ( null !== $pre ) { return $pre; } // Bypass cache if viewing site in Customizer. if ( genesis_is_customizer() ) { $use_cache = false; } // If we need to bypass the cache. if ( ! $use_cache ) { $options = get_option( $setting ); if ( ! is_array( $options ) || ! array_key_exists( $key, $options ) ) { return ''; } return is_array( $options[ $key ] ) ? $options[ $key ] : wp_kses_decode_entities( $options[ $key ] ); } // Setup caches. static $settings_cache = []; static $options_cache = []; // Check options cache. if ( isset( $options_cache[ $setting ][ $key ] ) ) { // Option has been cached. return $options_cache[ $setting ][ $key ]; } // Check settings cache. if ( isset( $settings_cache[ $setting ] ) ) { // Setting has been cached. $options = apply_filters( 'genesis_options', $settings_cache[ $setting ], $setting ); } else { // Set value and cache setting. $settings_cache[ $setting ] = apply_filters( 'genesis_options', get_option( $setting ), $setting ); $options = $settings_cache[ $setting ]; } // Check for non-existent option. if ( ! is_array( $options ) || ! array_key_exists( $key, (array) $options ) ) { // Cache non-existent option. $options_cache[ $setting ][ $key ] = ''; } else { // Option has not previously been cached, so cache now. $options_cache[ $setting ][ $key ] = is_array( $options[ $key ] ) ? $options[ $key ] : wp_kses_decode_entities( $options[ $key ] ); } return $options_cache[ $setting ][ $key ]; }