wppaste
WordPress

update_option( string $option, mixed $value, bool|null $autoload = null ): bool

Since
1.0.0, 4.2.0, 6.7.0
Source
wp-includes/option.php:844

Save a setting to the options table with update_option(), which serializes non-scalar values and creates the option if it does not exist yet. It returns true only when the stored value actually changed. The third $autoload argument controls whether the option loads on every request; pass false for data only a few admin screens read.

Updates the value of an option that was already added.

Description

You do not need to serialize values. If the value needs to be serialized, then it will be serialized before it is inserted into the database.
Remember, resources cannot be serialized or added as an option.

If the option does not exist, it will be created.

This function is designed to work with or without a logged-in user. In terms of security, plugin developers should check the current user's capabilities before updating any options.

Compatibility

WordPress
since 6.7.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 update. Expected to not be SQL-escaped.
$valuemixed
Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
$autoloadbool|nulloptional
Whether to load the option when WordPress starts up.
Accepts a boolean, or null to stick with the initial value or, if no initial value is set, to leave the decision up to default heuristics in WordPress.
For existing options, $autoload can only be updated using update_option() if $value is also changed.
For backward compatibility 'yes' and 'no' are also accepted, though using these values is deprecated.
Autoloading too many options can lead to performance problems, especially if the options are not frequently used. For options which are accessed across several places in the frontend, it is recommended to autoload them, by using true.
For options which are accessed only on few specific URLs, it is recommended to not autoload them, by using false.
For non-existent options, the default is null, which means WordPress will determine the autoload value.Default: null

Return value

bool
True if the value was updated, false otherwise.

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.

Save a plugin settings array

Options hold arrays directly, so a plugin's whole settings screen can live under one key.

$settings = get_option( 'wppaste_settings', array() );

$settings['accent_color'] = sanitize_hex_color( '#0055aa' );
$settings['show_promo']   = true;

update_option( 'wppaste_settings', $settings );

print_r( get_option( 'wppaste_settings' ) );

update_option() creates the option when it does not exist, so add_option() is rarely needed.

Store rarely-read data without autoloading it

Autoloaded options are fetched on every single request, so anything read on one screen should opt out.

$log   = get_option( 'wppaste_import_log', array() );
$log[] = array( 'time' => current_time( 'mysql' ), 'result' => 'ok' );

// false: never autoload, this is read on one admin screen only.
update_option( 'wppaste_import_log', $log, false );

echo 'rows stored: ', count( get_option( 'wppaste_import_log' ) ), "\n";
echo 'autoloaded:  ', isset( wp_load_alloptions()['wppaste_import_log'] ) ? 'yes' : 'no';

The autoload flag is only applied when the option is first created, not on later updates.

Performance profile

How much work a call to update_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_var().

Scaling
Constant

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

Instructions
9–171

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

Plugin surface
6 hooks

Third-party callbacks on 'pre_update_option_{$option}', 'pre_update_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 writeupdate_option()this function does it
  • hookthird-party callbacksapply_filters()called directly
  • serializeserialisationmaybe_serialize()called directly
  • cacheobject cachewp_cache_get()called directly
  • sqldatabase query->get_var()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 · 74 distinct outcomes

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

