[wp-trac] [WordPress Trac] #39040: Hide references to nav menu locations that are not visible in the customizer preview (was: Refresh Menu Locations in Customizer after refresh)

WordPress Trac noreply at wordpress.org
Sun Dec 4 20:47:16 UTC 2016


#39040: Hide references to nav menu locations that are not visible in the
customizer preview
-------------------------+-----------------------------
 Reporter:  khela        |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  Customize    |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+-----------------------------
Changes (by westonruter):

 * milestone:  Awaiting Review => Future Release


Comment:

 @khela thanks for the report. You raise an interesting use case. The best
 way to accomplish this right now would be to make use of the
 `active_callback`. This will get you most of the way:

 {{{#!php
 <?php
 add_action( 'customize_register', function( WP_Customize_Manager
 $wp_customize ) {
         $primary_menu_location_control = $wp_customize->get_control(
 'nav_menu_locations[primary]' );
         $primary_left_menu_location_control = $wp_customize->get_control(
 'nav_menu_locations[primary-left]' );
         $primary_right_menu_location_control = $wp_customize->get_control(
 'nav_menu_locations[primary-right]' );

         $single_menus_active_callback = function() {
                 return get_theme_mod( 'header_style', 'singlemenu' ) ===
 'singlemenu';
         };
         $plural_menus_active_callback = function() {
                 return get_theme_mod( 'header_style', 'singlemenu' ) !==
 'singlemenu';
         };
         $primary_menu_location_control->active_callback =
 $single_menus_active_callback;
         $primary_left_menu_location_control->active_callback =
 $plural_menus_active_callback;
         $primary_right_menu_location_control->active_callback =
 $plural_menus_active_callback;
 }, 20 );
 }}}

 What this won't do is ensure that the nav menu location checkboxes are
 hidden when editing a nav menu in the customizer. This would need to be
 some additional JS that disables/hides those nav menu locations. Ideally
 this should all happen by default when a nav menu location is not
 available in the preview just like sections for widget sidebars not shown
 in the preview when they are not rendered.

 This is also related to lazy-loading settings on demand: #28580.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39040#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list