wp_enqueue_command_palette_assets()
- Since
- 6.9.0
- Source
wp-includes/script-loader.php:3498
Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.
Performance profile
How much work a call to wp_enqueue_command_palette_assets() 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
- Scales with input
- Instructions
- 4–16
- Plugin surface
- None
- Called by
- 2
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 195.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()one call below wp_enqueue_command_palette_assets() - hookthird-party callbacks
apply_filters()one call below wp_enqueue_command_palette_assets()
Further down the call graph this can also reach cache, serialize, query 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_enqueue_command_palette_assets() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$label === "" | 4 | none |
$label !== "" && !->next_token() | 16 | label(), ->next_token() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 195 | 4–16 | 30 | |
| 8.5 | 195 | 4–16 | 30 | |
| 8.4 | 195 | 4–16 | 30 | 12 fewer instructions than PHP 8.3 |
| 8.3 | 207 | 4–21 | 30 | |
| 8.2 | 207 | 4–21 | 30 | |
| 8.1 | 207 | 4–21 | 30 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 208 | 4–22 | 30 |
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 · 12
- is_network_admin()Determines whether the current request is for the network administrative interface.
- current_user_can()Returns whether the current user has the specified capability.
- wp_http_validate_url()Validates a URL as safe for use in the HTTP API.
- menu_page_url()Gets the URL to access a particular menu page based on the slug it was registered with.
- __()Retrieves the translation of $text.
- wp_enqueue_script()Enqueues a script.
- wp_enqueue_style()Enqueues a CSS stylesheet.
- wp_add_inline_script()Adds extra code to a registered script.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- WP_HTML_Tag_Processor::__construct()Constructor.
- WP_HTML_Processor::is_void()Returns whether a given element is an HTML Void Element
- WP_HTML_Decoder::decode_attribute()Returns a string containing the decoded value of a given HTML attribute.
Used by · 2
- wp_font_library_render_page()Render the font-library page.
- wp_options_connectors_render_page()Render the options-connectors page.
Source code
function wp_enqueue_command_palette_assets() { global $menu, $submenu; $command_palette_settings = array( 'is_network_admin' => is_network_admin(), ); /** * Extracts root-level text nodes from HTML string. * * @ignore * @param string $label HTML string to extract text from. * @return string Extracted text content, trimmed. */ $extract_root_text = static function ( string $label ): string { if ( '' === $label ) { return ''; } $processor = new WP_HTML_Tag_Processor( $label ); $text_parts = array(); $depth = 0; while ( $processor->next_token() ) { $token_type = $processor->get_token_type(); if ( '#text' === $token_type ) { if ( 0 === $depth ) { $text_parts[] = $processor->get_modifiable_text(); } continue; } if ( '#tag' !== $token_type ) { continue; } if ( $processor->is_tag_closer() ) { if ( $depth > 0 ) { --$depth; } continue; } $token_name = $processor->get_tag(); if ( $token_name && ! WP_HTML_Processor::is_void( $token_name ) ) { ++$depth; } } return trim( implode( '', $text_parts ) ); }; if ( $menu ) { $menu_commands = array(); foreach ( $menu as $menu_item ) { if ( empty( $menu_item[0] ) || ! is_string( $menu_item[0] ) || ! empty( $menu_item[1] ) && ! current_user_can( $menu_item[1] ) ) { continue; } $menu_label = $extract_root_text( $menu_item[0] ); $menu_url = ''; $menu_slug = $menu_item[2]; if ( preg_match( '/\.php($|\?)/', $menu_slug ) || wp_http_validate_url( $menu_slug ) ) { $menu_url = $menu_slug; } elseif ( ! empty( menu_page_url( $menu_slug, false ) ) ) { $menu_url = WP_HTML_Decoder::decode_attribute( menu_page_url( $menu_slug, false ) ); } if ( $menu_url ) { $menu_commands[] = array( 'label' => $menu_label, 'url' => $menu_url, 'name' => $menu_slug, ); } if ( array_key_exists( $menu_slug, $submenu ) ) { foreach ( $submenu[ $menu_slug ] as $submenu_item ) {Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/script-loader.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.