[wp-trac] [WordPress Trac] #29165: customize_preview_$setting->id action should be customize_preview_$setting->type

WordPress Trac noreply at wordpress.org
Sat Aug 9 20:31:44 UTC 2014


#29165: customize_preview_$setting->id action should be
customize_preview_$setting->type
------------------------------+----------------------------
 Reporter:  celloexpressions  |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Future Release
Component:  Customize         |    Version:  3.4
 Severity:  normal            |   Keywords:  has-patch
  Focuses:                    |
------------------------------+----------------------------
 When working with custom Customizer Setting types, the following actions
 are available to implement saving and previewing:
 - `customize_update_$setting->type`
 - `customize_preview_$setting->id`

 Another action, `customize_save_$setting->id_data[ 'base' ]` fires for all
 settings, regardless of their type (the inline docs are wrong here, patch
 fixes them), so it has a different use case (also, the save method calls
 the update method, which fires the update action). However,
 `customize_preview_$setting->id` would be much more useful as
 `customize_preview_$setting->type`, matching
 `customize_update_$setting->type`, as custom setting ''types'' will
 typically be applicable to multiple settings (ie, multiple ''ids'').

 Here's an example of the workaround that I'm using in the Menu Customizer:
 {{{
 function menu_customizer_setup_menu_previewing() {
         $menus = wp_get_nav_menus();

         foreach ( $menus as $menu ) {
                 $menu_id = $menu->term_id;
                 $setting_id = 'nav_menu_' . $menu_id;
                 add_action( 'customize_preview_' . $setting_id,
 'menu_customizer_preview_nav_menu', 10, 1 );
         }
 }
 add_action( 'customize_register', 'menu_customizer_setup_menu_previewing'
 );
 }}}
 Which could be replaced with, simply:
 {{{
 add_action( 'customize_preview_nav_menu',
 'menu_customizer_preview_nav_menu', 10, 1 );
 }}}
 Which would match the corresponding update action:
 {{{
 add_action( 'customize_update_nav_menu',
 'menu_customizer_update_nav_menu', 10, 2 );
 }}}

 Can't really change the action at this point, so patch adds a new one.
 Would love to get this into 4.0, but probably needs to wait until 4.1.

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


More information about the wp-trac mailing list