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.
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:
- When the option has not been saved in the database, the
$default_valuevalue is returned if provided. If not, booleanfalseis returned. - 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.
- 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:
falsereturnsstring(0) ""truereturnsstring(1) "1"0returnsstring(1) "0"1returnsstring(1) "1"'0'returnsstring(1) "0"'1'returnsstring(1) "1"nullreturnsstring(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, booleanfalseis 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
- Scaling
- Constant
- Instructions
- 8–107
- Plugin surface
- 4 hooks
- Called by
- 50
Reaches the database via ->get_row().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 190.
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.
50 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()this function does it - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()called directly - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
empty($option) | 8–10 | none |
!empty($option) && !isset([…][$option]) | 28–32 | apply_filters(), apply_filters() |
!empty($option) && isset([…][$option]) && wp_installing() | 31–35 | wp_installing(), apply_filters(), apply_filters() |
!empty($option) && isset([…][$option]) && !wp_installing() | 34–36 | wp_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–51 | apply_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–54 | wp_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]) && !$option | 55–59 | 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]) && is_array($notoptions) && isset($notoptions[$option]) | 56–58 | apply_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]) && !$option | 58–62 | wp_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]) && $option | 59–63 | apply_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–61 | wp_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–64 | apply_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–64 | 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]) && $option | 62–66 | wp_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–65 | apply_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–66 | 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') && !isset($alloptions[$option]) && !is_array($notoptions) && isset($notoptions[$option]) | 65–67 | wp_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–67 | wp_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–68 | wp_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–69 | wp_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 && !$option | 69–73 | 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') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option === "home" && $value === "" | 69–71 | 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() && is_object($row) && !$option | 70–74 | 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') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && !$option | 72–76 | wp_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–74 | wp_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 && $option | 73–77 | 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) && !$option | 73–77 | wp_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) && $option | 74–78 | 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') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && !$option | 75–79 | 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') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option | 76–80 | wp_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) && $option | 77–81 | wp_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 && !$option | 78–82 | wp_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 && $option | 79–83 | 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') && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value !== false && $option | 82–86 | wp_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–86 | 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') && !wp_installing() && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option === "home" && $value === "" | 84–86 | 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') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && !is_object($row) | 87–89 | wp_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–89 | wp_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) && !$option | 90–94 | 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') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && !is_object($row) | 90–92 | 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') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option === "home" && $value === "" | 90–92 | 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') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && !$option | 93–97 | wp_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–95 | wp_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–95 | wp_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) && $option | 94–98 | 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') && !wp_installing() && !isset($alloptions[$option]) && !is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && !$option | 96–100 | 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') && !isset($alloptions[$option]) && is_array($notoptions) && !isset($notoptions[$option]) && $value === false && is_object($row) && $option | 97–101 | wp_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) && !$option | 99–103 | wp_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) && $option | 100–104 | 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() |
!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 | 103–107 | wp_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 190 | 8–107 | 16 | |
| 8.5 | 190 | 8–107 | 16 | |
| 8.4 | 190 | 8–107 | 16 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 192 | 8–109 | 16 | |
| 8.2 | 192 | 8–109 | 16 | |
| 8.1 | 192 | 8–109 | 16 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 194 | 10–111 | 16 |
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:
- apply_filters( pre_option_{$option} )filterline 132 (+54 into the body)
Filters the value of an existing option before it is retrieved.
- apply_filters( pre_option )filterline 150 (+72 into the body)
Filters the value of any existing option before it is retrieved.
- apply_filters( default_option_{$option} )filterline 199 (+121 into the body)
Filters the default value for an option.
- apply_filters( default_option_{$option} )filterline 217 (+139 into the body)
Filters the default value for an option.
- apply_filters( default_option_{$option} )filterline 230 (+152 into the body)
Filters the default value for an option.
- apply_filters( option_{$option} )filterline 256 (+178 into the body)
Filters the value of an existing option.
Uses · 11
- wp_installing()Checks or sets whether WordPress is in "installation" mode.
- _deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
- __()Retrieves the translation of $text.
- get_option()Retrieves an option value based on an option name.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_load_alloptions()Loads and caches all autoloaded options, if available or all options.
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- wp_cache_set()Saves the data to the cache.
- wp_cache_add()Adds data to the cache, if the cache key doesn't already exist.
- untrailingslashit()Removes trailing forward slashes and backslashes if they exist.
- maybe_unserialize()Unserializes data only if it was serialized.
Used by · 50
- Custom_Background::handle_upload()Handles an Image upload for the background image.
- Custom_Background::wp_set_background_image()
- Featured_Content::get_setting()Gets featured content settings.
- Featured_Content::get_sticky_posts()Returns an array with IDs of posts marked as sticky.
- Featured_Content::pre_get_posts()Excludes featured posts from the home page blog query.
- IXR_Server::output()
- Plugin_Upgrader::bulk_upgrade()Upgrades several plugins at once.
- Plugin_Upgrader::upgrade()Upgrades a plugin.
- Theme_Installer_Skin::after()Performs an action following a single theme install.
- Theme_Upgrader::bulk_upgrade()Upgrades several themes at once.
- Theme_Upgrader::upgrade()Upgrades a theme.
- TwentyTwenty_Walker_Page::start_el()Outputs the beginning of the current element in the tree.
Show all 50
- Twenty_Eleven_Ephemera_Widget::widget()Outputs the HTML for this widget.
- Twenty_Fourteen_Ephemera_Widget::widget()Outputs the HTML for this widget.
- WP::send_headers()Sends additional HTTP headers for caching, content type, etc.
- WP_Ajax_Response::send()Display XML formatted responses.
- WP_Automatic_Updater::send_email()Sends an email upon the completion or failure of a background core update.
- WP_Automatic_Updater::send_plugin_theme_email()Sends an email upon the completion or failure of a plugin or theme background update.
- WP_Comments_List_Table::__construct()Constructor.
- WP_Community_Events::format_event_data_time()Adds formatted date and time items for each event in an API response.
- WP_Customize_Date_Time_Control::content_template()Renders a JS template for the content of date time control.
- WP_Customize_Date_Time_Control::get_timezone_info()Get timezone info.
- WP_Customize_Manager::customize_pane_settings()Prints JavaScript settings for parent window.
- WP_Customize_Manager::get_lock_user_data()Gets lock user data.
- WP_Customize_Manager::import_theme_starter_content()Imports theme starter content into the customized state.
- WP_Customize_Manager::register_controls()Registers some default controls.
- WP_Customize_Manager::setup_theme()Starts preview and customize theme.
- WP_Customize_Manager::unsanitized_post_values()Gets dirty pre-sanitized setting values in the current customized state.
- WP_Customize_Manager::update_stashed_theme_mod_settings()Updates stashed theme mod settings.
- WP_Customize_Nav_Menu_Setting::update()Create/update the nav_menu term for this setting.
- WP_Customize_Nav_Menu_Setting::value()Get the instance data for a given widget setting.
- WP_Customize_Nav_Menus::customize_register()Adds the customizer settings and controls.
- WP_Customize_Nav_Menus::load_available_items_query()Performs the post_type and taxonomy queries for loading available menu items.
- WP_Customize_Nav_Menus::search_available_items_query()Performs post queries for available-item searching.
- WP_Customize_Setting::get_root_value()Get the root value for a setting, especially for multidimensional ones.
- WP_Customize_Widgets::preview_sidebars_widgets()When previewing, ensures the proper previewing widgets are used.
- WP_Debug_Data::get_wp_core()Gets the WordPress core section of the debug data.
- WP_HTTP_Proxy::send_through_proxy()Determines whether the request should be sent through a proxy.
- WP_Http::block_request()Determines whether an HTTP API request to the given URL should be blocked.
- WP_MS_Sites_List_Table::column_blogname()Handles the site name column output.
- WP_MS_Themes_List_Table::column_name()Handles the name column output.
- WP_Media_List_Table::get_columns()
- WP_Paused_Extensions_Storage::delete()Forgets a previously recorded extension error.
- WP_Paused_Extensions_Storage::delete_all()Remove all paused extensions.
- WP_Paused_Extensions_Storage::get_all()Gets the paused extensions with their errors.
- WP_Paused_Extensions_Storage::set()Records an extension error.
- WP_Plugins_List_Table::prepare_items()Prepares the list of items for displaying.
- WP_Post_Type::add_rewrite_rules()Adds the necessary rewrite rules for the post type.
- WP_Post_Type::set_props()Sets post type properties.
- WP_Posts_List_Table::__construct()Constructor.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.