wppaste
WordPress

get_option( string $option, mixed $default_value = false ): mixed

Since
1.5.0
Source
wp-includes/option.php:78

Read a saved setting from the options table with get_option(), which returns your $default_value, or false, when the option was never saved. Serialized arrays and objects come back with their original type, but scalar values stored in the database are returned as strings, so avoid strict comparisons against booleans or numbers.

Retrieves an option value based on an option name.

Description

If the option does not exist, and a default value is not provided, boolean false is returned. This could be used to check whether you need to initialize an option during installation of a plugin, however that can be done better by using add_option() which will not overwrite existing options.

Not initializing an option and using boolean false as a return value is a bad practice as it triggers an additional database query.

The type of the returned value can be different from the type that was passed when saving or updating the option. If the option value was serialized, then it will be unserialized when it is returned. In this case the type will be the same. For example, storing a non-scalar value like an array will return the same array.

In most cases non-string scalar and null values will be converted and returned as string equivalents.

Exceptions:

  1. When the option has not been saved in the database, the $default_value value is returned if provided. If not, boolean false is returned.
  2. When one of the Options API filters is used: 'preoption$option', 'defaultoption$option', or 'option_$option', the returned value may not match the expected type.
  3. When the option has just been saved in the database, and get_option() is used right after, non-string scalar and null values are not converted to string equivalents and the original type is returned.

Examples:

When adding options like this: add_option( 'my_option_name', 'value' ) and then retrieving them with get_option( 'my_option_name' ), the returned values will be:

  • false returns string(0) ""
  • true returns string(1) "1"
  • 0 returns string(1) "0"
  • 1 returns string(1) "1"
  • '0' returns string(1) "0"
  • '1' returns string(1) "1"
  • null returns string(0) ""

When adding options with non-scalar values like add_option( 'my_array', array( false, 'str', null ) ), the returned value will be identical to the original as it is serialized before saving it in the database:

array(3) {
 [0] => bool(false)
 [1] => string(3) "str"
 [2] => NULL
}

Compatibility

WordPress
since 1.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$optionstring
Name of the option to retrieve. Expected to not be SQL-escaped.
$default_valuemixedoptional
Default value to return if the option does not exist.Default: false

Return value

mixed
Value of the option. A value of any type may be returned, including scalar (string, boolean, float, integer), null, array, object.
Scalar and null values will be returned as strings as long as they originate from a database stored option value. If there is no option in the database, boolean false is returned.

Code examples

Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.

Read a plugin setting with a fallback

Fetch a settings array and supply a default so the code works before the option is ever saved.

$settings = get_option( 'myplugin_settings', array() );
$color    = $settings['accent_color'] ?? '#0055aa';

printf(
	'<div class="promo" style="--accent: %s">%s</div>',
	esc_attr( $color ),
	esc_html__( 'Sale on now', 'myplugin' )
);

A stored false and a missing option both come back as false unless you pass a distinct $default_value; use a sentinel default when you need to tell them apart.

Read core site options

Pull built-in settings such as the site title and posts-per-page count.

$site_name = get_option( 'blogname' );
$per_page  = (int) get_option( 'posts_per_page' );

printf(
	'<p>%s shows %d posts per page.</p>',
	esc_html( $site_name ),
	$per_page
);

Database-stored scalars are returned as strings ('1' for true, '0' for 0), so cast before doing arithmetic or strict comparisons; repeatedly reading an option that was never saved also costs an extra query, which add_option() with a default avoids.

Performance profile

How much work a call to get_option() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via ->get_row().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
8–107

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 190.

Plugin surface
4 hooks

Third-party callbacks on 'pre_option_{$option}', 'pre_option', 'default_option_{$option}' run inside this call, and their cost is not bounded by anything here.

Called by
50

