Make WordPress Core


Ignore:
Timestamp:
03/05/2015 07:13:00 PM (10 years ago)
Author:
boonebgorges
Message:

Introduce $autoload parameter to update_option().

When creating an option via add_option(), the $autoload param allows you to
tell WP whether the option should be loaded as part of the 'alloptions' cache
during every pageload. update_option(), when used with a non-existent option
calls add_option() internally. The new $autoload param in update_option()
is passed along to add_option() in cases where the option does not yet exist.

The associated unit tests are skipped on multisite due to an issue that causes
WP_INSTALLING to force cache misses. See #31130.

Props codix, nofearinc, MikeHansenMe.
Fixes #26394.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r31473 r31628  
    222222 *
    223223 * @since 1.0.0
    224  *
    225  * @param string $option Option name. Expected to not be SQL-escaped.
    226  * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
     224 * @since 4.2.0 The `$autoload` parameter was added.
     225 *
     226 * @param string      $option   Option name. Expected to not be SQL-escaped.
     227 * @param mixed       $value    Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
     228 * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. Accepts 'yes' or true to
     229 *                              enable, 'no' or false to disable. Default is enabled.
    227230 * @return bool False if value was not updated and true if value was updated.
    228231 */
    229 function update_option( $option, $value ) {
     232function update_option( $option, $value, $autoload = 'yes' ) {
    230233    global $wpdb;
    231234
     
    270273
    271274    /** This filter is documented in wp-includes/option.php */
    272     if ( apply_filters( 'default_option_' . $option, false ) === $old_value )
    273         return add_option( $option, $value );
     275    if ( apply_filters( 'default_option_' . $option, false ) === $old_value ) {
     276        return add_option( $option, $value, '', $autoload );
     277    }
    274278
    275279    $serialized_value = maybe_serialize( $value );
Note: See TracChangeset for help on using the changeset viewer.