diff --git a/css/src/adminbar.css b/css/src/adminbar.css index cd43c371b77..68e78ca0d76 100644 --- a/css/src/adminbar.css +++ b/css/src/adminbar.css @@ -111,6 +111,10 @@ color: #f18500; } +#wpadminbar .wpseo-no-adminbar-notifications { + display: none; +} + @media screen and (max-width: 782px) { #wp-admin-bar-wpseo-menu .wpseo-score-icon { margin: 16px 10px 0 2px !important; diff --git a/inc/class-wpseo-admin-bar-menu.php b/inc/class-wpseo-admin-bar-menu.php index 4b5f4d34c46..4fa28dbf711 100644 --- a/inc/class-wpseo-admin-bar-menu.php +++ b/inc/class-wpseo-admin-bar-menu.php @@ -359,6 +359,7 @@ protected function add_root_menu( WP_Admin_Bar $wp_admin_bar ) { $settings_url = ''; $counter = ''; $notification_popup = ''; + $notification_count = 0; $post = $this->get_singular_post(); if ( $post ) { @@ -377,7 +378,10 @@ protected function add_root_menu( WP_Admin_Bar $wp_admin_bar ) { } if ( empty( $score ) && ! is_network_admin() && $can_manage_options ) { - $counter = $this->get_notification_counter(); + $notification_center = Yoast_Notification_Center::get(); + $notification_count = $notification_center->get_notification_count(); + + $counter = $this->get_notification_counter( $notification_count ); $notification_popup = $this->get_notification_popup(); } @@ -389,7 +393,7 @@ protected function add_root_menu( WP_Admin_Bar $wp_admin_bar ) { ]; $wp_admin_bar->add_menu( $admin_bar_menu_args ); - if ( ! empty( $counter ) ) { + if ( $notification_count > 0 ) { $admin_bar_menu_args = [ 'parent' => self::MENU_IDENTIFIER, 'id' => 'wpseo-notifications', @@ -849,18 +853,17 @@ protected function get_settings_page_url() { /** * Gets the notification counter if in a valid context. * + * @param int $notification_count Number of notifications. + * * @return string Notification counter markup, or empty string if not available. */ - protected function get_notification_counter() { - $notification_center = Yoast_Notification_Center::get(); - $notification_count = $notification_center->get_notification_count(); - + protected function get_notification_counter( $notification_count ) { /* translators: Hidden accessibility text; %s: number of notifications. */ $counter_screen_reader_text = sprintf( _n( '%s notification', '%s notifications', $notification_count, 'wordpress-seo' ), number_format_i18n( $notification_count ) ); return sprintf( '