WordPress.org

Make WordPress Core

Changeset 33094


Ignore:
Timestamp:
07/06/2015 07:12:48 PM (4 years ago)
Author:
westonruter
Message:

Customizer: Register controls and settings for nav_menu_locations even when there are no menus yet.

This change ensures that the first menu created can be assigned to a location without first saving and reloading the Customizer.

Props markoheijnen.
Fixes #32858.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-nav-menus.js

    r33077 r33094  
    25462546     */
    25472547    function displayNavMenuName( name ) {
     2548        name = name || '';
    25482549        name = $( '<div>' ).text( name ).html(); // Emulate esc_html() which is used in wp-admin/nav-menus.php.
    25492550        name = $.trim( name );
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r33089 r33094  
    434434        ) );
    435435
    436         // @todo if ( ! $menus ) : make a "default" menu
    437         if ( $menus ) {
    438             $choices = array( '0' => __( '&mdash; Select &mdash;' ) );
    439             foreach ( $menus as $menu ) {
    440                 $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
     436        $choices = array( '0' => __( '&mdash; Select &mdash;' ) );
     437        foreach ( $menus as $menu ) {
     438            $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
     439        }
     440
     441        foreach ( $locations as $location => $description ) {
     442            $setting_id = "nav_menu_locations[{$location}]";
     443
     444            $setting = $this->manager->get_setting( $setting_id );
     445            if ( $setting ) {
     446                $setting->transport = 'postMessage';
     447                remove_filter( "customize_sanitize_{$setting_id}", 'absint' );
     448                add_filter( "customize_sanitize_{$setting_id}", array( $this, 'intval_base10' ) );
     449            } else {
     450                $this->manager->add_setting( $setting_id, array(
     451                    'sanitize_callback' => array( $this, 'intval_base10' ),
     452                    'theme_supports'    => 'menus',
     453                    'type'              => 'theme_mod',
     454                    'transport'         => 'postMessage',
     455                ) );
    441456            }
    442457
    443             foreach ( $locations as $location => $description ) {
    444                 $setting_id = "nav_menu_locations[{$location}]";
    445 
    446                 $setting = $this->manager->get_setting( $setting_id );
    447                 if ( $setting ) {
    448                     $setting->transport = 'postMessage';
    449                     remove_filter( "customize_sanitize_{$setting_id}", 'absint' );
    450                     add_filter( "customize_sanitize_{$setting_id}", array( $this, 'intval_base10' ) );
    451                 } else {
    452                     $this->manager->add_setting( $setting_id, array(
    453                         'sanitize_callback' => array( $this, 'intval_base10' ),
    454                         'theme_supports'    => 'menus',
    455                         'type'              => 'theme_mod',
    456                         'transport'         => 'postMessage',
    457                     ) );
    458                 }
    459 
    460                 $this->manager->add_control( new WP_Customize_Nav_Menu_Location_Control( $this->manager, $setting_id, array(
    461                     'label'       => $description,
    462                     'location_id' => $location,
    463                     'section'     => 'menu_locations',
    464                     'choices'     => $choices,
    465                 ) ) );
    466             }
     458            $this->manager->add_control( new WP_Customize_Nav_Menu_Location_Control( $this->manager, $setting_id, array(
     459                'label'       => $description,
     460                'location_id' => $location,
     461                'section'     => 'menu_locations',
     462                'choices'     => $choices,
     463            ) ) );
    467464        }
    468465
Note: See TracChangeset for help on using the changeset viewer.