WP_Admin_Bar::_render_item( object $node )


Description Description


Parameters Parameters

$node

(object) (Required)


Top ↑

Source Source

File: wp-includes/class-wp-admin-bar.php

	final protected function _render_item( $node ) {
		if ( $node->type != 'item' ) {
			return;
		}

		$is_parent = ! empty( $node->children );
		$has_link  = ! empty( $node->href );

		// 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 . '"' : '';

		$menuclass = '';

		if ( $is_parent ) {
			$menuclass        = 'menupop ';
			$aria_attributes .= ' aria-haspopup="true"';
		}

		if ( ! empty( $node->meta['class'] ) ) {
			$menuclass .= $node->meta['class'];
		}

		if ( $menuclass ) {
			$menuclass = ' class="' . esc_attr( trim( $menuclass ) ) . '"';
		}

		echo "<li 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 ) . "'";
			if ( ! empty( $node->meta['onclick'] ) ) {
				echo ' onclick="' . esc_js( $node->meta['onclick'] ) . '"';
			}
		} 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 ] ) ) {
				echo " $attribute='" . esc_attr( $node->meta[ $attribute ] ) . "'";
			}
		}

		echo ">{$node->title}";

		if ( $has_link ) {
			echo '</a>';
		} else {
			echo '</div>';
		}

		if ( $is_parent ) {
			echo '<div class="ab-sub-wrapper">';
			foreach ( $node->children as $group ) {
				$this->_render_group( $group );
			}
			echo '</div>';
		}

		if ( ! empty( $node->meta['html'] ) ) {
			echo $node->meta['html'];
		}

		echo '</li>';
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.