[wp-trac] [WordPress Trac] #48747: WP_Customize_Setting doesn't clean up after itself
WordPress Trac
noreply at wordpress.org
Thu Nov 21 04:06:08 UTC 2019
#48747: WP_Customize_Setting doesn't clean up after itself
--------------------------+-----------------------------
Reporter: jon81 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version: 5.3
Severity: minor | Keywords:
Focuses: template |
--------------------------+-----------------------------
I've been working on a child theme for twentytwenty, and needed to replace
the **sanitize_callback** on one of the customize settings registered in
the parent theme.
I figured I could just delete the setting and re-create it with my own
callback:-
{{{
// child theme
add_action( 'customize_register', function( $wp_customize )
{
$wp_customize->remove_setting( 'header_footer_background_color' );
$wp_customize->add_setting( 'header_footer_background_color', array(
'default' => '#ffffff'
'sanitize_callback' => 'my_sanitize_callback',
'transport' => 'postMessage',
) );
}, 20 );
function my_sanitize_callback( $value ) {
// sanitize $value
return $value;
}
}}}
.. but the **$value** in my callback was empty and I couldn't figure out
why until I dug a little deeper. The callback set in the parent theme was
still being called before my own callback.
**WP_Customize_Setting** has no destructor and doesn't remove the
filters/actions added during it's construction, so my call to
**$wp_customize->remove_setting()** was not removing the previous sanitize
callback.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48747>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list