Opened 7 years ago
Last modified 3 years ago
#41271 closed defect (bug)
Customizer sanitize_callback gets called multiple times on setting change — at Initial Version
Reported by: | kylejennings83 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.8 |
Component: | Customize | Keywords: | needs-patch |
Focuses: | performance | Cc: |
Description
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 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.
Note: See
TracTickets for help on using
tickets.