[wp-trac] [WordPress Trac] #41271: Customizer sanitize_callback gets called multiple times on setting change
WordPress Trac
noreply at wordpress.org
Fri Jul 7 19:24:25 UTC 2017
#41271: Customizer sanitize_callback gets called multiple times on setting change
----------------------------+-----------------------------
Reporter: kylejennings83 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version: 4.8
Severity: normal | Keywords:
Focuses: |
----------------------------+-----------------------------
I've noticed that the my Customizer setting sanitize_callback get's called
multiple times (4). I think I have deduced that it's not anything weird
I'm doing and that it's not a result of a conflicting plugin.
Using VVV, I spun up a new site, deactivated all the plugins and using
only the default Twenty Seventeen theme I added the following to
functions.php file:
{{{#!php
<?php
function wp_132423_customize_settings($wp_customize){
$wp_customize->add_setting( 'sidebar_size_setting', array(
'default' => 'wide',
'sanitize_callback' => function($val) {
error_log('boom'); // to test
},
)
);
$wp_customize->add_control( 'sidebar_size_control', array(
'label' => 'Sizebar Size',
'section' => 'title_tagline',
'settings' => 'sidebar_size_setting',
'type' => 'select',
'choices' => array(
'wide' => 'Wide',
'narrow' => 'Narrow',
),
)
);
}
add_action('customize_register', 'wp_132423_customize_settings');
}}}
Then I opened the Customizer and changed my "Sizebar Size" control from
wide to narrow while tailing the error log which shows:
{{{
[07-Jul-2017 18:12:22 UTC] boom
[07-Jul-2017 18:12:22 UTC] boom
[07-Jul-2017 18:12:22 UTC] boom
[07-Jul-2017 18:12:22 UTC] boom
}}}
I noticed this while trying to find a way to run a function in the backend
whenever a particular setting was changed. Seemed like the
sanitize_callback was a good place to hook into and noticed this.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41271>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list