Respect 'default_option_' filters during early sanity checks in `add_option()` and `update_option()`.

`add_option()` and `update_option()` both call `get_option()` to compare the
value passed to the function with any existing value for the given option name.
When a `'default_option_'` filter is in place to change the default value of
an option, `add_option()` and `update_option()` ought to check against the
filtered value, rather than a hardcoded `false`, in order to determine whether
a prior value exists.

Props GregLone, tyxla.
Fixes #31047.
Built from https://develop.svn.wordpress.org/trunk@31473


git-svn-id: http://core.svn.wordpress.org/trunk@31454 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-02-18 19:14:27 +00:00
parent 911f8d952a
commit ec8aef8233
2 changed files with 5 additions and 3 deletions

View File

@ -268,7 +268,8 @@ function update_option( $option, $value ) {
if ( $value === $old_value ) if ( $value === $old_value )
return false; return false;
if ( false === $old_value ) /** This filter is documented in wp-includes/option.php */
if ( apply_filters( 'default_option_' . $option, false ) === $old_value )
return add_option( $option, $value ); return add_option( $option, $value );
$serialized_value = maybe_serialize( $value ); $serialized_value = maybe_serialize( $value );
@ -370,7 +371,8 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' )
// Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query // 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' ); $notoptions = wp_cache_get( 'notoptions', 'options' );
if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) ) if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
if ( false !== get_option( $option ) ) /** This filter is documented in wp-includes/option.php */
if ( apply_filters( 'default_option_' . $option, false ) !== get_option( $option ) )
return false; return false;
$serialized_value = maybe_serialize( $value ); $serialized_value = maybe_serialize( $value );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.2-alpha-31472'; $wp_version = '4.2-alpha-31473';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.