50 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()this function does it
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()called directly
  • serializeserialisationmaybe_unserialize()called directly
  • sqldatabase query->get_row()called directly

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 50 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_option() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($option)8–10none
!empty($option) && !isset([…][$option])28–32apply_filters(), apply_filters()
!empty($option) && isset([…][$option]) && wp_installing()31–35wp_installing(), apply_filters(), apply_filters()
!empty($option) && isset([…][$option]) && !wp_installing()34–36wp_installing(), __(), sprintf(), _deprecated_argument(), get_option()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && isset($alloptions[$option]) && $option === "home" && $value === ""49–51apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), get_option()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && isset($alloptions[$option]) && $option === "home" && $value === ""52–54wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), get_option()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && isset($alloptions[$option]) && !$option55–59apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && is_array($notoptions) && isset($notoptions[$option])56–58apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && isset($alloptions[$option]) && !$option58–62wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && isset($alloptions[$option]) && $option59–63apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && is_array($notoptions) && isset($notoptions[$option])59–61wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && isset($notoptions[$option])62–64apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), apply_filters()
38 further outcomes, up to 107 instructions
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && wp_installing() && !is_object($row)62–64apply_filters(), apply_filters(), wp_installing(), ->suppress_errors(), ->prepare(), ->get_row(), ->suppress_errors(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && isset($alloptions[$option]) && $option62–66wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option === "home" && $value === ""63–65apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), get_option()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && wp_installing() && is_object($row) && $option === "home" && $value === ""64–66apply_filters(), apply_filters(), wp_installing(), ->suppress_errors(), ->prepare(), ->get_row(), ->suppress_errors(), get_option()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && !is_array($notoptions) && isset($notoptions[$option])65–67wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), apply_filters()
!empty($option) && isset([…][$option]) && wp_installing() && $pre === false && !defined('WP_SETUP_CONFIG') && !is_object($row)65–67wp_installing(), apply_filters(), apply_filters(), wp_installing(), ->suppress_errors(), ->prepare(), ->get_row(), ->suppress_errors(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option === "home" && $value === ""66–68wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), get_option()
!empty($option) && isset([…][$option]) && wp_installing() && $pre === false && !defined('WP_SETUP_CONFIG') && is_object($row) && $option === "home" && $value === ""67–69wp_installing(), apply_filters(), apply_filters(), wp_installing(), ->suppress_errors(), ->prepare(), ->get_row(), ->suppress_errors(), get_option()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && !$option69–73apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option === "home" && $value === ""69–71apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), get_option()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && wp_installing() && is_object($row) && !$option70–74apply_filters(), apply_filters(), wp_installing(), ->suppress_errors(), ->prepare(), ->get_row(), ->suppress_errors(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && !$option72–76wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option === "home" && $value === ""72–74wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), get_option()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option73–77apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && wp_installing() && $pre === false && !defined('WP_SETUP_CONFIG') && is_object($row) && !$option73–77wp_installing(), apply_filters(), apply_filters(), wp_installing(), ->suppress_errors(), ->prepare(), ->get_row(), ->suppress_errors(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && wp_installing() && is_object($row) && $option74–78apply_filters(), apply_filters(), wp_installing(), ->suppress_errors(), ->prepare(), ->get_row(), ->suppress_errors(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && !$option75–79apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option76–80wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && wp_installing() && $pre === false && !defined('WP_SETUP_CONFIG') && is_object($row) && $option77–81wp_installing(), apply_filters(), apply_filters(), wp_installing(), ->suppress_errors(), ->prepare(), ->get_row(), ->suppress_errors(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && !$option78–82wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option79–83apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option82–86wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && !is_object($row)84–86apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_set(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option === "home" && $value === ""84–86apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), get_option()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && !is_object($row)87–89wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_set(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option === "home" && $value === ""87–89wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), get_option()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && !$option90–94apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && !is_object($row)90–92apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_set(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option === "home" && $value === ""90–92apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), get_option()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && !$option93–97wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && !is_object($row)93–95wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_set(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option === "home" && $value === ""93–95wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), get_option()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option94–98apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && !$option96–100apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option97–101wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && !$option99–103wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), maybe_unserialize(), apply_filters()
!empty($option) && !isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option100–104apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), untrailingslashit(), maybe_unserialize(), apply_filters()
!empty($option) && isset([…][$option]) && $pre === false && !defined('WP_SETUP_CONFIG') && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option103–107wp_installing(), apply_filters(), apply_filters(), wp_installing(), wp_load_alloptions(), wp_cache_get(), wp_cache_set(), wp_cache_get(), ->prepare(), ->get_row(), wp_cache_add(), untrailingslashit(), maybe_unserialize(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1908–10716
8.51908–10716
8.41908–107162 fewer instructions than PHP 8.3
8.31928–10916
8.21928–10916
8.11928–109162 fewer instructions than PHP 7.4
7.419410–11116

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 6

6 hooks fire while get_option() runs, in this order:

  1. apply_filters( pre_option_{$option} )filterline 132 (+54 into the body)

    Filters the value of an existing option before it is retrieved.

  2. apply_filters( pre_option )filterline 150 (+72 into the body)

    Filters the value of any existing option before it is retrieved.

  3. apply_filters( default_option_{$option} )filterline 199 (+121 into the body)

    Filters the default value for an option.

  4. apply_filters( default_option_{$option} )filterline 217 (+139 into the body)

    Filters the default value for an option.

  5. apply_filters( default_option_{$option} )filterline 230 (+152 into the body)

    Filters the default value for an option.

  6. apply_filters( option_{$option} )filterline 256 (+178 into the body)

    Filters the value of an existing option.

Uses · 11

Used by · 50

Show all 50

Source code

function get_option( $option, $default_value = false ) {	global $wpdb; 	if ( is_scalar( $option ) ) {		$option = trim( $option );	} 	if ( empty( $option ) ) {		return false;	} 	/*	 * Until a proper _deprecated_option() function can be introduced,	 * redirect requests to deprecated keys to the new, correct ones.	 */	$deprecated_keys = array(		'blacklist_keys'    => 'disallowed_keys',		'comment_whitelist' => 'comment_previously_approved',	); 	if ( isset( $deprecated_keys[ $option ] ) && ! wp_installing() ) {		_deprecated_argument(			__FUNCTION__,			'5.5.0',			sprintf(				/* translators: 1: Deprecated option key, 2: New option key. */				__( 'The "%1$s" option key has been renamed to "%2$s".' ),				$option,				$deprecated_keys[ $option ]			)		);		return get_option( $deprecated_keys[ $option ], $default_value );	} 	/**	 * Filters the value of an existing option before it is retrieved.	 *	 * The dynamic portion of the hook name, `$option`, refers to the option name.	 *	 * Returning a value other than false from the filter will short-circuit retrieval	 * and return that value instead.	 *	 * @since 1.5.0	 * @since 4.4.0 The `$option` parameter was added.	 * @since 4.9.0 The `$default_value` parameter was added.	 *	 * @param mixed  $pre_option    The value to return instead of the option value. This differs from	 *                              `$default_value`, which is used as the fallback value in the event	 *                              the option doesn't exist elsewhere in get_option().	 *                              Default false (to skip past the short-circuit).	 * @param string $option        Option name.	 * @param mixed  $default_value The fallback value to return if the option does not exist.	 *                              Default false.	 */	$pre = apply_filters( "pre_option_{$option}", false, $option, $default_value ); 	/**	 * Filters the value of any existing option before it is retrieved.	 *	 * Returning a value other than false from the filter will short-circuit retrieval	 * and return that value instead.	 *	 * @since 6.1.0	 *	 * @param mixed  $pre_option    The value to return instead of the option value. This differs from	 *                              `$default_value`, which is used as the fallback value in the event	 *                              the option doesn't exist elsewhere in get_option().	 *                              Default false (to skip past the short-circuit).	 * @param string $option        Name of the option.	 * @param mixed  $default_value The fallback value to return if the option does not exist.	 *                              Default false.	 */	$pre = apply_filters( 'pre_option', $pre, $option, $default_value ); 	if ( false !== $pre ) {		return $pre;	} 	if ( defined( 'WP_SETUP_CONFIG' ) ) {		return false;

Changelog

Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/option.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.