wppaste
WordPress

WP_Customize_Nav_Menus::enqueue_scripts()

Since
4.3.0
Source
wp-includes/class-wp-customize-nav-menus.php:490
Enqueues scripts and styles for Customizer pane.

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

Reaches the database via get_terms().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
235–244

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 253.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()one call below WP_Customize_Nav_Menus::enqueue_scripts()
  • querycontent queryget_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.

WhenInstructionsCalls it makes
$num_locations === 1235–236wp_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 !== 1243–244wp_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

PHPCompiledExecutedBranchesNotes
8.6-dev251234–24322 fewer instructions than PHP 8.5
8.5253235–2442
8.4253235–24422 fewer instructions than PHP 8.3
8.3255237–2462
8.2255237–2462
8.1255237–24621 fewer instruction than PHP 7.4
7.4256238–2472

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

Show all 18

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 ) );		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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 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.