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'];
}
echo '</li>';
}
View all references View on Trac View on GitHub
Version | Description |
---|
3.3.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.