Source
File: wp-includes/class-wp-admin-bar.php
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 . '"' : '';
$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>';
}