From 60e9d045e72ce6e93674fad2ce9b07e1f1cc83a0 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Wed, 30 Nov 2016 21:31:38 +0000 Subject: [PATCH] Options: Pass the `$passed_default` parameter to the `default_option_{$option}` filter in `add_option()`. This was missed in [38910]. Merge of [39382] to the 4.7 branch. Props joehoyle, lucasstark. See #38176, #38930. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@39383 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/option.php | 2 +- tests/phpunit/tests/option/registration.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 82625f764e..05c6cc7421 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -421,7 +421,7 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) $notoptions = wp_cache_get( 'notoptions', 'options' ); if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) ) /** This filter is documented in wp-includes/option.php */ - if ( apply_filters( 'default_option_' . $option, false, $option ) !== get_option( $option ) ) + if ( apply_filters( 'default_option_' . $option, false, $option, false ) !== get_option( $option ) ) return false; $serialized_value = maybe_serialize( $value ); diff --git a/tests/phpunit/tests/option/registration.php b/tests/phpunit/tests/option/registration.php index 7e18e09afb..98c7d5b91a 100644 --- a/tests/phpunit/tests/option/registration.php +++ b/tests/phpunit/tests/option/registration.php @@ -61,6 +61,18 @@ class Tests_Option_Registration extends WP_UnitTestCase { $this->assertEquals( 'Fuck Leukemia', get_option( 'test_default', 'Fuck Leukemia' ) ); } + /** + * @ticket 38930 + */ + public function test_add_option_with_no_options_cache() { + register_setting( 'test_group', 'test_default', array( + 'default' => 'My Default :)', + )); + wp_cache_delete( 'notoptions', 'options' ); + $this->assertTrue( add_option( 'test_default', 'hello' ) ); + $this->assertEquals( 'hello', get_option( 'test_default' ) ); + } + /** * @expectedDeprecated register_setting */