From 11ec50e45375a927e751d72ccc07400f478c3cdf Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 5 Mar 2015 19:13:25 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@31628 git-svn-id: http://core.svn.wordpress.org/trunk@31609 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/option.php | 14 +++++++++----- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/wp-includes/option.php b/wp-includes/option.php index 566c896331..2f548e6151 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -221,12 +221,15 @@ function wp_load_core_site_options( $site_id = null ) { * to set whether an option is autoloaded, then you need to use the add_option(). * * @since 1.0.0 + * @since 4.2.0 The `$autoload` parameter was added. * - * @param string $option Option name. Expected to not be SQL-escaped. - * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. + * @param string $option Option name. Expected to not be SQL-escaped. + * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. + * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. Accepts 'yes' or true to + * enable, 'no' or false to disable. Default is enabled. * @return bool False if value was not updated and true if value was updated. */ -function update_option( $option, $value ) { +function update_option( $option, $value, $autoload = 'yes' ) { global $wpdb; $option = trim($option); @@ -269,8 +272,9 @@ function update_option( $option, $value ) { return false; /** This filter is documented in wp-includes/option.php */ - if ( apply_filters( 'default_option_' . $option, false ) === $old_value ) - return add_option( $option, $value ); + if ( apply_filters( 'default_option_' . $option, false ) === $old_value ) { + return add_option( $option, $value, '', $autoload ); + } $serialized_value = maybe_serialize( $value ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 3a93866cf4..0ac69b6257 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31627'; +$wp_version = '4.2-alpha-31628'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.