--- a/wp/wp-includes/widgets/class-wp-nav-menu-widget.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/widgets/class-wp-nav-menu-widget.php Tue Dec 15 13:49:49 2020 +0100
@@ -39,14 +39,15 @@
* @param array $instance Settings for the current Navigation Menu widget instance.
*/
public function widget( $args, $instance ) {
- // Get menu
+ // Get menu.
$nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
if ( ! $nav_menu ) {
return;
}
- $title = ! empty( $instance['title'] ) ? $instance['title'] : '';
+ $default_title = __( 'Menu' );
+ $title = ! empty( $instance['title'] ) ? $instance['title'] : '';
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
@@ -57,10 +58,36 @@
echo $args['before_title'] . $title . $args['after_title'];
}
- $nav_menu_args = array(
- 'fallback_cb' => '',
- 'menu' => $nav_menu,
- );
+ $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
+
+ /**
+ * Filters the HTML format of widgets with navigation links.
+ *
+ * @since 5.5.0
+ *
+ * @param string $format The type of markup to use in widgets with navigation links.
+ * Accepts 'html5', 'xhtml'.
+ */
+ $format = apply_filters( 'navigation_widgets_format', $format );
+
+ if ( 'html5' === $format ) {
+ // The title may be filtered: Strip out HTML and make sure the aria-label is never empty.
+ $title = trim( strip_tags( $title ) );
+ $aria_label = $title ? $title : $default_title;
+
+ $nav_menu_args = array(
+ 'fallback_cb' => '',
+ 'menu' => $nav_menu,
+ 'container' => 'nav',
+ 'container_aria_label' => $aria_label,
+ 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
+ );
+ } else {
+ $nav_menu_args = array(
+ 'fallback_cb' => '',
+ 'menu' => $nav_menu,
+ );
+ }
/**
* Filters the arguments for the Navigation Menu widget.
@@ -68,15 +95,15 @@
* @since 4.2.0
* @since 4.4.0 Added the `$instance` parameter.
*
- * @param array $nav_menu_args {
+ * @param array $nav_menu_args {
* An array of arguments passed to wp_nav_menu() to retrieve a navigation menu.
*
* @type callable|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty.
* @type mixed $menu Menu ID, slug, or name.
* }
- * @param WP_Term $nav_menu Nav menu object for the current menu.
- * @param array $args Display arguments for the current widget.
- * @param array $instance Array of settings for the current widget.
+ * @param WP_Term $nav_menu Nav menu object for the current menu.
+ * @param array $args Display arguments for the current widget.
+ * @param array $instance Array of settings for the current widget.
*/
wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args, $instance ) );
@@ -117,10 +144,11 @@
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
- // Get menus
+ // Get menus.
$menus = wp_get_nav_menus();
- $empty_menus_style = $not_empty_menus_style = '';
+ $empty_menus_style = '';
+ $not_empty_menus_style = '';
if ( empty( $menus ) ) {
$empty_menus_style = ' style="display:none" ';
} else {
@@ -141,8 +169,10 @@
} else {
$url = admin_url( 'nav-menus.php' );
}
+
+ /* translators: %s: URL to create a new menu. */
+ printf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) );
?>
- <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?>
</p>
<div class="nav-menu-widget-form-controls" <?php echo $empty_menus_style; ?>>
<p>