Opened 2 years ago
Last modified 2 years ago
#16672 new defect (bug)
Admin Bar and param href = FALSE
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | 3.1 |
| Severity: | normal | Keywords: | dev-feedback |
| Cc: |
Description
Current i dont find an solution to add an element in the admin bar with a a-tag inside the li-tag. But the function add_menu has an param href and is also possible to add the value false, but the a-tag ist always visible
maybe a fix on wp-includes/class-wp-admin-bar.php
/* Helpers */
function recursive_render( $id, &$menu_item ) { ?>
<?php
$is_parent = ! empty( $menu_item['children'] );
$menuclass = $is_parent ? 'menupop' : '';
if ( ! empty( $menu_item['meta']['class'] ) )
$menuclass .= ' ' . $menu_item['meta']['class'];
?>
<li id="<?php echo esc_attr( "wp-admin-bar-$id" ); ?>" class="<?php echo esc_attr( $menuclass ); ?>"><?php
if ( ! empty( $menu_item['href'] ) ) : ?>
<a href="<?php echo esc_url( $menu_item['href'] ) ?>"<?php
if ( ! empty( $menu_item['meta']['onclick'] ) ) :
?> onclick="<?php echo esc_js( $menu_item['meta']['onclick'] ); ?>"<?php
endif;
if ( ! empty( $menu_item['meta']['target'] ) ) :
?> target="<?php echo esc_attr( $menu_item['meta']['target'] ); ?>"<?php
endif;
if ( ! empty( $menu_item['meta']['title'] ) ) :
?> title="<?php echo esc_attr( $menu_item['meta']['title'] ); ?>"<?php
endif;
?>><?php
endif;
if ( $is_parent ) :
?><span><?php
endif;
echo $menu_item['title'];
if ( $is_parent ) :
?></span><?php
endif;
if ( ! empty( $menu_item['href'] ) ) : ?></a><?php endif; ?>
<?php if ( $is_parent ) : ?>
<ul>
<?php foreach ( $menu_item['children'] as $child_id => $child_menu_item ) : ?>
<?php $this->recursive_render( $child_id, $child_menu_item ); ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if ( ! empty( $menu_item['meta']['html'] ) ) : ?>
<?php echo $menu_item['meta']['html']; ?>
<?php endif; ?>
</li><?php
}
Attachments (2)
Change History (7)
comment:1
Bueltge
— 2 years ago
sorry, without a-tag inside the li-tag of the admin bar.
I think, is an problem of the function recursive_render(); in this function is donwt question for the href-attribut and always print the a-tag.
comment:2
solarissmoke
— 2 years ago
- Keywords dev-feedback added; has-patch removed
The href attribute in a elements is optional. I don't think you can assume that not having a href means that someone doesn't want the a element altogether. For example you could still have onclick attributes that you want to fire.
comment:3
follow-up:
↓ 4
Bueltge
— 2 years ago
ou can add via the meta-attribut the param onclick; but i think on html-standards is then href="#" or similar. The href is always inside the a-tag. For me it is important, that i can add elements in the admin bar without the a-tag and i think, current is this not possible. The search on the right top in the admin bar was added hard inside the function, nit via hook and that is the reason for works without a-tag.
comment:4
in reply to:
↑ 3
solarissmoke
— 2 years ago
Replying to Bueltge:
ou can add via the meta-attribut the param onclick; but i think on html-standards is then href="#" or similar.
Here is the relevant section from the spec:
If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed...
The target, ping, rel, media, hreflang, and type attributes must be omitted if the href attribute is not present.
But not others - like onclick etc.
I don't necessarily object to allowing a li element without an a element inside it - just saying that I don't think it should be done by checking for the presence/absence of href.
diff