wppaste
WordPress

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
Starts the element output.

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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

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

Instructions
152–211

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

Plugin surface
8 hooks

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.

Called by
0

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

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_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.

WhenInstructionsCalls it makes
empty($menu_item)152–157apply_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–162str_repeat(), apply_filters(), array_filter(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters(), apply_filters(), apply_filters(), ->build_atts(), apply_filters()
always159–170apply_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()
always164–169apply_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–175str_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–174str_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–182apply_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()
always175–180apply_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–187str_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–185str_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–193apply_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()
always186–193apply_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–198str_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–198str_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–206apply_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–211str_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

PHPCompiledExecutedBranchesNotes
8.6-dev229152–210161 fewer instruction than PHP 8.5
8.5230152–21116
8.4230152–2111616 fewer instructions than PHP 8.3
8.3246156–22716
8.2246156–22716
8.1246156–227164 fewer instructions than PHP 7.4
7.4250156–23116

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:

  1. apply_filters( nav_menu_item_args )filterline 164 (+25 into the body)

    Filters the arguments for a single nav menu item.

  2. 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.

  3. 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.

  4. apply_filters( nav_menu_item_attributes )filterline 211 (+72 into the body)

    Filters the HTML attributes applied to a menu's list item element.

  5. apply_filters( the_title )filterline 217 (+78 into the body)

    Filters the post title.

  6. apply_filters( nav_menu_item_title )filterline 232 (+93 into the body)

    Filters a menu item's title.

  7. apply_filters( nav_menu_link_attributes )filterline 280 (+141 into the body)

    Filters the HTML attributes applied to a menu item's anchor element.

  8. apply_filters( walker_nav_menu_start_el )filterline 303 (+164 into the body)

    Filters a menu item's starting output.

Uses · 3

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.

  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.

6.7.0
Removed redundant title attributes.from the docblock
5.9.0
Renamed $item to $data_object and $id to $current_object_id to match parent class for PHP 8 named parameter support.from the docblock
4.4.0
The 'nav_menu_item_args' filter was added.from the docblock
3.0.0
Introduced.from the docblock

About 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.