Make WordPress Core

Opened 6 years ago

Last modified 15 months ago

#46382 new defect (bug)

[walker-nav-menu] Undefined property stdclass::$current in class-walker-nav-menu.php

Reported by: winston_wolf's profile winston_wolf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.1
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

In wp-includes/class-walker-nav-menu.php line 177 there's a missing empty(); function around $item->current.
Causes PHP errors everywhere wp_nav_menu(); function occurrence:

$atts['aria-current'] = $item->current ? 'page' : '';

Should be:

$atts['aria-current'] = ! empty( $item->current ) ? 'page' : '';

Attachments (1)

46382.diff (687 bytes) - added by mukesh27 6 years ago.
Working patch.

Download all attachments as: .zip

Change History (6)

#1 follow-up: @mukesh27
6 years ago

Hi @winston_wolf, Welcome to WordPres Trac! Thanks for the report.

Good cache.

@mukesh27
6 years ago

Working patch.

#2 in reply to: ↑ 1 @winston_wolf
6 years ago

You're welcome ;)

Replying to mukesh27:

Thanks for the report.
Good cache.

#3 @rejuancse
4 years ago

Hello @winston_wolf,
In the WordPress update version, we are facing the exact same issue,

In wp-includes/nav-menu-template.php line 190 there’s a missing empty();
function around $args->container_aria_label.
Causes PHP errors everywhere wp_nav_menu(); function occurrence:

$aria_label = ( 'nav' === $args->container && $args->container_aria_label ) ? ' aria-label="' . esc_attr( $args->container_aria_label ) . '"' : '';

Should be:

$aria_label = ( 'nav' === $args->container && !empty($args->container_aria_label) ) ? ' aria-label="' . esc_attr( $args->container_aria_label ) . '"' : '';

Thanks

#4 @terraGirl
3 years ago

Watching this ticket as I've just had to delete a 12MB error log filled with

Undefined property: stdClass::$target in .../wp-includes/class-walker-nav-menu.php on line 180
Undefined property: stdClass::$xfn in .../wp-includes/class-walker-nav-menu.php on line 183

#5 @KTS915
15 months ago

Looks like lines 180 to 196 inclusive should be changed to read as follows:

        if ( ! empty( $menu_item->target ) && '_blank' === $menu_item->target && empty( $menu_item->xfn ) ) {
			$atts['rel'] = 'noopener';
		} else {
			$atts['rel'] = ! empty( $menu_item->xfn ) ? $menu_item->xfn : '';
		}

		if ( ! empty( $menu_item->url ) ) {
			if ( get_privacy_policy_url() === $menu_item->url ) {
				$atts['rel'] = empty( $atts['rel'] ) ? 'privacy-policy' : $atts['rel'] . ' privacy-policy';
			}

			$atts['href'] = $menu_item->url;
		} else {
			$atts['href'] = '';
		}

		$atts['aria-current'] = ! empty( $menu_item->current ) ? 'page' : '';
Last edited 15 months ago by KTS915 (previous) (diff)
Note: See TracTickets for help on using tickets.