Walker_Nav_Menu::start_el( string $output, WP_Post $data_object, int $depth = 0, stdClass $args = null, int $current_object_id = 0 )
- Since
- 3.0.0, 4.4.0, 5.9.0, 6.7.0
- Source
wp-includes/class-walker-nav-menu.php:139
Compatibility
- WordPress
- since 6.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
$outputstring- Used to append additional content (passed by reference).
$data_objectWP_Post- Menu item data object.
$depthintoptional- Depth of menu item. Used for padding.Default:
0 $argsstdClassoptional- An object of wp_nav_menu() arguments.Default:
null $current_object_idintoptional- ID of the current menu item. Default 0.Default:
0
Performance profile
How much work a call to Walker_Nav_Menu::start_el() 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
- Moderate
- Scaling
- Constant
- Instructions
- 152–211
- Plugin surface
- 8 hooks
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 230.
Third-party callbacks on 'nav_menu_item_args', 'nav_menu_css_class', 'nav_menu_item_id' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()one call below Walker_Nav_Menu::start_el()
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 · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost Walker_Nav_Menu::start_el() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($menu_item) | 152–157 | apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters() |
!isset($args) && empty($menu_item) | 157–162 | str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters() |
| always | 159–170 | apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), get_privacy_policy_url(), apply_filters(), ->build_atts(), apply_filters() |
| always | 164–169 | apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
!isset($args) | 164–175 | str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), get_privacy_policy_url(), apply_filters(), ->build_atts(), apply_filters() |
!isset($args) | 169–174 | str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
!empty($menu_item) | 171–182 | apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), get_privacy_policy_url(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
| always | 175–180 | apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), strtolower(), strtolower(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
!isset($args) && !empty($menu_item) | 176–187 | str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), get_privacy_policy_url(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
!isset($args) | 180–185 | str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), strtolower(), strtolower(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
!empty($menu_item) | 182–193 | apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), get_privacy_policy_url(), strtolower(), strtolower(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
| always | 186–193 | apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), strtolower(), strtolower(), strtolower(), strtolower(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
4 further outcomes, up to 211 instructions
!isset($args) && !empty($menu_item) | 187–198 | str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), get_privacy_policy_url(), strtolower(), strtolower(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
!isset($args) | 191–198 | str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), strtolower(), strtolower(), strtolower(), strtolower(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
!empty($menu_item) | 193–206 | apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), get_privacy_policy_url(), strtolower(), strtolower(), strtolower(), strtolower(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
!isset($args) && !empty($menu_item) | 198–211 | str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), get_privacy_policy_url(), strtolower(), strtolower(), strtolower(), strtolower(), strtolower(), strtolower(), apply_filters(), ->build_atts(), apply_filters() |
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 | 229 | 152–210 | 16 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 230 | 152–211 | 16 | |
| 8.4 | 230 | 152–211 | 16 | 16 fewer instructions than PHP 8.3 |
| 8.3 | 246 | 156–227 | 16 | |
| 8.2 | 246 | 156–227 | 16 | |
| 8.1 | 246 | 156–227 | 16 | 4 fewer instructions than PHP 7.4 |
| 7.4 | 250 | 156–231 | 16 |
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.
Hooks and filters fired · 8
8 hooks fire while Walker_Nav_Menu::start_el() runs, in this order:
- apply_filters( nav_menu_item_args )filterline 164 (+25 into the body)
Filters the arguments for a single nav menu item.
- apply_filters( nav_menu_css_class )filterline 177 (+38 into the body)
Filters the CSS classes applied to a menu item's list item element.
- apply_filters( nav_menu_item_id )filterline 190 (+51 into the body)
Filters the ID attribute applied to a menu item's list item element.
- apply_filters( nav_menu_item_attributes )filterline 211 (+72 into the body)
Filters the HTML attributes applied to a menu's list item element.
- apply_filters( nav_menu_link_attributes )filterline 280 (+141 into the body)
Filters the HTML attributes applied to a menu item's anchor element.
- apply_filters( walker_nav_menu_start_el )filterline 303 (+164 into the body)
Filters a menu item's starting output.
Uses · 3
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_privacy_policy_url()Retrieves the URL to the privacy policy page.
- Walker_Nav_Menu::build_atts()Builds a string of HTML attributes from an array of key/value pairs.
Source code
public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) { // Restores the more descriptive, specific name for use within this method. $menu_item = $data_object; if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; } else { $t = "\t"; $n = "\n"; } $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; $classes = empty( $menu_item->classes ) ? array() : (array) $menu_item->classes; $classes[] = 'menu-item-' . $menu_item->ID; /** * Filters the arguments for a single nav menu item. * * @since 4.4.0 * * @param stdClass $args An object of wp_nav_menu() arguments. * @param WP_Post $menu_item Menu item data object. * @param int $depth Depth of menu item. Used for padding. */ $args = apply_filters( 'nav_menu_item_args', $args, $menu_item, $depth ); /** * Filters the CSS classes applied to a menu item's list item element. * * @since 3.0.0 * @since 4.1.0 The `$depth` parameter was added. * * @param string[] $classes Array of the CSS classes that are applied to the menu item's `<li>` element. * @param WP_Post $menu_item The current menu item object. * @param stdClass $args An object of wp_nav_menu() arguments. * @param int $depth Depth of menu item. Used for padding. */ $class_names = implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $menu_item, $args, $depth ) ); /** * Filters the ID attribute applied to a menu item's list item element. * * @since 3.0.1 * @since 4.1.0 The `$depth` parameter was added. * * @param string $menu_item_id The ID attribute applied to the menu item's `<li>` element. * @param WP_Post $menu_item The current menu item. * @param stdClass $args An object of wp_nav_menu() arguments. * @param int $depth Depth of menu item. Used for padding. */ $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $menu_item->ID, $menu_item, $args, $depth ); $li_atts = array(); $li_atts['id'] = ! empty( $id ) ? $id : ''; $li_atts['class'] = ! empty( $class_names ) ? $class_names : ''; /** * Filters the HTML attributes applied to a menu's list item element. * * @since 6.3.0 * * @param array $li_atts { * The HTML attributes applied to the menu item's `<li>` element, empty strings are ignored. * * @type string $class HTML CSS class attribute. * @type string $id HTML id attribute. * } * @param WP_Post $menu_item The current menu item object. * @param stdClass $args An object of wp_nav_menu() arguments. * @param int $depth Depth of menu item. Used for padding. */ $li_atts = apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth ); $li_attributes = $this->build_atts( $li_atts ); $output .= $indent . '<li' . $li_attributes . '>'; /** This filter is documented in wp-includes/post-template.php */ $title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID );Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$item to $data_object and $id to $current_object_id to match parent class for PHP 8 named parameter support.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/class-walker-nav-menu.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.