From ea13c56d7f55729d0ddd2b6e82ff5decee2069a1 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 6 Feb 2018 14:48:46 +0000 Subject: [PATCH] Options: Unhook default option filter when setting is unregistered. Fixes #43207. git-svn-id: https://develop.svn.wordpress.org/trunk@42655 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/option.php | 5 +++++ tests/phpunit/tests/option/registration.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index f8f3180d5c..f52b7efee7 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -2182,6 +2182,11 @@ function unregister_setting( $option_group, $option_name, $deprecated = '' ) { remove_filter( "sanitize_option_{$option_name}", $wp_registered_settings[ $option_name ]['sanitize_callback'] ); } + // Remove the default filter if a default was provided during registration. + if ( array_key_exists( 'default', $wp_registered_settings[ $option_name ] ) ) { + remove_filter( "default_option_{$option_name}", 'filter_default_option', 10 ); + } + unset( $wp_registered_settings[ $option_name ] ); } } diff --git a/tests/phpunit/tests/option/registration.php b/tests/phpunit/tests/option/registration.php index ba34863ac8..c29663f12f 100644 --- a/tests/phpunit/tests/option/registration.php +++ b/tests/phpunit/tests/option/registration.php @@ -94,4 +94,19 @@ class Tests_Option_Registration extends WP_UnitTestCase { public function test_register_deprecated_group_privacy() { register_setting( 'privacy', 'test_option' ); } + + /** + * @ticket 43207 + */ + public function test_unregister_setting_removes_default() { + register_setting( + 'test_group', 'test_default', array( + 'default' => 'Fuck Cancer', + ) + ); + + unregister_setting( 'test_group', 'test_default' ); + + $this->assertFalse( has_filter( 'default_option_test_default', 'filter_default_option' ) ); + } }