wppaste
WordPress

WP_Admin_Bar::_render_item( object $node )

Since
3.3.0
Source
wp-includes/class-wp-admin-bar.php:541

Compatibility

WordPress
since 3.3.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

$nodeobject

Performance profile

How much work a call to WP_Admin_Bar::_render_item() 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
59–97

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()one call below WP_Admin_Bar::_render_item()

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 · 4 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Admin_Bar::_render_item() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$value59–80esc_attr()
$value66–87esc_attr(), esc_attr()
!$value69–90esc_attr(), esc_url()
!$value76–97esc_attr(), esc_attr(), esc_url()

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-dev15759–9721
8.515759–9721
8.415759–97214 fewer instructions than PHP 8.3
8.316159–10121
8.216159–10121
8.116159–101212 fewer instructions than PHP 7.4
7.416359–10121

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 · 4

Used by · 2

Source code

	final protected function _render_item( $node ) {		if ( 'item' !== $node->type ) {			return;		} 		$is_parent             = ! empty( $node->children );		$has_link              = ! empty( $node->href );		$is_root_top_item      = 'root-default' === $node->parent;		$is_top_secondary_item = 'top-secondary' === $node->parent; 		// Allow only numeric values, then casted to integers, and allow a tabindex value of `0` for a11y.		$tabindex         = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : '';		$aria_attributes  = ( '' !== $tabindex ) ? ' tabindex="' . $tabindex . '"' : '';		$aria_attributes .= ' role="menuitem"'; 		$menuclass = '';		$arrow     = ''; 		if ( $is_parent ) {			$menuclass        = 'menupop ';			$aria_attributes .= ' aria-expanded="false"';		} 		if ( ! empty( $node->meta['class'] ) ) {			$menuclass .= $node->meta['class'];		} 		// Print the arrow icon for the menu children with children.		if ( ! $is_root_top_item && ! $is_top_secondary_item && $is_parent ) {			$arrow = '<span class="wp-admin-bar-arrow" aria-hidden="true"></span>';		} 		if ( $menuclass ) {			$menuclass = ' class="' . esc_attr( trim( $menuclass ) ) . '"';		} 		echo "<li role='group' id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$menuclass>"; 		if ( $has_link ) {			$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );			echo "<a class='ab-item'$aria_attributes href='" . esc_url( $node->href ) . "'";		} else {			$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );			echo '<div class="ab-item ab-empty-item"' . $aria_attributes;		} 		foreach ( $attributes as $attribute ) {			if ( empty( $node->meta[ $attribute ] ) ) {				continue;			} 			if ( 'onclick' === $attribute ) {				echo " $attribute='" . esc_js( $node->meta[ $attribute ] ) . "'";			} else {				echo " $attribute='" . esc_attr( $node->meta[ $attribute ] ) . "'";			}		} 		echo ">{$arrow}{$node->title}"; 		if ( $has_link ) {			echo '</a>';		} else {			echo '</div>';		} 		if ( $is_parent ) {			echo '<div class="ab-sub-wrapper">';			foreach ( $node->children as $group ) {				if ( empty( $node->meta['menu_title'] ) ) {					$this->_render_group( $group, false );				} else {					$this->_render_group( $group, $node->meta['menu_title'] );				}			}			echo '</div>';		} 		if ( ! empty( $node->meta['html'] ) ) {			echo $node->meta['html'];

Changelog

Introduced in 3.3.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.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-admin-bar.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.