--- a/wp/wp-includes/class-walker-nav-menu.php Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/class-walker-nav-menu.php Mon Oct 14 18:28:13 2019 +0200
@@ -34,7 +34,10 @@
*
* @see Walker::$db_fields
*/
- public $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
+ public $db_fields = array(
+ 'parent' => 'menu_item_parent',
+ 'id' => 'db_id',
+ );
/**
* Starts the list before the elements are added.
@@ -65,7 +68,7 @@
*
* @since 4.8.0
*
- * @param array $classes The CSS classes that are applied to the menu `<ul>` element.
+ * @param string[] $classes Array of the CSS classes that are applied to the menu `<ul>` element.
* @param stdClass $args An object of `wp_nav_menu()` arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
@@ -94,7 +97,7 @@
$t = "\t";
$n = "\n";
}
- $indent = str_repeat( $t, $depth );
+ $indent = str_repeat( $t, $depth );
$output .= "$indent</ul>{$n}";
}
@@ -122,7 +125,7 @@
}
$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
- $classes = empty( $item->classes ) ? array() : (array) $item->classes;
+ $classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
/**
@@ -137,12 +140,12 @@
$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
/**
- * Filters the CSS class(es) applied to a menu item's list item element.
+ * Filters the CSS classes applied to a menu item's list item element.
*
* @since 3.0.0
* @since 4.1.0 The `$depth` parameter was added.
*
- * @param array $classes The CSS classes that are applied to the menu item's `<li>` element.
+ * @param string[] $classes Array of the CSS classes that are applied to the menu item's `<li>` element.
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
@@ -161,16 +164,21 @@
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
- $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth );
+ $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
- $output .= $indent . '<li' . $id . $class_names .'>';
+ $output .= $indent . '<li' . $id . $class_names . '>';
- $atts = array();
+ $atts = array();
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
- $atts['target'] = ! empty( $item->target ) ? $item->target : '';
- $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
- $atts['href'] = ! empty( $item->url ) ? $item->url : '';
+ $atts['target'] = ! empty( $item->target ) ? $item->target : '';
+ if ( '_blank' === $item->target && empty( $item->xfn ) ) {
+ $atts['rel'] = 'noopener noreferrer';
+ } else {
+ $atts['rel'] = $item->xfn;
+ }
+ $atts['href'] = ! empty( $item->url ) ? $item->url : '';
+ $atts['aria-current'] = $item->current ? 'page' : '';
/**
* Filters the HTML attributes applied to a menu item's anchor element.
@@ -181,10 +189,11 @@
* @param array $atts {
* The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
*
- * @type string $title Title attribute.
- * @type string $target Target attribute.
- * @type string $rel The rel attribute.
- * @type string $href The href attribute.
+ * @type string $title Title attribute.
+ * @type string $target Target attribute.
+ * @type string $rel The rel attribute.
+ * @type string $href The href attribute.
+ * @type string $aria_current The aria-current attribute.
* }
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
@@ -195,7 +204,7 @@
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
- $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
+ $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
@@ -215,8 +224,8 @@
*/
$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
- $item_output = $args->before;
- $item_output .= '<a'. $attributes .'>';
+ $item_output = $args->before;
+ $item_output .= '<a' . $attributes . '>';
$item_output .= $args->link_before . $title . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;