WP_Customize_Nav_Menus::enqueue_scripts()
- Since
- 4.3.0
- Source
wp-includes/class-wp-customize-nav-menus.php:494
Compatibility
- WordPress
- since 4.3.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Performance profile
How much work a call to WP_Customize_Nav_Menus::enqueue_scripts() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 236–245
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_terms().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 254.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_Customize_Nav_Menus::enqueue_scripts() - querycontent query
get_terms()one call below WP_Customize_Nav_Menus::enqueue_scripts()
Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Nav_Menus::enqueue_scripts() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$num_locations === 1 | 236–237 | wp_enqueue_style(), wp_enqueue_script(), get_registered_nav_menus(), __(), wp_get_nav_menus(), ->available_item_types(), _x(), _x(), __(), get_post_type_object(), _x(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), ->get_panel(), esc_html(), sprintf(), __(), __(), __(), __(), __(), __(), __(), esc_attr__(), esc_attr__(), get_registered_nav_menus(), wp_json_encode(), wp_scripts(), ->add_data(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), wp_localize_script() |
$num_locations !== 1 | 244–245 | wp_enqueue_style(), wp_enqueue_script(), get_registered_nav_menus(), _n(), number_format_i18n(), sprintf(), wp_get_nav_menus(), ->available_item_types(), _x(), _x(), __(), get_post_type_object(), _x(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), ->get_panel(), esc_html(), sprintf(), __(), __(), __(), __(), __(), __(), __(), esc_attr__(), esc_attr__(), get_registered_nav_menus(), wp_json_encode(), wp_scripts(), ->add_data(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), wp_localize_script() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 252 | 235–244 | 2 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 254 | 236–245 | 2 | |
| 8.4 | 254 | 236–245 | 2 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 256 | 238–247 | 2 | |
| 8.2 | 256 | 238–247 | 2 | |
| 8.1 | 256 | 238–247 | 2 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 257 | 239–248 | 2 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 18
- wp_enqueue_style()Enqueues a CSS stylesheet.
- wp_enqueue_script()Enqueues a script.
- get_registered_nav_menus()Retrieves all registered navigation menu locations in a theme.
- __()Retrieves the translation of $text.
- _n()Translates and retrieves the singular or plural form based on the supplied number.
- number_format_i18n()Converts float number to format based on the locale.
- wp_get_nav_menus()Returns all navigation menu objects.
- _x()Retrieves translated string with gettext context.
- get_post_type_object()Retrieves a post type object by name.
- esc_html()Escaping for HTML blocks.
- esc_attr__()Retrieves the translation of $text and escapes it for safe use in an attribute.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
Show all 18
- wp_scripts()Initializes $wp_scripts if it has not been set.
- wp_localize_script()Localizes a script.
- WP_Customize_Nav_Menu_Setting::__construct()Constructor.
- WP_Customize_Nav_Menu_Item_Setting::__construct()Constructor.
- WP_Customize_Nav_Menus::available_item_types()Returns an array of all the available item types.
- wp_scripts()::add_data()
Source code
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, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ); 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. */Changelog
Introduced in 4.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-customize-nav-menus.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.