From acaa5ad7a76ce0586abaaadebf37b8416f13b830 Mon Sep 17 00:00:00 2001 From: Ames Plant Date: Thu, 15 Aug 2024 11:08:23 -0500 Subject: [PATCH] [Accessibility] Add aria-current to the current link in My Account side nav (#49800) * Add aria-current to the current link in My Account side nav * Update current page check for dashboard, orders, and payment methods * Fix PHP linting errors * Update function for getting current aria for account menu * Bump template version * Create a helper function to test current item in the account menu * Fix liniting errors --------- Co-authored-by: amesplant <95257231+amesplant-dmv@users.noreply.github.com> --- .../fix-43626-account-nav-aria-current | 4 +++ .../includes/wc-account-functions.php | 32 ++++++++++++------- .../templates/myaccount/navigation.php | 6 ++-- 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-43626-account-nav-aria-current diff --git a/plugins/woocommerce/changelog/fix-43626-account-nav-aria-current b/plugins/woocommerce/changelog/fix-43626-account-nav-aria-current new file mode 100644 index 00000000000..e8ac0302abd --- /dev/null +++ b/plugins/woocommerce/changelog/fix-43626-account-nav-aria-current @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Add aria-current to the current link in My Account side nav diff --git a/plugins/woocommerce/includes/wc-account-functions.php b/plugins/woocommerce/includes/wc-account-functions.php index 0abfaba1b4d..7a4fe452588 100644 --- a/plugins/woocommerce/includes/wc-account-functions.php +++ b/plugins/woocommerce/includes/wc-account-functions.php @@ -136,21 +136,15 @@ function wc_get_account_menu_items() { } /** - * Get account menu item classes. + * Find current item in account menu. * - * @since 2.6.0 + * @since 9.3.0 * @param string $endpoint Endpoint. - * @return string + * @return bool */ -function wc_get_account_menu_item_classes( $endpoint ) { +function wc_is_current_account_menu_item( $endpoint ) { global $wp; - $classes = array( - 'woocommerce-MyAccount-navigation-link', - 'woocommerce-MyAccount-navigation-link--' . $endpoint, - ); - - // Set current item class. $current = isset( $wp->query_vars[ $endpoint ] ); if ( 'dashboard' === $endpoint && ( isset( $wp->query_vars['page'] ) || empty( $wp->query_vars ) ) ) { $current = true; // Dashboard is not an endpoint, so needs a custom check. @@ -160,7 +154,23 @@ function wc_get_account_menu_item_classes( $endpoint ) { $current = true; } - if ( $current ) { + return $current; +} + +/** + * Get account menu item classes. + * + * @since 2.6.0 + * @param string $endpoint Endpoint. + * @return string + */ +function wc_get_account_menu_item_classes( $endpoint ) { + $classes = array( + 'woocommerce-MyAccount-navigation-link', + 'woocommerce-MyAccount-navigation-link--' . $endpoint, + ); + + if ( wc_is_current_account_menu_item( $endpoint ) ) { $classes[] = 'is-active'; } diff --git a/plugins/woocommerce/templates/myaccount/navigation.php b/plugins/woocommerce/templates/myaccount/navigation.php index 54373433691..00946235971 100644 --- a/plugins/woocommerce/templates/myaccount/navigation.php +++ b/plugins/woocommerce/templates/myaccount/navigation.php @@ -12,7 +12,7 @@ * * @see https://woocommerce.com/document/template-structure/ * @package WooCommerce\Templates - * @version 9.0.0 + * @version 9.3.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -26,7 +26,9 @@ do_action( 'woocommerce_before_account_navigation' );