mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-22 07:22:01 +01:00
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
This commit is contained in:
parent
cd49531b14
commit
11ec50e453
@ -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 );
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user