Ticket #32814: 32814.2.diff
File 32814.2.diff, 6.8 KB (added by , 10 years ago) |
---|
-
wp-admin/js/customize-nav-menus.js
1651 1651 select.append( new Option( name, menuId ) ); 1652 1652 } 1653 1653 } ); 1654 $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first' ).append( new Option( name, menuId ) );1655 1654 } 1656 1655 }, 1657 1656 … … 1695 1694 var select = widgetControl.container.find( 'select' ); 1696 1695 select.find( 'option[value=' + String( menuId ) + ']' ).text( name ); 1697 1696 }); 1698 $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first option[value=' + String( menuId ) + ']' ).text( name );1699 1697 } 1700 1698 } ); 1701 1699 … … 1707 1705 }, 1708 1706 1709 1707 /** 1708 * Whenever a menu is changed, ensure any custom menu widgets also get refreshed. 1709 */ 1710 _resetCustomMenuWidgets: function() { 1711 api.each( function( setting ) { 1712 setting.preview(); 1713 } ); 1714 }, 1715 1716 /** 1710 1717 * Allow items in each menu to be re-ordered, and for the order to be previewed. 1711 1718 * 1712 1719 * Notice that the UI aspects here are handled by wpNavMenu.initSortables() … … 1767 1774 menuItemControl.setting.set( setting ); 1768 1775 }); 1769 1776 }); 1777 control._resetCustomMenuWidgets(); 1770 1778 }); 1771 1772 1779 control.isReordering = false; 1773 1780 1774 1781 /** … … 1835 1842 } 1836 1843 select.find( 'option[value=' + String( menuId ) + ']' ).remove(); 1837 1844 }); 1838 $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first option[value=' + String( menuId ) + ']' ).remove();1845 control._resetCustomMenuWidgets(); 1839 1846 }, 1840 1847 1841 1848 // Setup theme location checkboxes. … … 2232 2239 2233 2240 // Focus on the new menu section. 2234 2241 api.section( customizeId ).focus(); // @todo should we focus on the new menu's control and open the add-items panel? Thinking user flow... 2242 // Fix an issue with extra space at top immediately after creating new menu. 2243 $( "#menu-to-edit" ).css( 'margin-top', 0 ); 2235 2244 } 2236 2245 }); 2237 2246 … … 2359 2368 oldSetting.preview(); 2360 2369 newSetting.preview(); 2361 2370 2371 /** 2372 * Update the saved menu in any custom menu widgets. 2373 * If the previous_term_id item is selected, reselect the 2374 * item with the updated term_id. 2375 */ 2376 api.control.each( function( setting ) { 2377 /** 2378 * Only act on nav_menu widgets 2379 */ 2380 if ( ! setting.extended( api.controlConstructor.widget_form ) || 2381 'nav_menu' !== setting.params.widget_id_base ) { 2382 return; 2383 } 2384 var select = setting.container.find( 'select' ); 2385 var oldMenuOption = select.find( 'option[value=' + String( update. 2386 previous_term_id ) + ']' ); 2387 2388 /** 2389 * Adjust menu options matching the old ID, setting them to the new ID. 2390 */ 2391 if ( oldMenuOption.length !== 0 ) { 2392 console.log( oldMenuOption ); 2393 oldMenuOption.attr( 'value', update.term_id ); 2394 } 2395 } ); 2396 2362 2397 // Update nav_menu_locations to reference the new ID. 2363 2398 api.each( function( setting ) { 2364 2399 var wasSaved = api.state( 'saved' ).get(); -
wp-admin/js/customize-widgets.js
1041 1041 params.wp_customize = 'on'; 1042 1042 params.nonce = api.Widgets.data.nonce; 1043 1043 params.theme = api.settings.theme.stylesheet; 1044 params.customized = wp.customize.previewer.query().customized; 1044 1045 1045 1046 data = $.param( params ); 1046 1047 $inputs = this._getInputs( $widgetContent ); -
wp-includes/class-wp-customize-nav-menus.php
59 59 add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_templates' ) ); 60 60 add_action( 'customize_controls_print_footer_scripts', array( $this, 'available_items_template' ) ); 61 61 add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) ); 62 add_filter( 'wp_get_nav_menu_object', array( $this, 'filter_nav_menu_object' ), 10, 2 ); 63 62 64 } 63 65 64 66 /** 67 * Filter the nav menu object to inject `customized` menus. 68 * 69 * @since 4.3.0 70 */ 71 public function filter_nav_menu_object( $menu_obj, $menu ) { 72 /** 73 * Customized menus always have a negative ID. 74 */ 75 if ( is_int( $menu ) && $menu < 0 ) { 76 /** 77 * Check to see if there is a customized menu item matching this id. 78 */ 79 if ( isset( $_POST['customized'] ) && current_user_can( 'customize' ) ) { 80 $customized = json_decode( wp_unslash( $_POST['customized'] ), true ); 81 if ( ! empty( $customized ) ) { 82 $menu_key = 'nav_menu[' . $menu . ']'; 83 $item_key = 'nav_menu_item[' . $menu . ']'; 84 if ( isset( $customized[ $menu_key ] ) ) { 85 $menu_item = $customized[ $menu_key ]; 86 } else if ( isset( $customized[ $item_key ] ) ) { 87 $menu_item = $customized[ $item_key ]; 88 } 89 90 if ( isset( $menu_item ) ) { 91 92 /** 93 * Initialize the $menu_obj, required for PHP 5.2 compatibility. 94 */ 95 $menu_obj = new stdClass(); 96 97 /** 98 * Build menu object from the customized data. 99 */ 100 $menu_obj->name = $menu_item['name']; 101 $menu_obj->parent = $menu_item['parent']; 102 $menu_obj->term_id = (int) $menu; 103 $menu_obj->term_taxonomy_id = (int) $menu; 104 $menu_obj->slug = sanitize_title( $menu_obj->name ); 105 $menu_obj->taxonomy = 'nav_menu'; 106 $menu_obj->count = isset( $menu_item['count'] ) ? $menu_item['count'] : ''; 107 $menu_obj->description = $menu_item['description']; 108 $menu_obj->filter = isset( $menu_item['raw'] ) ? $menu_item['raw'] : ''; 109 $menu_obj->ID = (int) $menu; 110 } else { 111 $menu_obj = false; 112 } 113 } 114 } 115 } 116 return $menu_obj; 117 } 118 119 120 /** 65 121 * Ajax handler for loading available menu items. 66 122 * 67 123 * @since 4.3.0 -
wp-includes/nav-menu.php
12 12 * 13 13 * @since 3.0.0 14 14 * 15 * @param string $menu Menu ID, slug, or name .15 * @param string $menu Menu ID, slug, or name - or the menu object. 16 16 * @return object|false False if $menu param isn't supplied or term does not exist, menu object if successful. 17 17 */ 18 18 function wp_get_nav_menu_object( $menu ) { 19 19 $menu_obj = false; 20 if ( $menu ) { 20 21 if ( is_object( $menu ) ) { 22 $menu_obj = $menu; 23 } 24 25 if ( $menu && ! $menu_obj ) { 21 26 $menu_obj = get_term( $menu, 'nav_menu' ); 22 27 23 28 if ( ! $menu_obj ) {