Ticket #32814: 32814.6.diff
File 32814.6.diff, 7.7 KB (added by , 10 years ago) |
---|
-
src/wp-admin/js/customize-nav-menus.js
diff --git src/wp-admin/js/customize-nav-menus.js src/wp-admin/js/customize-nav-menus.js index e745561..b1cd591 100644
1111 1111 control.getMenuControl().debouncedReflowMenuItems(); 1112 1112 } 1113 1113 } 1114 1115 // After updating, refresh any custom menu widgets containing this menu. 1116 control.getMenuControl()._resetCustomMenuWidgets( control.getMenuControl() ); 1117 1114 1118 }); 1115 1119 }, 1116 1120 … … 1651 1655 select.append( new Option( name, menuId ) ); 1652 1656 } 1653 1657 } ); 1654 $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first' ).append( new Option( name, menuId ) );1655 1658 } 1656 1659 }, 1657 1660 … … 1695 1698 var select = widgetControl.container.find( 'select' ); 1696 1699 select.find( 'option[value=' + String( menuId ) + ']' ).text( name ); 1697 1700 }); 1698 $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first option[value=' + String( menuId ) + ']' ).text( name );1699 1701 } 1700 1702 } ); 1701 1703 … … 1707 1709 }, 1708 1710 1709 1711 /** 1712 * Helper function to keep custom menu widgets in sync with menu changes. 1713 * 1714 * Whenever a menu is changed, ensure any custom menu widgets also get refreshed. 1715 */ 1716 _resetCustomMenuWidgets: function( control ) { 1717 api.control.each( function( widgetControl ) { 1718 if ( ! widgetControl.extended( api.controlConstructor.widget_form ) || 'nav_menu' !== widgetControl.params.widget_id_base ) { 1719 return; 1720 } 1721 var select, option; 1722 select = widgetControl.container.find( 'select' ); 1723 option = select.find( 'option[value=' + control.id.match(/(-?\d+)/)[0] + ']' ); 1724 if ( option.length > 0 ) { 1725 widgetControl.previewer.trigger( 'refresh' ); 1726 } 1727 }); 1728 }, 1729 1730 /** 1710 1731 * Allow items in each menu to be re-ordered, and for the order to be previewed. 1711 1732 * 1712 1733 * Notice that the UI aspects here are handled by wpNavMenu.initSortables() … … 1767 1788 menuItemControl.setting.set( setting ); 1768 1789 }); 1769 1790 }); 1770 });1771 1791 1792 // After sorting, refresh any custom menu widgets containing this menu. 1793 control._resetCustomMenuWidgets( control ); 1794 1795 }); 1772 1796 control.isReordering = false; 1773 1797 1774 1798 /** … … 1835 1859 } 1836 1860 select.find( 'option[value=' + String( menuId ) + ']' ).remove(); 1837 1861 }); 1838 $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first option[value=' + String( menuId ) + ']' ).remove(); 1862 1863 // After deleting, refresh any custom menu widgets containing this menu. 1864 control._resetCustomMenuWidgets( control ); 1839 1865 }, 1840 1866 1841 1867 // Setup theme location checkboxes. … … 2232 2258 2233 2259 // Focus on the new menu section. 2234 2260 api.section( customizeId ).focus(); // @todo should we focus on the new menu's control and open the add-items panel? Thinking user flow... 2261 2262 // Fix an issue with extra space at top immediately after creating new menu. 2263 $( '#menu-to-edit' ).css( 'margin-top', 0 ); 2235 2264 } 2236 2265 }); 2237 2266 … … 2370 2399 } 2371 2400 } ); 2372 2401 2402 /** 2403 * Update the saved menu in any custom menu widgets. 2404 * If the previous_term_id item is selected, reselect the 2405 * item with the updated term_id. 2406 */ 2407 api.control.each( function( setting ) { 2408 // Only act on nav_menu widgets. 2409 if ( ! setting.extended( api.controlConstructor.widget_form ) || 2410 'nav_menu' !== setting.params.widget_id_base ) { 2411 return; 2412 } 2413 var select, oldMenuOption, oldMenuSelected, newMenuOption; 2414 select = setting.container.find( 'select' ); 2415 oldMenuOption = select.find( 'option[value=' + String( update.previous_term_id ) + ']' ); 2416 oldMenuSelected = select.find( 'option[value=' + String( update.previous_term_id ) + ']:selected' ); 2417 newMenuOption = select.find( 'option[value=' + String( update.term_id ) + ']' ); 2418 2419 // Adjust menu options matching the old ID, setting them to the new ID. 2420 if ( oldMenuSelected.length !== 0 ) { 2421 newMenuOption.attr( 'selected', true ); 2422 } 2423 2424 // Remove the old option. 2425 oldMenuOption.remove(); 2426 } ); 2427 2373 2428 if ( oldSection.expanded.get() ) { 2374 2429 // @todo This doesn't seem to be working. 2375 2430 newSection.expand(); -
src/wp-admin/js/customize-widgets.js
diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js index 2907b4f..f56a048 100644
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 ); -
src/wp-includes/class-wp-customize-nav-menus.php
diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php index e7b7e0f..46a3e2f 100644
final class WP_Customize_Nav_Menus { 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 64 } 65 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 // Newly-created menus always have a negative ID. 73 if ( is_int( $menu ) && $menu < 0 ) { 74 // Check to see if there is a customized menu item matching this id. 75 if ( isset( $_POST['customized'] ) && current_user_can( 'customize' ) ) { 76 $customized = json_decode( wp_unslash( $_POST['customized'] ), true ); 77 if ( ! empty( $customized ) ) { 78 $item_key = 'nav_menu_item[' . $menu . ']'; 79 if ( isset( $customized[ $item_key ] ) ) { 80 $menu_item = $customized[ $item_key ]; 81 } 82 83 if ( isset( $menu_item ) ) { 84 85 // Initialize the $menu_obj, required for PHP 5.2 compatibility. 86 $menu_obj = new stdClass(); 87 88 // Build menu object from the customized data. 89 $menu_obj->term_id = $menu; 90 $menu_obj->name = isset( $menu_item['name'] ) ? $menu_item['name'] : ''; 91 $menu_obj->slug = sanitize_title( $menu_obj->name ); 92 $menu_obj->term_group = 0; 93 $menu_obj->term_taxonomy_id = $menu; 94 $menu_obj->taxonomy = 'nav_menu'; 95 $menu_obj->parent = isset( $menu_item['parent'] ) ? $menu_item['parent'] : ''; 96 $menu_obj->count = isset( $menu_item['count'] ) ? $menu_item['count'] : ''; 97 $menu_obj->description = isset( $menu_item['description'] ) ? $menu_item['description'] : ''; 98 $menu_obj->filter = isset( $menu_item['filter'] ) ? $menu_item['filter'] : ''; 99 $menu_obj->ID = $menu; 100 } else { 101 $menu_obj = false; 102 } 103 } 104 } 105 } 106 return $menu_obj; 62 107 } 63 108 64 109 /** -
src/wp-includes/nav-menu.php
diff --git src/wp-includes/nav-menu.php src/wp-includes/nav-menu.php index d255859..fc681b8 100644
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 ) {