[wp-trac] [WordPress Trac] #32103: Customizer sanitizes data multiple times when options are served as Serialized Settings
WordPress Trac
noreply at wordpress.org
Sat Oct 3 16:49:59 UTC 2015
#32103: Customizer sanitizes data multiple times when options are served as
Serialized Settings
-------------------------------------+-------------------------------------
Reporter: Air. | Owner: westonruter
Type: defect (bug) | Status: accepted
Priority: normal | Milestone: 4.4
Component: Customize | Version: 3.4
Severity: normal | Resolution:
Keywords: has-patch needs-testing | Focuses: administration,
reporter-feedback | performance
-------------------------------------+-------------------------------------
Comment (by wpweaver):
Final follow up - I'm sure my diagnosis is correct because my solution
completely fixes the issue. It is SO cool to see an instant update no
matter how many options I used. I tested with 2000 controls, and the
preview updated within a couple of seconds. (The customizer panel took a
bit longer to build, but that's a one shot thing.)
I use the optional alternate type case to implement my solution as you
suggested earlier, but I think the principles will apply to a more general
solution. The key is to build a list of the WP_Customize_Setting objects
instead of adding yet another filter, then using that list in the option
filters. Here's my code just to prove the concept. I hope it helps to
speed up the preview code because even the few seconds the preview is
taking for even 50 options is too long. This will help everyone without
making them find their own solution.
I don't think the multidimensional replace code is too slow, so you can no
doubt use that logic. My replacement loop is obviously specific for the
settings array used by my theme. But the concept holds true.
{{{
function weaverx_weaverx_cz( $setting ) {
// This action is called once for each Weaver Xtreme option added
to the Customizer controls.
if (!isset( $GLOBALS['weaverx_cz_settings']))
$GLOBALS['weaverx_cz_settings'] = array();
$GLOBALS['weaverx_cz_settings'][] = $setting;
}
add_action('customize_preview_weaverx_cz','weaverx_weaverx_cz');
function weaverx_cz_options_filter( $original ) {
if (empty($GLOBALS['weaverx_cz_settings']))
return $original;
$copy = $original;
foreach ($GLOBALS['weaverx_cz_settings'] as $setting ) {
$id = str_replace(array('weaverx_settings[',']'), '',
$setting->id);
$value = $setting->post_value();
if ( $value != null)
if ( isset($copy[$id]) && $copy[$id] != $value)
$copy[$id] = $value;
else
$copy[$id] = $value;
}
return $copy;
}
add_filter('option_weaverx_settings', 'weaverx_cz_options_filter');
add_filter('default_option_weaverx_settings',
'weaverx_cz_options_filter');
add_filter('pre_option_weaverx_settings', 'weaverx_cz_options_filter');
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32103#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list