[wp-trac] [WordPress Trac] #32103: Customizer snitize data multiple times when options are served as Serialized Settings

WordPress Trac noreply at wordpress.org
Fri Apr 24 08:20:27 UTC 2015


#32103: Customizer snitize data multiple times when options are served as
Serialized Settings
----------------------------+-----------------------------
 Reporter:  Air.            |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Customize       |    Version:  4.2
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 When you have theme settings saved as serialized data(like explained in
 ottos tutorial in point 3 of paragraph "Existing Options"
 http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-
 own-themes/ ), customizer will sanitize data as many times, as many
 options there are in this array of settings. Per option! So if you have
 like 20 options in such setting, and you change 1, sanitize callback will
 be called 20 times, for this one setting. If I change 3 options, then it
 will be called 60 times, 57 too much:-) And I have big array of settings,
 like 60 per section, and also heavy sanitize function so it gives big
 waste of time.

 Now to be more detailed: if we have Array with three settings like this:
 nice_theme_settings[setting1]
 nice_theme_settings[setting2]
 nice_theme_settings[setting3]
 ....
 nice_theme_settings[setting20]

 and we use "sanitize_callback" then for each such option is registered
 filter in preview method(file wp-includes\class-wp-customize-setting.php
 ~155:

 {{{
         public function preview() {
                 ...

                 switch( $this->type ) {
                         ....
                         case 'option' :
                                 if ( empty( $this->id_data[ 'keys' ] ) )
                                         add_filter( 'pre_option_' .
 $this->id_data[ 'base' ], array( $this, '_preview_filter' ) );
                                 else {
                                         add_filter( 'option_' .
 $this->id_data[ 'base' ], array( $this, '_preview_filter' ) );
                                         add_filter( 'default_option_' .
 $this->id_data[ 'base' ], array( $this, '_preview_filter' ) );
                                 }
                                 break;
                         ....


                 }
         }
 }}}

 All these filters that add filters using " $this->id_data[ 'base' ]"
 '''will add X(20 in this case) times filter''' that looks like this:

 {{{
 add_filter( 'option_nice_theme_settings', 'function' );
 }}}


 In other place wordpress uses id as variable part of filter so it looks
 proper, like this:

 {{{
 add_filter( 'option_nice_theme_settings[setting3]', 'function' );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32103>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list