From 0bab64c3708adb25c296705fe0232bd3762f38b7 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Tue, 27 Sep 2016 19:00:35 +0000 Subject: [PATCH] Toolbar: Update links to the about page if current user can't access the dashboard of the current site. Add missing focus styling for menu items with an icon. Fixes #37949. git-svn-id: https://develop.svn.wordpress.org/trunk@38660 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/colors/_admin.scss | 1 + src/wp-includes/admin-bar.php | 31 ++++++++++++++++++++++------- src/wp-includes/css/admin-bar.css | 1 + tests/phpunit/tests/adminbar.php | 24 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/css/colors/_admin.scss b/src/wp-admin/css/colors/_admin.scss index 3e1753ea57..07753a641e 100644 --- a/src/wp-admin/css/colors/_admin.scss +++ b/src/wp-admin/css/colors/_admin.scss @@ -324,6 +324,7 @@ ul#adminmenu > li.current > a.current:after { #wpadminbar li:hover .ab-item:before, #wpadminbar li a:focus .ab-icon:before, #wpadminbar li .ab-item:focus:before, +#wpadminbar li .ab-item:focus .ab-icon:before, #wpadminbar li.hover .ab-icon:before, #wpadminbar li.hover .ab-item:before, #wpadminbar li:hover #adminbarsearch:before, diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index 4c4765d88a..5790d5be7b 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -107,19 +107,36 @@ function wp_admin_bar_render() { * @param WP_Admin_Bar $wp_admin_bar */ function wp_admin_bar_wp_menu( $wp_admin_bar ) { - $wp_admin_bar->add_menu( array( + if ( current_user_can( 'read' ) ) { + $about_url = self_admin_url( 'about.php' ); + } elseif ( is_multisite() ) { + $about_url = get_dashboard_url( get_current_user_id(), 'about.php' ); + } else { + $about_url = false; + } + + $wp_logo_menu_args = array( 'id' => 'wp-logo', 'title' => '' . __( 'About WordPress' ) . '', - 'href' => self_admin_url( 'about.php' ), - ) ); + 'href' => $about_url, + ); - if ( is_user_logged_in() ) { + // Set tabindex="0" to make sub menus accessible when no URL is available. + if ( ! $about_url ) { + $wp_logo_menu_args['meta'] = array( + 'tabindex' => 0, + ); + } + + $wp_admin_bar->add_menu( $wp_logo_menu_args ); + + if ( $about_url ) { // Add "About WordPress" link $wp_admin_bar->add_menu( array( 'parent' => 'wp-logo', 'id' => 'about', 'title' => __('About WordPress'), - 'href' => self_admin_url( 'about.php' ), + 'href' => $about_url, ) ); } @@ -294,10 +311,10 @@ function wp_admin_bar_site_menu( $wp_admin_bar ) { } if ( is_network_admin() ) { - /* translators: %s: site name */ + /* translators: %s: site name */ $blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_current_site()->site_name ) ); } elseif ( is_user_admin() ) { - /* translators: %s: site name */ + /* translators: %s: site name */ $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_current_site()->site_name ) ); } diff --git a/src/wp-includes/css/admin-bar.css b/src/wp-includes/css/admin-bar.css index 573ff8d8a6..e108a8e6bc 100644 --- a/src/wp-includes/css/admin-bar.css +++ b/src/wp-includes/css/admin-bar.css @@ -294,6 +294,7 @@ html:lang(he-il) .rtl #wpadminbar * { #wpadminbar li:hover .ab-item:before, #wpadminbar li a:focus .ab-icon:before, #wpadminbar li .ab-item:focus:before, +#wpadminbar li .ab-item:focus .ab-icon:before, #wpadminbar li.hover .ab-icon:before, #wpadminbar li.hover .ab-item:before, #wpadminbar li:hover #adminbarsearch:before, diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index 32507e3ce3..c673038ed8 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -407,4 +407,28 @@ class Tests_AdminBar extends WP_UnitTestCase { $this->assertNull( $node ); } + + /** + * @ticket 37949 + */ + public function test_admin_bar_does_not_add_about_page_url() { + wp_set_current_user( self::$no_role_id ); + + $wp_admin_bar = $this->get_standard_admin_bar(); + $node = $wp_admin_bar->get_node( 'wp-logo' ); + + $this->assertNotNull( $node ); + $this->assertSame( false, $node->href ); + $this->assertArrayHasKey( 'tabindex', $node->meta ); + $this->assertSame( 0, $node->meta['tabindex'] ); + + wp_set_current_user( self::$editor_id ); + + $wp_admin_bar = $this->get_standard_admin_bar(); + $node = $wp_admin_bar->get_node( 'wp-logo' ); + + $this->assertNotNull( $node ); + $this->assertSame( admin_url( 'about.php' ), $node->href ); + $this->assertArrayNotHasKey( 'tabindex', $node->meta ); + } }