WP_Customize_Nav_Menus::enqueue_scripts()
Enqueue scripts and styles for Customizer pane.
Source
File: wp-includes/class-wp-customize-nav-menus.php
public function enqueue_scripts() { wp_enqueue_style( 'customize-nav-menus' ); wp_enqueue_script( 'customize-nav-menus' ); $temp_nav_menu_setting = new WP_Customize_Nav_Menu_Setting( $this->manager, 'nav_menu[-1]' ); $temp_nav_menu_item_setting = new WP_Customize_Nav_Menu_Item_Setting( $this->manager, 'nav_menu_item[-1]' ); $num_locations = count( get_registered_nav_menus() ); if ( 1 === $num_locations ) { $locations_description = __( 'Your theme can display menus in one location.' ); } else { /* translators: %s: Number of menu locations. */ $locations_description = sprintf( _n( 'Your theme can display menus in %s location.', 'Your theme can display menus in %s locations.', $num_locations ), number_format_i18n( $num_locations ) ); } // Pass data to JS. $settings = array( 'allMenus' => wp_get_nav_menus(), 'itemTypes' => $this->available_item_types(), 'l10n' => array( 'untitled' => _x( '(no label)', 'missing menu item navigation label' ), 'unnamed' => _x( '(unnamed)', 'Missing menu name.' ), 'custom_label' => __( 'Custom Link' ), 'page_label' => get_post_type_object( 'page' )->labels->singular_name, /* translators: %s: Menu location. */ 'menuLocation' => _x( '(Currently set to: %s)', 'menu' ), 'locationsTitle' => 1 === $num_locations ? __( 'Menu Location' ) : __( 'Menu Locations' ), 'locationsDescription' => $locations_description, 'menuNameLabel' => __( 'Menu Name' ), 'newMenuNameDescription' => __( 'If your theme has multiple menus, giving them clear names will help you manage them.' ), 'itemAdded' => __( 'Menu item added' ), 'itemDeleted' => __( 'Menu item deleted' ), 'menuAdded' => __( 'Menu created' ), 'menuDeleted' => __( 'Menu deleted' ), 'movedUp' => __( 'Menu item moved up' ), 'movedDown' => __( 'Menu item moved down' ), 'movedLeft' => __( 'Menu item moved out of submenu' ), 'movedRight' => __( 'Menu item is now a sub-item' ), /* translators: ▸ is the unicode right-pointing triangle. %s: Section title in the Customizer. */ 'customizingMenus' => sprintf( __( 'Customizing ▸ %s' ), esc_html( $this->manager->get_panel( 'nav_menus' )->title ) ), /* translators: %s: Title of an invalid menu item. */ 'invalidTitleTpl' => __( '%s (Invalid)' ), /* translators: %s: Title of a menu item in draft status. */ 'pendingTitleTpl' => __( '%s (Pending)' ), /* translators: %d: Number of menu items found. */ 'itemsFound' => __( 'Number of items found: %d' ), /* translators: %d: Number of additional menu items found. */ 'itemsFoundMore' => __( 'Additional items found: %d' ), 'itemsLoadingMore' => __( 'Loading more results... please wait.' ), 'reorderModeOn' => __( 'Reorder mode enabled' ), 'reorderModeOff' => __( 'Reorder mode closed' ), 'reorderLabelOn' => esc_attr__( 'Reorder menu items' ), 'reorderLabelOff' => esc_attr__( 'Close reorder mode' ), ), 'settingTransport' => 'postMessage', 'phpIntMax' => PHP_INT_MAX, 'defaultSettingValues' => array( 'nav_menu' => $temp_nav_menu_setting->default, 'nav_menu_item' => $temp_nav_menu_item_setting->default, ), 'locationSlugMappedToName' => get_registered_nav_menus(), ); $data = sprintf( 'var _wpCustomizeNavMenusSettings = %s;', wp_json_encode( $settings ) ); wp_scripts()->add_data( 'customize-nav-menus', 'data', $data ); // This is copied from nav-menus.php, and it has an unfortunate object name of `menus`. $nav_menus_l10n = array( 'oneThemeLocationNoMenus' => null, 'moveUp' => __( 'Move up one' ), 'moveDown' => __( 'Move down one' ), 'moveToTop' => __( 'Move to the top' ), /* translators: %s: Previous item name. */ 'moveUnder' => __( 'Move under %s' ), /* translators: %s: Previous item name. */ 'moveOutFrom' => __( 'Move out from under %s' ), /* translators: %s: Previous item name. */ 'under' => __( 'Under %s' ), /* translators: %s: Previous item name. */ 'outFrom' => __( 'Out from under %s' ), /* translators: 1: Item name, 2: Item position, 3: Total number of items. */ 'menuFocus' => __( '%1$s. Menu item %2$d of %3$d.' ), /* translators: 1: Item name, 2: Item position, 3: Parent item name. */ 'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ), ); wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n ); }
Changelog
Version | Description |
---|---|
4.3.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_customize_nav_menus/enqueue_scripts