From 798c1894f41ec9405e41b6e23f01309a072a71a5 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Sat, 9 Sep 2017 14:49:53 +0000 Subject: [PATCH] Administration: Admin menu: Use `aria-current` for the current active page. The `aria-current` attribute is a simple, effective way to communicate to assistive technologies which the current item within a set of items is. While the admin menu structure isn't 100% ideal (the top-level item is repeated also as a sub-item) adding `aria-current="page"` to the sub-items gives an important feedback to assistive technologies users. This change introduces `aria-current` for the first time in core. Worth noting there are other places where it can be used to improve accessibility. These should be addressed in separate tickets and patches. Fixes #41589. git-svn-id: https://develop.svn.wordpress.org/trunk@41359 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/menu-header.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/menu-header.php b/src/wp-admin/menu-header.php index 8c47b63789..c253db454c 100644 --- a/src/wp-admin/menu-header.php +++ b/src/wp-admin/menu-header.php @@ -89,7 +89,12 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { } if ( ( $parent_file && $item[2] == $parent_file ) || ( empty($typenow) && $self == $item[2] ) ) { - $class[] = ! empty( $submenu_items ) ? 'wp-has-current-submenu wp-menu-open' : 'current'; + if ( ! empty( $submenu_items ) ) { + $class[] = 'wp-has-current-submenu wp-menu-open'; + } else { + $class[] = 'current'; + $aria_attributes .= 'aria-current="page"'; + } } else { $class[] = 'wp-not-current-submenu'; if ( ! empty( $submenu_items ) ) @@ -178,6 +183,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { continue; $class = array(); + $aria_attributes = ''; if ( $first ) { $class[] = 'wp-first-item'; $first = false; @@ -192,8 +198,10 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { $self_type = ! empty( $typenow ) ? $self . '?post_type=' . $typenow : 'nothing'; if ( isset( $submenu_file ) ) { - if ( $submenu_file == $sub_item[2] ) + if ( $submenu_file == $sub_item[2] ) { $class[] = 'current'; + $aria_attributes .= ' aria-current="page"'; + } // If plugin_page is set the parent must either match the current page or not physically exist. // This allows plugin pages with the same hook to exist under different parents. } elseif ( @@ -201,6 +209,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { ( isset( $plugin_page ) && $plugin_page == $sub_item[2] && ( $item[2] == $self_type || $item[2] == $self || file_exists($menu_file) === false ) ) ) { $class[] = 'current'; + $aria_attributes .= ' aria-current="page"'; } if ( ! empty( $sub_item[4] ) ) { @@ -224,9 +233,9 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { $sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), 'admin.php' ); $sub_item_url = esc_url( $sub_item_url ); - echo "$title"; + echo "$title"; } else { - echo "$title"; + echo "$title"; } } echo "";