mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-04 22:57:20 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@31473 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -59,6 +59,30 @@ class Tests_Option_Option extends WP_UnitTestCase {
|
||||
$this->assertFalse( get_option( 'doesnotexist' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31047
|
||||
*/
|
||||
public function test_add_option_should_respect_default_option_filter() {
|
||||
add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
|
||||
$added = add_option( 'doesnotexist', 'bar' );
|
||||
remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
|
||||
|
||||
$this->assertTrue( $added );
|
||||
$this->assertSame( 'bar', get_option( 'doesnotexist' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31047
|
||||
*/
|
||||
public function test_update_option_should_respect_default_option_filter_when_option_does_not_yet_exist_in_database() {
|
||||
add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
|
||||
$added = update_option( 'doesnotexist', 'bar' );
|
||||
remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
|
||||
|
||||
$this->assertTrue( $added );
|
||||
$this->assertSame( 'bar', get_option( 'doesnotexist' ) );
|
||||
}
|
||||
|
||||
function test_serialized_data() {
|
||||
$key = rand_str();
|
||||
$value = array( 'foo' => true, 'bar' => true );
|
||||
|
||||
Reference in New Issue
Block a user