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:156
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
- Trivial
- Scaling
- Constant
- Instructions
- 152–210
- Plugin surface
- 8 hooks
- Called by
- 0
Touches nothing outside its own arguments.
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 229.
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
What one call costs · 8 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–169 | 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–174 | str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters() |
!empty($menu_item) | 164–181 | 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) && !empty($menu_item) | 169–186 | 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) | 175–192 | 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) | 180–197 | 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) | 186–205 | 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() |
!isset($args) && !empty($menu_item) | 191–210 | 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() |
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 | 228 | 152–209 | 16 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 229 | 152–210 | 16 | |
| 8.4 | 229 | 152–210 | 16 | 16 fewer instructions than PHP 8.3 |
| 8.3 | 245 | 156–226 | 16 | |
| 8.2 | 245 | 156–226 | 16 | |
| 8.1 | 245 | 156–226 | 16 | 4 fewer instructions than PHP 7.4 |
| 7.4 | 249 | 156–230 | 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 181 (+25 into the body)
Filters the arguments for a single nav menu item.
- apply_filters( nav_menu_css_class )filterline 194 (+38 into the body)
Filters the CSS classes applied to a menu item's list item element.
- apply_filters( nav_menu_item_id )filterline 207 (+51 into the body)
Filters the ID attribute applied to a menu item's list item element.
- apply_filters( nav_menu_item_attributes )filterline 228 (+72 into the body)
Filters the HTML attributes applied to a menu's list item element.
- apply_filters( nav_menu_link_attributes )filterline 297 (+141 into the body)
Filters the HTML attributes applied to a menu item's anchor element.
- apply_filters( walker_nav_menu_start_el )filterline 320 (+164 into the body)
Filters a menu item's starting output.
Uses · 2
- apply_filters()Calls the callback functions that have been added to a filter hook.
- 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 7.1.0 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.