<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[33488] trunk: Customizer: Ensure that all existing menus are shown in the Custom Menu widget's dropdown.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/33488">33488</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/33488","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-07-29 16:02:08 +0000 (Wed, 29 Jul 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/32814">#32814</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjscustomizenavmenusjs">trunk/src/wp-admin/js/customize-nav-menus.js</a></li>
<li><a href="#trunksrcwpadminjscustomizewidgetsjs">trunk/src/wp-admin/js/customize-widgets.js</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizesettingphp">trunk/src/wp-includes/class-wp-customize-setting.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizewidgetsphp">trunk/src/wp-includes/class-wp-customize-widgets.php</a></li>
<li><a href="#trunksrcwpincludesdefaultwidgetsphp">trunk/src/wp-includes/default-widgets.php</a></li>
<li><a href="#trunksrcwpincludesnavmenuphp">trunk/src/wp-includes/nav-menu.php</a></li>
<li><a href="#trunktestsphpunittestscustomizenavmenusettingphp">trunk/tests/phpunit/tests/customize/nav-menu-setting.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjscustomizenavmenusjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/customize-nav-menus.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/customize-nav-menus.js 2015-07-29 14:56:23 UTC (rev 33487)
+++ trunk/src/wp-admin/js/customize-nav-menus.js 2015-07-29 16:02:08 UTC (rev 33488)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -957,7 +957,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var control = this;
</span><span class="cx" style="display: block; padding: 0 10px"> api.Control.prototype.initialize.call( control, id, options );
</span><span class="cx" style="display: block; padding: 0 10px"> control.active.validate = function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return api.section( control.section() ).active();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var value, section = api.section( control.section() );
+ if ( section ) {
+ value = section.active();
+ } else {
+ value = false;
+ }
+ return value;
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1604,7 +1610,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * being deactivated.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> control.active.validate = function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return api.section( control.section() ).active();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var value, section = api.section( control.section() );
+ if ( section ) {
+ value = section.active();
+ } else {
+ value = false;
+ }
+ return value;
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> control.nameElement = new api.Element( control.container.find( '.menu-name-field' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1650,7 +1662,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * being deactivated.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> control.active.validate = function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return api.section( control.section() ).active();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var value, section = api.section( control.section() );
+ if ( section ) {
+ value = section.active();
+ } else {
+ value = false;
+ }
+ return value;
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> control.autoAddElement = new api.Element( control.container.find( 'input[type=checkbox].auto_add' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1693,7 +1711,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var control = this,
</span><span class="cx" style="display: block; padding: 0 10px"> menuId = control.params.menu_id,
</span><span class="cx" style="display: block; padding: 0 10px"> menu = control.setting(),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- name;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ name,
+ widgetTemplate,
+ select;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'undefined' === typeof this.params.menu_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error( 'params.menu_id was not defined' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1705,7 +1725,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * being deactivated.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> control.active.validate = function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return api.section( control.section() ).active();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var value, section = api.section( control.section() );
+ if ( section ) {
+ value = section.active();
+ } else {
+ value = false;
+ }
+ return value;
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> control.$controlSection = control.container.closest( '.control-section' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1727,16 +1753,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( menu ) {
</span><span class="cx" style="display: block; padding: 0 10px"> name = displayNavMenuName( menu.name );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Add the menu to the existing controls.
</ins><span class="cx" style="display: block; padding: 0 10px"> api.control.each( function( widgetControl ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! widgetControl.extended( api.controlConstructor.widget_form ) || 'nav_menu' !== widgetControl.params.widget_id_base ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var select = widgetControl.container.find( 'select' );
- if ( select.find( 'option[value=' + String( menuId ) + ']' ).length === 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ widgetControl.container.find( '.nav-menu-widget-form-controls:first' ).show();
+ widgetControl.container.find( '.nav-menu-widget-no-menus-message:first' ).hide();
+
+ select = widgetControl.container.find( 'select' );
+ if ( 0 === select.find( 'option[value=' + String( menuId ) + ']' ).length ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> select.append( new Option( name, menuId ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first' ).append( new Option( name, menuId ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Add the menu to the widget template.
+ widgetTemplate = $( '#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )' );
+ widgetTemplate.find( '.nav-menu-widget-form-controls:first' ).show();
+ widgetTemplate.find( '.nav-menu-widget-no-menus-message:first' ).hide();
+ select = widgetTemplate.find( '.widget-inside select:first' );
+ if ( 0 === select.find( 'option[value=' + String( menuId ) + ']' ).length ) {
+ select.append( new Option( name, menuId ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1761,7 +1799,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var select = widgetControl.container.find( 'select' );
</span><span class="cx" style="display: block; padding: 0 10px"> select.find( 'option[value=' + String( menuId ) + ']' ).text( name );
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first option[value=' + String( menuId ) + ']' ).text( name );
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1833,8 +1870,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> menuItemControl.setting.set( setting );
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> });
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> control.isReordering = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1871,7 +1908,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var control = this,
</span><span class="cx" style="display: block; padding: 0 10px"> section,
</span><span class="cx" style="display: block; padding: 0 10px"> menuId = control.params.menu_id,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- removeSection;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ removeSection,
+ widgetTemplate,
+ navMenuCount = 0;
</ins><span class="cx" style="display: block; padding: 0 10px"> section = api.section( control.section() );
</span><span class="cx" style="display: block; padding: 0 10px"> removeSection = function() {
</span><span class="cx" style="display: block; padding: 0 10px"> section.container.remove();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1890,6 +1929,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> removeSection();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ api.each(function( setting ) {
+ if ( /^nav_menu\[/.test( setting.id ) && false !== setting() ) {
+ navMenuCount += 1;
+ }
+ });
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Remove the menu from any Custom Menu widgets.
</span><span class="cx" style="display: block; padding: 0 10px"> api.control.each(function( widgetControl ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! widgetControl.extended( api.controlConstructor.widget_form ) || 'nav_menu' !== widgetControl.params.widget_id_base ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1899,9 +1944,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( select.val() === String( menuId ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> select.prop( 'selectedIndex', 0 ).trigger( 'change' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- select.find( 'option[value=' + String( menuId ) + ']' ).remove();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ widgetControl.container.find( '.nav-menu-widget-form-controls:first' ).toggle( 0 !== navMenuCount );
+ widgetControl.container.find( '.nav-menu-widget-no-menus-message:first' ).toggle( 0 === navMenuCount );
+ widgetControl.container.find( 'option[value=' + String( menuId ) + ']' ).remove();
</ins><span class="cx" style="display: block; padding: 0 10px"> });
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first option[value=' + String( menuId ) + ']' ).remove();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Remove the menu to the nav menu widget template.
+ widgetTemplate = $( '#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )' );
+ widgetTemplate.find( '.nav-menu-widget-form-controls:first' ).toggle( 0 !== navMenuCount );
+ widgetTemplate.find( '.nav-menu-widget-no-menus-message:first' ).toggle( 0 === navMenuCount );
+ widgetTemplate.find( 'option[value=' + String( menuId ) + ']' ).remove();
</ins><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Setup theme location checkboxes.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2294,6 +2347,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Focus on the new menu section.
</span><span class="cx" style="display: block; padding: 0 10px"> api.section( customizeId ).focus(); // @todo should we focus on the new menu's control and open the add-items panel? Thinking user flow...
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Fix an issue with extra space at top immediately after creating new menu.
+ $( '#menu-to-edit' ).css( 'margin-top', 0 );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2359,7 +2415,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var insertedMenuIdMapping = {};
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> _( data.nav_menu_updates ).each(function( update ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var oldCustomizeId, newCustomizeId, customizeId, oldSetting, newSetting, setting, settingValue, oldSection, newSection, wasSaved;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var oldCustomizeId, newCustomizeId, customizeId, oldSetting, newSetting, setting, settingValue, oldSection, newSection, wasSaved, widgetTemplate, navMenuCount;
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( 'inserted' === update.status ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! update.previous_term_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error( 'Expected previous_term_id' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2409,19 +2465,45 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Remove old setting and control.
- oldSection.container.remove();
- api.section.remove( oldCustomizeId );
-
- // Add new control to take its place.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Add new control for the new menu.
</ins><span class="cx" style="display: block; padding: 0 10px"> api.section.add( newCustomizeId, newSection );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Delete the placeholder and preview the new setting.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Update the values for nav menus in Custom Menu controls.
+ api.control.each( function( setting ) {
+ if ( ! setting.extended( api.controlConstructor.widget_form ) || 'nav_menu' !== setting.params.widget_id_base ) {
+ return;
+ }
+ var select, oldMenuOption, newMenuOption;
+ select = setting.container.find( 'select' );
+ oldMenuOption = select.find( 'option[value=' + String( update.previous_term_id ) + ']' );
+ newMenuOption = select.find( 'option[value=' + String( update.term_id ) + ']' );
+ newMenuOption.prop( 'selected', oldMenuOption.prop( 'selected' ) );
+ oldMenuOption.remove();
+ } );
+
+ // Delete the old placeholder nav_menu.
</ins><span class="cx" style="display: block; padding: 0 10px"> oldSetting.callbacks.disable(); // Prevent setting triggering Customizer dirty state when set.
</span><span class="cx" style="display: block; padding: 0 10px"> oldSetting.set( false );
</span><span class="cx" style="display: block; padding: 0 10px"> oldSetting.preview();
</span><span class="cx" style="display: block; padding: 0 10px"> newSetting.preview();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ oldSetting._dirty = false;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Remove nav_menu section.
+ oldSection.container.remove();
+ api.section.remove( oldCustomizeId );
+
+ // Remove the menu to the nav menu widget template.
+ navMenuCount = 0;
+ api.each(function( setting ) {
+ if ( /^nav_menu\[/.test( setting.id ) && false !== setting() ) {
+ navMenuCount += 1;
+ }
+ });
+ widgetTemplate = $( '#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )' );
+ widgetTemplate.find( '.nav-menu-widget-form-controls:first' ).toggle( 0 !== navMenuCount );
+ widgetTemplate.find( '.nav-menu-widget-no-menus-message:first' ).toggle( 0 === navMenuCount );
+ widgetTemplate.find( 'option[value=' + String( update.previous_term_id ) + ']' ).remove();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Update nav_menu_locations to reference the new ID.
</span><span class="cx" style="display: block; padding: 0 10px"> api.each( function( setting ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var wasSaved = api.state( 'saved' ).get();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2437,8 +2519,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // @todo This doesn't seem to be working.
</span><span class="cx" style="display: block; padding: 0 10px"> newSection.expand();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- // @todo Update the Custom Menu selects, ensuring the newly-inserted IDs are used for any that have selected a placeholder menu.
</del><span class="cx" style="display: block; padding: 0 10px"> } else if ( 'updated' === update.status ) {
</span><span class="cx" style="display: block; padding: 0 10px"> customizeId = 'nav_menu[' + String( update.term_id ) + ']';
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! api.has( customizeId ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2510,7 +2590,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> previewer: api.previewer
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Remove old setting and control.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Remove old control.
</ins><span class="cx" style="display: block; padding: 0 10px"> oldControl.container.remove();
</span><span class="cx" style="display: block; padding: 0 10px"> api.control.remove( oldCustomizeId );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2522,12 +2602,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> oldSetting.set( false );
</span><span class="cx" style="display: block; padding: 0 10px"> oldSetting.preview();
</span><span class="cx" style="display: block; padding: 0 10px"> newSetting.preview();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ oldSetting._dirty = false;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> newControl.container.toggleClass( 'menu-item-edit-inactive', oldControl.container.hasClass( 'menu-item-edit-inactive' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // @todo trigger change event for each Custom Menu widget that was modified.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Update the settings for any nav_menu widgets that had selected a placeholder ID.
+ */
+ _.each( data.widget_nav_menu_updates, function( widgetSettingValue, widgetSettingId ) {
+ var setting = api( widgetSettingId );
+ if ( setting ) {
+ setting._value = widgetSettingValue;
+ setting.preview(); // Send to the preview now so that menu refresh will use the inserted menu.
+ }
+ });
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpadminjscustomizewidgetsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/customize-widgets.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/customize-widgets.js 2015-07-29 14:56:23 UTC (rev 33487)
+++ trunk/src/wp-admin/js/customize-widgets.js 2015-07-29 16:02:08 UTC (rev 33488)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -786,13 +786,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Handle widgets that support live previews
</span><span class="cx" style="display: block; padding: 0 10px"> $widgetContent.on( 'change input propertychange', ':input', function( e ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( self.liveUpdateMode ) {
- if ( e.type === 'change' ) {
- self.updateWidget();
- } else if ( this.checkValidity && this.checkValidity() ) {
- updateWidgetDebounced();
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! self.liveUpdateMode ) {
+ return;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( e.type === 'change' || ( this.checkValidity && this.checkValidity() ) ) {
+ updateWidgetDebounced();
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Remove loading indicators when the setting is saved and the preview updates
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1041,6 +1040,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> params.wp_customize = 'on';
</span><span class="cx" style="display: block; padding: 0 10px"> params.nonce = api.Widgets.data.nonce;
</span><span class="cx" style="display: block; padding: 0 10px"> params.theme = api.settings.theme.stylesheet;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ params.customized = wp.customize.previewer.query().customized;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> data = $.param( params );
</span><span class="cx" style="display: block; padding: 0 10px"> $inputs = this._getInputs( $widgetContent );
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizesettingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-customize-setting.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-setting.php 2015-07-29 14:56:23 UTC (rev 33487)
+++ trunk/src/wp-includes/class-wp-customize-setting.php 2015-07-29 16:02:08 UTC (rev 33488)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1625,12 +1625,102 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->_original_value = $this->value();
</span><span class="cx" style="display: block; padding: 0 10px"> $this->_previewed_blog_id = get_current_blog_id();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_filter( 'wp_get_nav_menus', array( $this, 'filter_wp_get_nav_menus' ), 10, 2 );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'wp_get_nav_menu_object', array( $this, 'filter_wp_get_nav_menu_object' ), 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'default_option_nav_menu_options', array( $this, 'filter_nav_menu_options' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'option_nav_menu_options', array( $this, 'filter_nav_menu_options' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filter the wp_get_nav_menus() result to ensure the inserted menu object is included, and the deleted one is removed.
+ *
+ * @since 4.3.0
+ * @access public
+ *
+ * @see wp_get_nav_menus()
+ *
+ * @param array $menus An array of menu objects.
+ * @param array $args An array of arguments used to retrieve menu objects.
+ * @return array
+ */
+ public function filter_wp_get_nav_menus( $menus, $args ) {
+ if ( get_current_blog_id() !== $this->_previewed_blog_id ) {
+ return $menus;
+ }
+
+ $setting_value = $this->value();
+ $is_delete = ( false === $setting_value );
+ $index = -1;
+
+ // Find the existing menu item's position in the list.
+ foreach ( $menus as $i => $menu ) {
+ if ( (int) $this->term_id === (int) $menu->term_id || (int) $this->previous_term_id === (int) $menu->term_id ) {
+ $index = $i;
+ break;
+ }
+ }
+
+ if ( $is_delete ) {
+ // Handle deleted menu by removing it from the list.
+ if ( -1 !== $index ) {
+ array_splice( $menus, $index, 1 );
+ }
+ } else {
+ // Handle menus being updated or inserted.
+ $menu_obj = (object) array_merge( array(
+ 'term_id' => $this->term_id,
+ 'term_taxonomy_id' => $this->term_id,
+ 'slug' => sanitize_title( $setting_value['name'] ),
+ 'count' => 0,
+ 'term_group' => 0,
+ 'taxonomy' => self::TAXONOMY,
+ 'filter' => 'raw',
+ ), $setting_value );
+
+ array_splice( $menus, $index, ( -1 === $index ? 0 : 1 ), array( $menu_obj ) );
+ }
+
+ // Make sure the menu objects get re-sorted after an update/insert.
+ if ( ! $is_delete && ! empty( $args['orderby'] ) ) {
+ $this->_current_menus_sort_orderby = $args['orderby'];
+ usort( $menus, array( $this, '_sort_menus_by_orderby' ) );
+ }
+ // @todo add support for $args['hide_empty'] === true
+
+ return $menus;
+ }
+
+ /**
+ * Temporary non-closure passing of orderby value to function.
+ *
+ * @since 4.3.0
+ * @access protected
+ * @var string
+ *
+ * @see WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus()
+ * @see WP_Customize_Nav_Menu_Setting::_sort_menus_by_orderby()
+ */
+ protected $_current_menus_sort_orderby;
+
+ /**
+ * Sort menu objects by the class-supplied orderby property.
+ *
+ * This is a workaround for a lack of closures.
+ *
+ * @since 4.3.0
+ * @access protected
+ * @param object $menu1
+ * @param object $menu2
+ * @return int
+ *
+ * @see WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus()
+ */
+ protected function _sort_menus_by_orderby( $menu1, $menu2 ) {
+ $key = $this->_current_menus_sort_orderby;
+ return strcmp( $menu1->$key, $menu2->$key );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Filter the wp_get_nav_menu_object() result to supply the previewed menu object.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Requesting a nav_menu object by anything but ID is not supported.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1752,6 +1842,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Storage for data to be sent back to client in customize_save_response filter.
+ *
+ * @access protected
+ * @since 4.3.0
+ * @var array
+ *
+ * @see WP_Customize_Nav_Menu_Setting::amend_customize_save_response()
+ */
+ protected $_widget_nav_menu_updates = array();
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Create/update the nav_menu term for this setting.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Any created menus will have their assigned term IDs exported to the client
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1761,7 +1862,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * To delete a menu, the client can send false as the value.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.3.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @access public
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @access protected
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @see wp_update_nav_menu_object()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1844,8 +1945,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> update_option( 'nav_menu_options', $nav_menu_options );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Make sure that new menus assigned to nav menu locations use their new IDs.
</del><span class="cx" style="display: block; padding: 0 10px"> if ( 'inserted' === $this->update_status ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Make sure that new menus assigned to nav menu locations use their new IDs.
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $this->manager->settings() as $setting ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! preg_match( '/^nav_menu_locations\[/', $setting->id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1857,6 +1958,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $setting->save();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Make sure that any nav_menu widgets referencing the placeholder nav menu get updated and sent back to client.
+ foreach ( array_keys( $this->manager->unsanitized_post_values() ) as $setting_id ) {
+ $nav_menu_widget_setting = $this->manager->get_setting( $setting_id );
+ if ( ! $nav_menu_widget_setting || ! preg_match( '/^widget_nav_menu\[/', $nav_menu_widget_setting->id ) ) {
+ continue;
+ }
+
+ $widget_instance = $nav_menu_widget_setting->post_value(); // Note that this calls WP_Customize_Widgets::sanitize_widget_instance().
+ if ( empty( $widget_instance['nav_menu'] ) || intval( $widget_instance['nav_menu'] ) !== $this->previous_term_id ) {
+ continue;
+ }
+
+ $widget_instance['nav_menu'] = $this->term_id;
+ $updated_widget_instance = $this->manager->widgets->sanitize_widget_js_instance( $widget_instance );
+ $this->manager->set_post_value( $nav_menu_widget_setting->id, $updated_widget_instance );
+ $nav_menu_widget_setting->save();
+
+ $this->_widget_nav_menu_updates[ $nav_menu_widget_setting->id ] = $updated_widget_instance;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1864,7 +1985,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Updates a nav_menu_options array.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.3.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @access public
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @access protected
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @see WP_Customize_Nav_Menu_Setting::filter_nav_menu_options()
</span><span class="cx" style="display: block; padding: 0 10px"> * @see WP_Customize_Nav_Menu_Setting::update()
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1905,6 +2026,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $data['nav_menu_updates'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['nav_menu_updates'] = array();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! isset( $data['widget_nav_menu_updates'] ) ) {
+ $data['widget_nav_menu_updates'] = array();
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $data['nav_menu_updates'][] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'term_id' => $this->term_id,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1914,6 +2038,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'saved_value' => 'deleted' === $this->update_status ? null : $this->value(),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data['widget_nav_menu_updates'] = array_merge(
+ $data['widget_nav_menu_updates'],
+ $this->_widget_nav_menu_updates
+ );
+ $this->_widget_nav_menu_updates = array();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $data;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizewidgetsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-customize-widgets.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-widgets.php 2015-07-29 14:56:23 UTC (rev 33487)
+++ trunk/src/wp-includes/class-wp-customize-widgets.php 2015-07-29 16:02:08 UTC (rev 33488)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1241,6 +1241,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function call_widget_update( $widget_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wp_registered_widget_updates, $wp_registered_widget_controls;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $setting_id = $this->get_setting_id( $widget_id );
+
+ /*
+ * Make sure that other setting changes have previewed since this widget
+ * may depend on them (e.g. Menus being present for Custom Menu widget).
+ */
+ if ( ! did_action( 'customize_preview_init' ) ) {
+ foreach ( $this->manager->settings() as $setting ) {
+ if ( $setting->id !== $setting_id ) {
+ $setting->preview();
+ }
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->start_capturing_option_updates();
</span><span class="cx" style="display: block; padding: 0 10px"> $parsed_id = $this->parse_widget_id( $widget_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $option_name = 'widget_' . $parsed_id['id_base'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1321,7 +1335,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * in place from WP_Customize_Setting::preview() will use this value
</span><span class="cx" style="display: block; padding: 0 10px"> * instead of the default widget instance value (an empty array).
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $setting_id = $this->get_setting_id( $widget_id );
</del><span class="cx" style="display: block; padding: 0 10px"> $this->manager->set_post_value( $setting_id, $instance );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Obtain the widget control with the updated instance in place.
</span></span></pre></div>
<a id="trunksrcwpincludesdefaultwidgetsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/default-widgets.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/default-widgets.php 2015-07-29 14:56:23 UTC (rev 33487)
+++ trunk/src/wp-includes/default-widgets.php 2015-07-29 16:02:08 UTC (rev 33488)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1570,28 +1570,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $menus = wp_get_nav_menus();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If no menus exists, direct the user to go and create some.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( !$menus ) {
- echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
- return;
- }
</del><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
- <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; ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
- <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
- <option value="0"><?php _e( '— Select —' ) ?></option>
- <?php
- foreach ( $menus as $menu ) {
- echo '<option value="' . $menu->term_id . '"'
- . selected( $nav_menu, $menu->term_id, false )
- . '>'. esc_html( $menu->name ) . '</option>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>>
+ <?php
+ if ( isset( $GLOBALS['wp_customize'] ) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager ) {
+ // @todo When expanding a panel, the JS should be smart enough to collapse any existing panels and sections.
+ $url = 'javascript: wp.customize.section.each(function( section ){ section.collapse(); }); wp.customize.panel( "nav_menus" ).focus();';
+ } else {
+ $url = admin_url( 'nav-menus.php' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ?>
- </select>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ?>
+ <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> </p>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <div class="nav-menu-widget-form-controls" <?php if ( empty( $menus ) ) { echo ' style="display:none" '; } ?>>
+ <p>
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ) ?></label>
+ <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 ); ?>"/>
+ </p>
+ <p>
+ <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label>
+ <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>">
+ <option value="0"><?php _e( '— Select —' ); ?></option>
+ <?php foreach ( $menus as $menu ) : ?>
+ <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $nav_menu, $menu->term_id ); ?>>
+ <?php echo esc_html( $menu->name ); ?>
+ </option>
+ <?php endforeach; ?>
+ </select>
+ </p>
+ </div>
</ins><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesnavmenuphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/nav-menu.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/nav-menu.php 2015-07-29 14:56:23 UTC (rev 33487)
+++ trunk/src/wp-includes/nav-menu.php 2015-07-29 16:02:08 UTC (rev 33488)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -12,12 +12,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $menu Menu ID, slug, or name.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $menu Menu ID, slug, or name - or the menu object.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return object|false False if $menu param isn't supplied or term does not exist, menu object if successful.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_get_nav_menu_object( $menu ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $menu_obj = false;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $menu ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( is_object( $menu ) ) {
+ $menu_obj = $menu;
+ }
+
+ if ( $menu && ! $menu_obj ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $menu_obj = get_term( $menu, 'nav_menu' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $menu_obj ) {
</span></span></pre></div>
<a id="trunktestsphpunittestscustomizenavmenusettingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/customize/nav-menu-setting.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/customize/nav-menu-setting.php 2015-07-29 14:56:23 UTC (rev 33487)
+++ trunk/tests/phpunit/tests/customize/nav-menu-setting.php 2015-07-29 16:02:08 UTC (rev 33488)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -211,6 +211,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $nav_menu_options = get_option( 'nav_menu_options', array( 'auto_add' => array() ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertContains( $menu_id, $nav_menu_options['auto_add'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $menus = wp_get_nav_menus();
+ $menus_ids = wp_list_pluck( $menus, 'term_id' );
+ $i = array_search( $menu_id, $menus_ids );
+ $this->assertNotFalse( $i, 'Update-previewed menu does not appear in wp_get_nav_menus()' );
+ $filtered_menu = $menus[ $i ];
+ $this->assertEquals( 'Name 2', $filtered_menu->name );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -249,6 +256,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $nav_menu_options = $this->get_nav_menu_items_option();
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $menus = wp_get_nav_menus();
+ $menus_ids = wp_list_pluck( $menus, 'term_id' );
+ $i = array_search( $menu_id, $menus_ids );
+ $this->assertNotFalse( $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()' );
+ $filtered_menu = $menus[ $i ];
+ $this->assertEquals( 'New Menu Name 1', $filtered_menu->name );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre>
</div>
</div>
</body>
</html>