Make WordPress Core


Ignore:
Timestamp:
07/06/2015 07:12:48 PM (11 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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' => __( '— Select —' ) );
    439                         foreach ( $menus as $menu ) {
    440                                 $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '…' );
     436                $choices = array( '0' => __( '— Select —' ) );
     437                foreach ( $menus as $menu ) {
     438                        $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '…' );
     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.