Make WordPress Core

Opened 3 years ago

Last modified 11 months ago

#16672 new defect (bug)

Admin Bar and param href = FALSE

Reported by: Bueltge Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.1
Component: Toolbar Keywords: dev-feedback
Focuses: Cc:


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 ) { ?>
		$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
				if ( ! empty( $menu_item['meta']['target'] ) ) :
					?> target="<?php echo esc_attr( $menu_item['meta']['target'] ); ?>"<?php
				if ( ! empty( $menu_item['meta']['title'] ) ) :
					?> title="<?php echo esc_attr( $menu_item['meta']['title'] ); ?>"<?php
			if ( $is_parent ) :

			echo $menu_item['title'];

			if ( $is_parent ) :

			if ( ! empty( $menu_item['href'] ) ) : ?></a><?php endif; ?>

			<?php if ( $is_parent ) : ?>
				<?php foreach ( $menu_item['children'] as $child_id => $child_menu_item ) : ?>
					<?php $this->recursive_render( $child_id, $child_menu_item ); ?>
				<?php endforeach; ?>
			<?php endif; ?>

			<?php if ( ! empty( $menu_item['meta']['html'] ) ) : ?>
				<?php echo $menu_item['meta']['html']; ?>
			<?php endif; ?>

Attachments (2)

class-wp-admin-bar.php.diff (1.6 KB) - added by Bueltge 3 years ago.
class-wp-admin-bar.php (7.0 KB) - added by Bueltge 3 years ago.
file with working changes

Download all attachments as: .zip

Change History (8)

Bueltge3 years ago


Bueltge3 years ago

file with working changes

comment:1 Bueltge3 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 solarissmoke3 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: Bueltge3 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 solarissmoke3 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.

comment:5 Bueltge3 years ago

I understand your opinion and i understand now also the spec. Ok, than it is important, that we have a new param for the a-Tag or do you see an other solution?

comment:6 avryl11 months ago

  • Component changed from General to Toolbar
Note: See TracTickets for help on using tickets.