Ticket #32814: 32814.3.diff
File 32814.3.diff, 7.6 KB (added by , 10 years ago) |
---|
-
wp-admin/js/customize-nav-menus.js
1111 1111 control.getMenuControl().debouncedReflowMenuItems(); 1112 1112 } 1113 1113 } 1114 /** 1115 * After updating, refresh any custom menu widgets containing this menu. 1116 */ 1117 control.getMenuControl()._resetCustomMenuWidgets( control.getMenuControl() ); 1118 1114 1119 }); 1115 1120 }, 1116 1121 … … 1651 1656 select.append( new Option( name, menuId ) ); 1652 1657 } 1653 1658 } ); 1654 $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first' ).append( new Option( name, menuId ) );1655 1659 } 1656 1660 }, 1657 1661 … … 1695 1699 var select = widgetControl.container.find( 'select' ); 1696 1700 select.find( 'option[value=' + String( menuId ) + ']' ).text( name ); 1697 1701 }); 1698 $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first option[value=' + String( menuId ) + ']' ).text( name );1699 1702 } 1700 1703 } ); 1701 1704 … … 1707 1710 }, 1708 1711 1709 1712 /** 1713 * Helper function to keep custom menu widgets in sync with menu changes. 1714 * 1715 * Whenever a menu is changed, ensure any custom menu widgets also get refreshed. 1716 */ 1717 _resetCustomMenuWidgets: function( control ) { 1718 api.control.each( function( widgetControl ) { 1719 if ( ! widgetControl.extended( api.controlConstructor.widget_form ) || 'nav_menu' !== widgetControl.params.widget_id_base ) { 1720 return; 1721 } 1722 var 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 }); 1791 /** 1792 * After sorting, refresh any custom menu widgets containing this menu. 1793 */ 1794 control._resetCustomMenuWidgets( control ); 1795 1770 1796 }); 1771 1772 1797 control.isReordering = false; 1773 1798 1774 1799 /** … … 1835 1860 } 1836 1861 select.find( 'option[value=' + String( menuId ) + ']' ).remove(); 1837 1862 }); 1838 $( '#available-widgets-list .widget-inside:has(input.id_base[value=nav_menu]) select:first option[value=' + String( menuId ) + ']' ).remove(); 1863 1864 /** 1865 * After deleting, refresh any custom menu widgets containing this menu. 1866 */ 1867 control._resetCustomMenuWidgets( control ); 1839 1868 }, 1840 1869 1841 1870 // Setup theme location checkboxes. … … 2232 2261 2233 2262 // Focus on the new menu section. 2234 2263 api.section( customizeId ).focus(); // @todo should we focus on the new menu's control and open the add-items panel? Thinking user flow... 2264 // Fix an issue with extra space at top immediately after creating new menu. 2265 $( "#menu-to-edit" ).css( 'margin-top', 0 ); 2235 2266 } 2236 2267 }); 2237 2268 … … 2359 2390 oldSetting.preview(); 2360 2391 newSetting.preview(); 2361 2392 2393 /** 2394 * Update the saved menu in any custom menu widgets. 2395 * If the previous_term_id item is selected, reselect the 2396 * item with the updated term_id. 2397 */ 2398 api.control.each( function( setting ) { 2399 /** 2400 * Only act on nav_menu widgets 2401 */ 2402 if ( ! setting.extended( api.controlConstructor.widget_form ) || 2403 'nav_menu' !== setting.params.widget_id_base ) { 2404 return; 2405 } 2406 var select = setting.container.find( 'select' ); 2407 var oldMenuOption = select.find( 'option[value=' + String( update. 2408 previous_term_id ) + ']' ); 2409 2410 /** 2411 * Adjust menu options matching the old ID, setting them to the new ID. 2412 */ 2413 if ( oldMenuOption.length !== 0 ) { 2414 oldMenuOption.attr( 'value', update.term_id ); 2415 } 2416 } ); 2417 2362 2418 // Update nav_menu_locations to reference the new ID. 2363 2419 api.each( function( setting ) { 2364 2420 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 $item_key = 'nav_menu_item[' . $menu . ']'; 83 if ( isset( $customized[ $item_key ] ) ) { 84 $menu_item = $customized[ $item_key ]; 85 } 86 87 if ( isset( $menu_item ) ) { 88 89 /** 90 * Initialize the $menu_obj, required for PHP 5.2 compatibility. 91 */ 92 $menu_obj = new stdClass(); 93 94 /** 95 * Build menu object from the customized data. 96 */ 97 $menu_obj->term_id = (int) $menu; 98 $menu_obj->name = $menu_item['name']; 99 $menu_obj->slug = sanitize_title( $menu_obj->name ); 100 $menu_obj->term_group = 0; 101 $menu_obj->term_taxonomy_id = (int) $menu; 102 $menu_obj->taxonomy = 'nav_menu'; 103 $menu_obj->parent = $menu_item['parent']; 104 $menu_obj->count = isset( $menu_item['count'] ) ? $menu_item['count'] : ''; 105 $menu_obj->description = $menu_item['description']; 106 $menu_obj->filter = isset( $menu_item['filter'] ) ? $menu_item['filter'] : ''; 107 $menu_obj->ID = (int) $menu; 108 } else { 109 $menu_obj = false; 110 } 111 } 112 } 113 } 114 return $menu_obj; 115 } 116 117 /** 65 118 * Ajax handler for loading available menu items. 66 119 * 67 120 * @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 ) {