_wp_menu_output( array $menu, array $submenu, bool $submenu_as_parent = true )
- Since
- 2.7.0
- Source
wp-admin/menu-header.php:73
Compatibility
- WordPress
- since 2.7.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.
Parameters
Performance profile
How much work a call to _wp_menu_output() 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
- Light
- Scaling
- Scales with input
- Instructions
- 23–24
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 521.
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_menu_output()
Further down the call graph this can also reach option, 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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost _wp_menu_output() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 23–24 | esc_attr__(), __() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 521 | 23–24 | 62 | |
| 8.5 | 521 | 23–24 | 62 | |
| 8.4 | 521 | 23–24 | 62 | 42 fewer instructions than PHP 8.3 |
| 8.3 | 563 | 23–24 | 62 | |
| 8.2 | 563 | 23–24 | 62 | |
| 8.1 | 563 | 23–24 | 62 | 8 fewer instructions than PHP 7.4 |
| 7.4 | 571 | 23–24 | 62 |
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 · 11
- esc_attr()Escaping for HTML attributes.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- esc_url()Checks and cleans a URL.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- sanitize_html_class()Sanitizes an HTML classname to ensure it only contains valid characters.
- wptexturize()Replaces common plain text characters with formatted entities.
- get_plugin_page_hook()Gets the hook attached to the administrative page of a plugin.
- current_user_can()Returns whether the current user has the specified capability.
- add_query_arg()Retrieves a modified URL query string.
- esc_attr__()Retrieves the translation of $text and escapes it for safe use in an attribute.
- __()Retrieves the translation of $text.
Source code
function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { global $self, $parent_file, $submenu_file, $plugin_page, $typenow; $first = true; // 0 = menu_title, 1 = capability, 2 = menu_slug, 3 = page_title, 4 = classes, 5 = hookname, 6 = icon_url. foreach ( $menu as $key => $item ) { $admin_is_parent = false; $class = array(); $aria_attributes = ''; $aria_hidden = ''; $is_separator = false; if ( $first ) { $class[] = 'wp-first-item'; $first = false; } $submenu_items = array(); if ( ! empty( $submenu[ $item[2] ] ) ) { $class[] = 'wp-has-submenu'; $submenu_items = $submenu[ $item[2] ]; } if ( ( $parent_file && $item[2] === $parent_file ) || ( empty( $typenow ) && $self === $item[2] ) ) { if ( ! empty( $submenu_items ) ) { $class[] = 'wp-has-current-submenu wp-menu-open'; } else { $class[] = 'current'; $aria_attributes .= 'aria-current="page"'; } } else { $class[] = 'wp-not-current-submenu'; if ( ! empty( $submenu_items ) ) { $aria_attributes .= 'data-ariahaspopup'; } } if ( ! empty( $item[4] ) ) { $class[] = esc_attr( $item[4] ); } $class = $class ? ' class="' . implode( ' ', $class ) . '"' : ''; $id = ! empty( $item[5] ) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : ''; $img = ''; $img_style = ''; $img_class = ' dashicons-before'; if ( str_contains( $class, 'wp-menu-separator' ) ) { $is_separator = true; } /* * If the string 'none' (previously 'div') is passed instead of a URL, don't output * the default menu image so an icon can be added to div.wp-menu-image as background * with CSS. Dashicons and base64-encoded data:image/svg_xml URIs are also handled * as special cases. */ if ( ! empty( $item[6] ) ) { $img = '<img src="' . esc_url( $item[6] ) . '" alt="" />'; if ( 'none' === $item[6] || 'div' === $item[6] ) { $img = '<br />'; } elseif ( str_starts_with( $item[6], 'data:image/svg+xml;base64,' ) ) { $img = '<br />'; // The value is base64-encoded data, so esc_attr() is used here instead of esc_url(). $img_style = ' style="background-image:url(\'' . esc_attr( $item[6] ) . '\')"'; $img_class = ' svg'; } elseif ( str_starts_with( $item[6], 'dashicons-' ) ) { $img = '<br />'; $img_class = ' dashicons-before ' . sanitize_html_class( $item[6] ); } } $title = wptexturize( $item[0] ); // Hide separators from screen readers. if ( $is_separator ) { $aria_hidden = ' aria-hidden="true"'; }Changelog
Introduced in 2.7.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 6.9.7 tag, from
src/wp-admin/menu-header.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.