WP_Admin_Bar::_render_item

Advertisement

Syntax Syntax

WP_Admin_Bar::_render_item( object $node )

Parameters Parameters

$node

(Required)

Source Source

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

		$tabindex        = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : '';
		$aria_attributes = ( '' !== $tabindex ) ? ' tabindex="' . $tabindex . '"' : '';

		$menuclass = '';
		$arrow     = '';

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

		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 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 ) {
				$this->_render_group( $group );
			}
			echo '</div>';
		}

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

		echo '</li>';
	}

	/**
	 * Renders toolbar items recursively.
	 *
	 * @since 3.1.0
	 * @deprecated 3.3.0 Use WP_Admin_Bar::_render_item() or WP_Admin_bar::render() instead.
	 * @see WP_Admin_Bar::_render_item()
	 * @see WP_Admin_Bar::render()
	 *
	 * @param string $id    Unused.
	 * @param object $node

Advertisement

Advertisement

Leave a Reply