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
This commit is contained in:
Felix Arntz 2018-02-06 14:48:46 +00:00
parent e04b4d47b4
commit ea13c56d7f
2 changed files with 20 additions and 0 deletions

View File

@ -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 ] );
}
}

View File

@ -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' ) );
}
}