: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Fires after the value of an option has been successfully updated.
* @param string $option Name of the updated option.
* @param mixed $old_value The old option value.
* @param mixed $value The new option value.
do_action( 'updated_option', $option, $old_value, $value );
* 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.
* You can create options without values and then update the values later.
* Existing options will not be updated and checks are performed to ensure that you
* aren't adding a protected WordPress option. Care should be taken to not name
* options the same as the ones which are protected.
* @since 6.6.0 The $autoload parameter's default value was changed to null.
* @global wpdb $wpdb WordPress database abstraction object.
* @param string $option Name of the option to add. Expected to not be SQL-escaped.
* @param mixed $value Optional. Option value. Must be serializable if non-scalar.
* Expected to not be SQL-escaped.
* @param string $deprecated Optional. Description. Not used anymore.
* @param bool|null $autoload Optional. Whether to load the option when WordPress starts up.
* Accepts a boolean, or `null` to leave the decision up to default heuristics in WordPress.
* For backward compatibility 'yes' and 'no' are also accepted.
* 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 'yes'|true.
* For options which are accessed only on few specific URLs, it is recommended
* to not autoload them, by using false.
* Default is null, which means WordPress will determine the autoload value.
* @return bool True if the option was added, false otherwise.
function add_option( $option, $value = '', $deprecated = '', $autoload = null ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '2.3.0' );
if ( is_scalar( $option ) ) {
$option = trim( $option );
if ( empty( $option ) ) {
* 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() ) {
/* translators: 1: Deprecated option key, 2: New option key. */
__( 'The "%1$s" option key has been renamed to "%2$s".' ),
$deprecated_keys[ $option ]
return add_option( $deprecated_keys[ $option ], $value, $deprecated, $autoload );
wp_protect_special_option( $option );
if ( is_object( $value ) ) {
$value = sanitize_option( $option, $value );
* Make sure the option doesn't already exist.
* We can check the 'notoptions' cache before we ask for a DB query.
$notoptions = wp_cache_get( 'notoptions', 'options' );
if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
/** This filter is documented in wp-includes/option.php */
if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) {
$serialized_value = maybe_serialize( $value );
$autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload );
* Fires before an option is added.
* @param string $option Name of the option to add.
* @param mixed $value Value of the option.
do_action( 'add_option', $option, $value );
$result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) );
if ( ! wp_installing() ) {
if ( in_array( $autoload, wp_autoload_values_to_autoload(), true ) ) {
$alloptions = wp_load_alloptions( true );
$alloptions[ $option ] = $serialized_value;
wp_cache_set( 'alloptions', $alloptions, 'options' );
wp_cache_set( $option, $serialized_value, 'options' );
// This option exists now.
$notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh.
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
unset( $notoptions[ $option ] );
wp_cache_set( 'notoptions', $notoptions, 'options' );
* Fires after a specific option has been added.
* The dynamic portion of the hook name, `$option`, refers to the option name.
* @since 2.5.0 As "add_option_{$name}"
* @param string $option Name of the option to add.
* @param mixed $value Value of the option.
do_action( "add_option_{$option}", $option, $value );
* Fires after an option has been added.
* @param string $option Name of the added option.
* @param mixed $value Value of the option.
do_action( 'added_option', $option, $value );
* Removes an option by name. Prevents removal of protected WordPress options.
* @global wpdb $wpdb WordPress database abstraction object.
* @param string $option Name of the option to delete. Expected to not be SQL-escaped.
* @return bool True if the option was deleted, false otherwise.
function delete_option( $option ) {
if ( is_scalar( $option ) ) {
$option = trim( $option );
if ( empty( $option ) ) {
wp_protect_special_option( $option );
// Get the ID, if no ID then return.
$row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) );
* Fires immediately before an option is deleted.
* @param string $option Name of the option to delete.
do_action( 'delete_option', $option );
$result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) );
if ( ! wp_installing() ) {
if ( in_array( $row->autoload, wp_autoload_values_to_autoload(), true ) ) {
$alloptions = wp_load_alloptions( true );
if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) {
unset( $alloptions[ $option ] );
wp_cache_set( 'alloptions', $alloptions, 'options' );
wp_cache_delete( $option, 'options' );
* Fires after a specific option has been deleted.
* The dynamic portion of the hook name, `$option`, refers to the option name.
* @param string $option Name of the deleted option.
do_action( "delete_option_{$option}", $option );
* Fires after an option has been deleted.
* @param string $option Name of the deleted option.
do_action( 'deleted_option', $option );
* Determines the appropriate autoload value for an option based on input.
* This function checks the provided autoload value and returns a standardized value
* ('on', 'off', 'auto-on', 'auto-off', or 'auto') based on specific conditions.
* If no explicit autoload value is provided, the function will check for certain heuristics around the given option.
* It will return `auto-on` to indicate autoloading, `auto-off` to indicate not autoloading, or `auto` if no clear
* decision could be made.
* @param string $option The name of the option.
* @param mixed $value The value of the option to check its autoload value.
* @param mixed $serialized_value The serialized value of the option to check its autoload value.
* @param bool|null $autoload The autoload value to check.
* Accepts 'on'|true to enable or 'off'|false to disable, or
* 'auto-on', 'auto-off', or 'auto' for internal purposes.
* Any other autoload value will be forced to either 'auto-on',
* 'yes' and 'no' are supported for backward compatibility.
* @return string Returns the original $autoload value if explicit, or 'auto-on', 'auto-off',
* or 'auto' depending on default heuristics.
function wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ) {
// Check if autoload is a boolean.
if ( is_bool( $autoload ) ) {
return $autoload ? 'on' : 'off';
* Allows to determine the default autoload value for an option where no explicit value is passed.
* @param bool|null $autoload The default autoload value to set. Returning true will be set as 'auto-on' in the
* database, false will be set as 'auto-off', and null will be set as 'auto'.
* @param string $option The passed option name.
* @param mixed $value The passed option value to be saved.
$autoload = apply_filters( 'wp_default_autoload_value', null, $option, $value, $serialized_value );
if ( is_bool( $autoload ) ) {
return $autoload ? 'auto-on' : 'auto-off';
* Filters the default autoload value to disable autoloading if the option value is too large.
* @param bool|null $autoload The default autoload value to set.
* @param string $option The passed option name.
* @param mixed $value The passed option value to be saved.
* @param mixed $serialized_value The passed option value to be saved, in serialized form.
* @return bool|null Potentially modified $default.
function wp_filter_default_autoload_value_via_option_size( $autoload, $option, $value, $serialized_value ) {
* Filters the maximum size of option value in bytes.
* @param int $max_option_size The option-size threshold, in bytes. Default 150000.
* @param string $option The name of the option.
$max_option_size = (int) apply_filters( 'wp_max_autoloaded_option_size', 150000, $option );
$size = ! empty( $serialized_value ) ? strlen( $serialized_value ) : 0;
if ( $size > $max_option_size ) {
* @param string $transient Transient name. Expected to not be SQL-escaped.
* @return bool True if the transient was deleted, false otherwise.
function delete_transient( $transient ) {
* Fires immediately before a specific transient is deleted.
* The dynamic portion of the hook name, `$transient`, refers to the transient name.
* @param string $transient Transient name.
do_action( "delete_transient_{$transient}", $transient );
if ( wp_using_ext_object_cache() || wp_installing() ) {
$result = wp_cache_delete( $transient, 'transient' );
$option_timeout = '_transient_timeout_' . $transient;
$option = '_transient_' . $transient;
$result = delete_option( $option );
delete_option( $option_timeout );
* Fires after a transient is deleted.
* @param string $transient Deleted transient name.
do_action( 'deleted_transient', $transient );
* Retrieves the value of a transient.
* If the transient does not exist, does not have a value, or has expired,
* then the return value will be false.
* @param string $transient Transient name. Expected to not be SQL-escaped.
* @return mixed Value of transient.
function get_transient( $transient ) {
* Filters the value of an existing transient before it is retrieved.
* The dynamic portion of the hook name, `$transient`, refers to the transient name.
* Returning a value other than false from the filter will short-circuit retrieval
* and return that value instead.
* @since 4.4.0 The `$transient` parameter was added
* @param mixed $pre_transient The default value to return if the transient does not exist.
* Any value other than false will short-circuit the retrieval
* of the transient, and return that value.
* @param string $transient Transient name.
$pre = apply_filters( "pre_transient_{$transient}", false, $transient );
if ( wp_using_ext_object_cache() || wp_installing() ) {
$value = wp_cache_get( $transient, 'transient' );
$transient_option = '_transient_' . $transient;
if ( ! wp_installing() ) {
// If option is not in alloptions, it is not autoloaded and thus has a timeout.
$alloptions = wp_load_alloptions();
if ( ! isset( $alloptions[ $transient_option ] ) ) {
$transient_timeout = '_transient_timeout_' . $transient;
wp_prime_option_caches( array( $transient_option, $transient_timeout ) );
$timeout = get_option( $transient_timeout );
if ( false !== $timeout && $timeout < time() ) {
delete_option( $transient_option );
delete_option( $transient_timeout );
if ( ! isset( $value ) ) {
$value = get_option( $transient_option );
* Filters an existing transient's value.
* The dynamic portion of the hook name, `$transient`, refers to the transient name.
* @since 4.4.0 The `$transient` parameter was added
* @param mixed $value Value of transient.
* @param string $transient Transient name.
return apply_filters( "transient_{$transient}", $value, $transient );
* Sets/updates the value of a transient.
* You do not need to serialize values. If the value needs to be serialized,
* then it will be serialized before it is set.
* @param string $transient Transient name. Expected to not be SQL-escaped.
* Must be 172 characters or fewer in length.
* @param mixed $value Transient value. Must be serializable if non-scalar.
* Expected to not be SQL-escaped.
* @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
* @return bool True if the value was set, false otherwise.
function set_transient( $transient, $value, $expiration = 0 ) {
$expiration = (int) $expiration;
* Filters a specific transient before its value is set.
* The dynamic portion of the hook name, `$transient`, refers to the transient name.
* @since 4.2.0 The `$expiration` parameter was added.
* @since 4.4.0 The `$transient` parameter was added.
* @param mixed $value New value of transient.
* @param int $expiration Time until expiration in seconds.
* @param string $transient Transient name.
$value = apply_filters( "pre_set_transient_{$transient}", $value, $expiration, $transient );
* Filters the expiration for a transient before its value is set.
* The dynamic portion of the hook name, `$transient`, refers to the transient name.