WhenInstructionsCalls it makes
empty($option)9–11none
!empty($option) && isset([…][$option]) && !wp_installing()36–38wp_installing(), __(), sprintf(), _deprecated_argument(), update_option()
!empty($option) && !isset([…][$option]) && $value === false43–47wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters()
!empty($option) && isset([…][$option]) && wp_installing() && $value === false46–50wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters()
!empty($option) && !isset([…][$option]) && $value !== false51–55wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false54–58wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value === false66–70wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), add_option()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value === false69–73wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), add_option()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null92–96wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value !== false && $autoload !== null95–99wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload97–101wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload100–104wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name()
62 further outcomes, up to 171 instructions
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload106–112wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value !== false && $autoload === null && $raw_autoload109–115wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && wp_installing()115–121wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), do_action(), do_action()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value !== false && $autoload !== null118–124wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && wp_installing()120–126wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option]) && wp_installing()123–127wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), do_action(), do_action()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload123–129wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), do_action(), do_action()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option])126–130wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && wp_installing()128–132wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && wp_installing()129–137wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && !wp_installing() && !isset($update_args)129–137wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option])131–135wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), do_action(), do_action()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value !== false && $autoload === null && $raw_autoload132–140wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && !isset($update_args)132–140wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && !wp_installing() && !isset($update_args)134–142wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && !wp_installing() && isset($update_args) && !isset($alloptions[$option])134–140wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && wp_installing()137–143wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && !isset($update_args)137–143wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && !isset($update_args)137–145wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && isset($update_args) && !isset($alloptions[$option])137–143wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && !wp_installing() && isset($update_args) && !isset($alloptions[$option])139–145wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && !wp_installing() && isset($update_args)139–145wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && !wp_installing() && isset($update_args) && isset($alloptions[$option])140–146wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && wp_installing() && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option])140–146wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option]) && !isset($update_args)140–146wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && !isset($update_args)142–148wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && isset($update_args) && !isset($alloptions[$option])142–146wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && isset($update_args) && !isset($alloptions[$option])142–148wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && isset($update_args)142–148wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && !wp_installing() && !isset($update_args)143–153wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && isset($update_args) && isset($alloptions[$option])143–149wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && !wp_installing() && isset($update_args)144–150wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && !wp_installing() && isset($update_args) && isset($alloptions[$option])145–151wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !isset($update_args)145–151wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option]) && isset($update_args) && !isset($alloptions[$option])145–149wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && !isset($update_args)146–156wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && isset($update_args) && !isset($alloptions[$option])147–151wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && isset($update_args)147–151wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && isset($update_args)147–153wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && !wp_installing() && isset($update_args) && !isset($alloptions[$option])148–156wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && isset($update_args) && isset($alloptions[$option])148–152wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && isset($update_args) && isset($alloptions[$option])148–154wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && isset($update_args) && !isset($alloptions[$option])150–154wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option]) && isset($update_args)150–154wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && !isset($update_args)151–159wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && isset($update_args) && !isset($alloptions[$option])151–159wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload !== null && is_array($notoptions) && isset($notoptions[$option]) && isset($update_args) && isset($alloptions[$option])151–155wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && isset($update_args)152–156wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && isset($update_args) && isset($alloptions[$option])153–157wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && !wp_installing() && isset($update_args)153–161wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && !wp_installing() && isset($update_args) && isset($alloptions[$option])154–162wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !isset($update_args)154–162wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && isset($update_args)155–159wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && isset($update_args) && !isset($alloptions[$option])156–162wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && !$raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && isset($update_args) && isset($alloptions[$option])156–160wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && isset($update_args)156–164wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && isset($update_args) && isset($alloptions[$option])157–165wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && isset($update_args) && !isset($alloptions[$option])159–165wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && isset($update_args)161–167wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && !isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && !wp_installing() && isset($update_args) && isset($alloptions[$option])162–168wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && isset($update_args)164–170wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_cache_delete(), wp_load_alloptions(), wp_cache_set(), do_action(), do_action()
!empty($option) && isset([…][$option]) && $value !== false && $old_value !== false && $autoload === null && $raw_autoload && is_array($notoptions) && isset($notoptions[$option]) && isset($update_args) && isset($alloptions[$option])165–171wp_installing(), wp_protect_special_option(), sanitize_option(), get_option(), apply_filters(), apply_filters(), maybe_serialize(), maybe_serialize(), apply_filters(), maybe_serialize(), do_action(), ->prepare(), ->get_var(), wp_determine_option_autoload_value(), option_name(), wp_cache_get(), wp_cache_set(), wp_installing(), wp_autoload_values_to_autoload(), wp_load_alloptions(), wp_cache_set(), wp_cache_set(), do_action(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev2489–17119
8.52489–17119
8.42489–171195 fewer instructions than PHP 8.3
8.32539–17619
8.22539–17619
8.12539–176192 fewer instructions than PHP 7.4
7.425511–17819

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 update_option() runs, in this order:

  1. apply_filters( pre_update_option_{$option} )filterline 899 (+55 into the body)

    Filters a specific option before its value is (maybe) serialized and updated.

  2. apply_filters( pre_update_option )filterline 910 (+66 into the body)

    Filters an option before its value is (maybe) serialized and updated.

  3. apply_filters( default_option_{$option} )filterline 926 (+82 into the body)

    Filters the default value for an option.

  4. do_action( update_option )actionline 941 (+97 into the body)

    Fires immediately before an option value is updated.

  5. do_action( update_option_{$option} )actionline 1017 (+173 into the body)

    Fires after the value of a specific option has been successfully updated.

  6. do_action( updated_option )actionline 1028 (+184 into the body)

    Fires after the value of an option has been successfully updated.

Uses · 17

Show all 17

Used by · 50

Show all 50

Source code

function update_option( $option, $value, $autoload = null ) {	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 update_option( $deprecated_keys[ $option ], $value, $autoload );	} 	wp_protect_special_option( $option ); 	if ( is_object( $value ) ) {		$value = clone $value;	} 	$value     = sanitize_option( $option, $value );	$old_value = get_option( $option ); 	/**	 * Filters a specific option before its value is (maybe) serialized and updated.	 *	 * The dynamic portion of the hook name, `$option`, refers to the option name.	 *	 * @since 2.6.0	 * @since 4.4.0 The `$option` parameter was added.	 *	 * @param mixed  $value     The new, unserialized option value.	 * @param mixed  $old_value The old option value.	 * @param string $option    Option name.	 */	$value = apply_filters( "pre_update_option_{$option}", $value, $old_value, $option ); 	/**	 * Filters an option before its value is (maybe) serialized and updated.	 *	 * @since 3.9.0	 *	 * @param mixed  $value     The new, unserialized option value.	 * @param string $option    Name of the option.	 * @param mixed  $old_value The old option value.	 */	$value = apply_filters( 'pre_update_option', $value, $option, $old_value ); 	/*	 * If the new and old values are the same, no need to update.	 *	 * Unserialized values will be adequate in most cases. If the unserialized	 * data differs, the (maybe) serialized data is checked to avoid	 * unnecessary database calls for otherwise identical object instances.	 *	 * See https://core.trac.wordpress.org/ticket/38903	 */	if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {		return false;	}

Changelog

Introduced in 1.0.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.

6.7.0
The autoload values 'yes' and 'no' are deprecated.from the docblock
4.2.0
The $autoload parameter was added.from the docblock
1.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.