Make WordPress Core


Ignore:
Timestamp:
07/29/2015 04:02:08 PM (9 years ago)
Author:
westonruter
Message:

Customizer: Ensure that all existing menus are shown in the Custom Menu widget's dropdown.

  • Ensure that a Custom Menu widget selecting a newly-inserted menu gets updated to use the new menu ID upon Save & Publish.
  • Dynamically update the visibility of the Custom Menu widget's "no menus" message when the number of menus changes between 0 and 1+.
  • Send all dirty Customized settings in update-widget Ajax request and preview() them so that the widget update/form callbacks have access to any data dependencies in the current Customizer session (such as newly created unsaved menus).
  • Update link in Custom Menu widget to point to Menus panel as opposed to Menus admin page, when in the Customizer.
  • Fix an issue with extra space at top immediately after creating new menu.
  • Fix doubled update-widget Ajax requests when changing select dropdown; prevent initial from being aborted.
  • Add missing wp_get_nav_menus() hooks to preview Customizer updates/inserts for nav_menu settings; includes tests.
  • Update wp_get_nav_menu_object() to allow a menu object to be passed in (and thus passed through).

Props westonruter, adamsilverstein.
Fixes #32814.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-widgets.php

    r32907 r33488  
    15711571
    15721572        // If no menus exists, direct the user to go and create some.
    1573         if ( !$menus ) {
    1574             echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
    1575             return;
    1576         }
    15771573        ?>
    1578         <p>
    1579             <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
    1580             <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
     1574        <p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>>
     1575            <?php
     1576            if ( isset( $GLOBALS['wp_customize'] ) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager ) {
     1577                // @todo When expanding a panel, the JS should be smart enough to collapse any existing panels and sections.
     1578                $url = 'javascript: wp.customize.section.each(function( section ){ section.collapse(); }); wp.customize.panel( "nav_menus" ).focus();';
     1579            } else {
     1580                $url = admin_url( 'nav-menus.php' );
     1581            }
     1582            ?>
     1583            <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?>
    15811584        </p>
    1582         <p>
    1583             <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
    1584             <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
    1585                 <option value="0"><?php _e( '&mdash; Select &mdash;' ) ?></option>
    1586         <?php
    1587             foreach ( $menus as $menu ) {
    1588                 echo '<option value="' . $menu->term_id . '"'
    1589                     . selected( $nav_menu, $menu->term_id, false )
    1590                     . '>'. esc_html( $menu->name ) . '</option>';
    1591             }
    1592         ?>
    1593             </select>
    1594         </p>
     1585        <div class="nav-menu-widget-form-controls" <?php if ( empty( $menus ) ) { echo ' style="display:none" '; } ?>>
     1586            <p>
     1587                <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ) ?></label>
     1588                <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>"/>
     1589            </p>
     1590            <p>
     1591                <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label>
     1592                <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>">
     1593                    <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
     1594                    <?php foreach ( $menus as $menu ) : ?>
     1595                        <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $nav_menu, $menu->term_id ); ?>>
     1596                            <?php echo esc_html( $menu->name ); ?>
     1597                        </option>
     1598                    <?php endforeach; ?>
     1599                </select>
     1600            </p>
     1601        </div>
    15951602        <?php
    15961603    }
Note: See TracChangeset for help on using the changeset viewer.