_manage_options(); if ( $can_manage_options ) { $settings_url = $this->get_settings_page_url(); } if ( empty( $score ) && ! is_network_admin() && $can_manage_options ) { $counter = $this->get_notification_counter(); $notification_popup = $this->get_notification_popup(); } $admin_bar_menu_args = [ 'id' => self::MENU_IDENTIFIER, 'title' => $title . $score . $counter . $notification_popup, 'href' => $settings_url, 'meta' => [ 'tabindex' => ! empty( $settings_url ) ? false : '0' ], ]; $wp_admin_bar->add_menu( $admin_bar_menu_args ); if ( ! empty( $counter ) ) { $admin_bar_menu_args = [ 'parent' => self::MENU_IDENTIFIER, 'id' => 'wpseo-notifications', 'title' => __( 'Notifications', 'wordpress-seo' ) . $counter, 'href' => $settings_url, 'meta' => [ 'tabindex' => ! empty( $settings_url ) ? false : '0' ], ]; $wp_admin_bar->add_menu( $admin_bar_menu_args ); } if ( ! is_network_admin() && $can_manage_options ) { $admin_bar_menu_args = [ 'parent' => self::MENU_IDENTIFIER, 'id' => 'wpseo-configuration-wizard', 'title' => __( 'Configuration Wizard', 'wordpress-seo' ), 'href' => admin_url( 'admin.php?page=' . WPSEO_Configuration_Page::PAGE_IDENTIFIER ), ]; $wp_admin_bar->add_menu( $admin_bar_menu_args ); } } /** * Adds the admin bar keyword research submenu. * * @param WP_Admin_Bar $wp_admin_bar Admin bar instance to add the menu to. * * @return void */ protected function add_keyword_research_submenu( WP_Admin_Bar $wp_admin_bar ) { $adwords_url = 'https://yoa.st/keywordplanner'; $trends_url = 'https://yoa.st/google-trends'; $post = $this->get_singular_post(); if ( $post ) { $focus_keyword = $this->get_post_focus_keyword( $post ); if ( ! empty( $focus_keyword ) ) { $trends_url .= '#q=' . urlencode( $focus_keyword ); } } $menu_args = [ 'parent' => self::MENU_IDENTIFIER, 'id' => self::KEYWORD_RESEARCH_SUBMENU_IDENTIFIER, 'title' => __( 'Keyword Research', 'wordpress-seo' ), 'meta' => [ 'tabindex' => '0' ], ]; $wp_admin_bar->add_menu( $menu_args ); $submenu_items = [ [ 'id' => 'wpseo-kwresearchtraining', 'title' => __( 'Keyword research training', 'wordpress-seo' ), 'href' => WPSEO_Shortlinker::get( 'https://yoa.st/wp-admin-bar' ), ], [ 'id' => 'wpseo-adwordsexternal', 'title' => __( 'Google Ads', 'wordpress-seo' ), 'href' => $adwords_url, ], [ 'id' => 'wpseo-googleinsights', 'title' => __( 'Google Trends', 'wordpress-seo' ), 'href' => $trends_url, ], ]; foreach ( $submenu_items as $menu_item ) { $menu_args = [ 'parent' => self::KEYWORD_RESEARCH_SUBMENU_IDENTIFIER, 'id' => $menu_item['id'], 'title' => $menu_item['title'], 'href' => $menu_item['href'], 'meta' => [ 'target' => '_blank' ], ]; $wp_admin_bar->add_menu( $menu_args ); } } /** * Adds the admin bar analysis submenu. * * @param WP_Admin_Bar $wp_admin_bar Admin bar instance to add the menu to. * * @return void */ protected function add_analysis_submenu( WP_Admin_Bar $wp_admin_bar ) { try { $url = YoastSEO()->meta->for_current_page()->canonical; } catch ( Exception $e ) { // This is not the type of error we can handle here. return; } $focus_keyword = ''; if ( ! $url ) { return; } $post = $this->get_singular_post(); if ( $post ) { $focus_keyword = $this->get_post_focus_keyword( $post ); } $menu_args = [ 'parent' => self::MENU_IDENTIFIER, 'id' => self::ANALYSIS_SUBMENU_IDENTIFIER, 'title' => __( 'Analyze this page', 'wordpress-seo' ), 'meta' => [ 'tabindex' => '0' ], ]; $wp_admin_bar->add_menu( $menu_args ); $encoded_url = urlencode( $url ); $submenu_items = [ [ 'id' => 'wpseo-inlinks', 'title' => __( 'Check links to this URL', 'wordpress-seo' ), 'href' => 'https://search.google.com/search-console/links/drilldown?resource_id=' . urlencode( get_option( 'siteurl' ) ) . '&type=EXTERNAL&target=' . $encoded_url . '&domain=', ], [ 'id' => 'wpseo-kwdensity', 'title' => __( 'Check Keyphrase Density', 'wordpress-seo' ), // HTTPS not available. 'href' => 'http://www.zippy.co.uk/keyworddensity/index.php?url=' . $encoded_url . '&keyword=' . urlencode( $focus_keyword ), ], [ 'id' => 'wpseo-cache', 'title' => __( 'Check Google Cache', 'wordpress-seo' ), 'href' => '//webcache.googleusercontent.com/search?strip=1&q=cache:' . $encoded_url, ], [ 'id' => 'wpseo-structureddata', 'title' => __( 'Google Rich Results Test', 'wordpress-seo' ), 'href' => 'https://search.google.com/test/rich-results?url=' . $encoded_url, ], [ 'id' => 'wpseo-facebookdebug', 'title' => __( 'Facebook Debugger', 'wordpress-seo' ), 'href' => '//developers.facebook.com/tools/debug/?q=' . $encoded_url, ], [ 'id' => 'wpseo-pinterestvalidator', 'title' => __( 'Pinterest Rich Pins Validator', 'wordpress-seo' ), 'href' => 'https://developers.pinterest.com/tools/url-debugger/?link=' . $encoded_url, ], [ 'id' => 'wpseo-htmlvalidation', 'title' => __( 'HTML Validator', 'wordpress-seo' ), 'href' => '//validator.w3.org/check?uri=' . $encoded_url, ], [ 'id' => 'wpseo-cssvalidation', 'title' => __( 'CSS Validator', 'wordpress-seo' ), 'href' => '//jigsaw.w3.org/css-validator/validator?uri=' . $encoded_url, ], [ 'id' => 'wpseo-pagespeed', 'title' => __( 'Google Page Speed Test', 'wordpress-seo' ), 'href' => '//developers.google.com/speed/pagespeed/insights/?url=' . $encoded_url, ], [ 'id' => 'wpseo-google-mobile-friendly', 'title' => __( 'Mobile-Friendly Test', 'wordpress-seo' ), 'href' => 'https://www.google.com/webmasters/tools/mobile-friendly/?url=' . $encoded_url, ], ]; foreach ( $submenu_items as $menu_item ) { $menu_args = [ 'parent' => self::ANALYSIS_SUBMENU_IDENTIFIER, 'id' => $menu_item['id'], 'title' => $menu_item['title'], 'href' => $menu_item['href'], 'meta' => [ 'target' => '_blank' ], ]; $wp_admin_bar->add_menu( $menu_args ); } } /** * Adds the admin bar settings submenu. * * @param WP_Admin_Bar $wp_admin_bar Admin bar instance to add the menu to. * * @return void */ protected function add_settings_submenu( WP_Admin_Bar $wp_admin_bar ) { if ( ! $this->can_manage_options() ) { return; } $admin_menu = new WPSEO_Admin_Menu( new WPSEO_Menu() ); $submenu_pages = $admin_menu->get_submenu_pages(); $menu_args = [ 'parent' => self::MENU_IDENTIFIER, 'id' => self::SETTINGS_SUBMENU_IDENTIFIER, 'title' => __( 'SEO Settings', 'wordpress-seo' ), 'meta' => [ 'tabindex' => '0' ], ]; $wp_admin_bar->add_menu( $menu_args ); foreach ( $submenu_pages as $submenu_page ) { if ( ! current_user_can( $submenu_page[3] ) ) { continue; } // Don't add the Google Search Console menu item. if ( $submenu_page[4] === 'wpseo_search_console' ) { continue; } $id = 'wpseo-' . str_replace( '_', '-', str_replace( 'wpseo_', '', $submenu_page[4] ) ); if ( $id === 'wpseo-dashboard' ) { $id = 'wpseo-general'; } $menu_args = [ 'parent' => self::SETTINGS_SUBMENU_IDENTIFIER, 'id' => $id, 'title' => $submenu_page[2], 'href' => admin_url( 'admin.php?page=' . urlencode( $submenu_page[4] ) ), ]; $wp_admin_bar->add_menu( $menu_args ); } } /** * Adds the admin bar network settings submenu. * * @param WP_Admin_Bar $wp_admin_bar Admin bar instance to add the menu to. * * @return void */ protected function add_network_settings_submenu( WP_Admin_Bar $wp_admin_bar ) { if ( ! $this->can_manage_options() ) { return; } $network_admin_menu = new WPSEO_Network_Admin_Menu( new WPSEO_Menu() ); $submenu_pages = $network_admin_menu->get_submenu_pages(); $menu_args = [ 'parent' => self::MENU_IDENTIFIER, 'id' => self::NETWORK_SETTINGS_SUBMENU_IDENTIFIER, 'title' => __( 'SEO Settings', 'wordpress-seo' ), 'meta' => [ 'tabindex' => '0' ], ]; $wp_admin_bar->add_menu( $menu_args ); foreach ( $submenu_pages as $submenu_page ) { if ( ! current_user_can( $submenu_page[3] ) ) { continue; } $id = 'wpseo-' . str_replace( '_', '-', str_replace( 'wpseo_', '', $submenu_page[4] ) ); if ( $id === 'wpseo-dashboard' ) { $id = 'wpseo-general'; } $menu_args = [ 'parent' => self::NETWORK_SETTINGS_SUBMENU_IDENTIFIER, 'id' => $id, 'title' => $submenu_page[2], 'href' => network_admin_url( 'admin.php?page=' . urlencode( $submenu_page[4] ) ), ]; $wp_admin_bar->add_menu( $menu_args ); } } /** * Gets the menu title markup. * * @return string Admin bar title markup. */ protected function get_title() { return '