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.

Built from https://develop.svn.wordpress.org/trunk@33094


git-svn-id: http://core.svn.wordpress.org/trunk@33065 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2015-07-06 19:13:25 +00:00
parent 7b7fe01f76
commit a62cc940ea
4 changed files with 29 additions and 31 deletions

View File

@ -2545,6 +2545,7 @@
* @returns {string} * @returns {string}
*/ */
function displayNavMenuName( name ) { function displayNavMenuName( name ) {
name = name || '';
name = $( '<div>' ).text( name ).html(); // Emulate esc_html() which is used in wp-admin/nav-menus.php. name = $( '<div>' ).text( name ).html(); // Emulate esc_html() which is used in wp-admin/nav-menus.php.
name = $.trim( name ); name = $.trim( name );
return name || api.Menus.data.l10n.unnamed; return name || api.Menus.data.l10n.unnamed;

File diff suppressed because one or more lines are too long

View File

@ -433,37 +433,34 @@ final class WP_Customize_Nav_Menus {
'description' => $description, 'description' => $description,
) ); ) );
// @todo if ( ! $menus ) : make a "default" menu $choices = array( '0' => __( '&mdash; Select &mdash;' ) );
if ( $menus ) { foreach ( $menus as $menu ) {
$choices = array( '0' => __( '&mdash; Select &mdash;' ) ); $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
foreach ( $menus as $menu ) { }
$choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
foreach ( $locations as $location => $description ) {
$setting_id = "nav_menu_locations[{$location}]";
$setting = $this->manager->get_setting( $setting_id );
if ( $setting ) {
$setting->transport = 'postMessage';
remove_filter( "customize_sanitize_{$setting_id}", 'absint' );
add_filter( "customize_sanitize_{$setting_id}", array( $this, 'intval_base10' ) );
} else {
$this->manager->add_setting( $setting_id, array(
'sanitize_callback' => array( $this, 'intval_base10' ),
'theme_supports' => 'menus',
'type' => 'theme_mod',
'transport' => 'postMessage',
) );
} }
foreach ( $locations as $location => $description ) { $this->manager->add_control( new WP_Customize_Nav_Menu_Location_Control( $this->manager, $setting_id, array(
$setting_id = "nav_menu_locations[{$location}]"; 'label' => $description,
'location_id' => $location,
$setting = $this->manager->get_setting( $setting_id ); 'section' => 'menu_locations',
if ( $setting ) { 'choices' => $choices,
$setting->transport = 'postMessage'; ) ) );
remove_filter( "customize_sanitize_{$setting_id}", 'absint' );
add_filter( "customize_sanitize_{$setting_id}", array( $this, 'intval_base10' ) );
} else {
$this->manager->add_setting( $setting_id, array(
'sanitize_callback' => array( $this, 'intval_base10' ),
'theme_supports' => 'menus',
'type' => 'theme_mod',
'transport' => 'postMessage',
) );
}
$this->manager->add_control( new WP_Customize_Nav_Menu_Location_Control( $this->manager, $setting_id, array(
'label' => $description,
'location_id' => $location,
'section' => 'menu_locations',
'choices' => $choices,
) ) );
}
} }
// Register each menu as a Customizer section, and add each menu item to each menu. // Register each menu as a Customizer section, and add each menu item to each menu.

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-beta1-33093'; $wp_version = '4.3-beta1-33094';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.