wpseo_admin_bar_menu

Adds an SEO admin bar menu with several options.

Description

wpseo_admin_bar_menu(); 

If the current user is an admin he can also go straight to several settings menu's from here.


Usage

  1. if ( !function_exists( 'wpseo_admin_bar_menu' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yoast-seo/inc/wpseo-non-ajax-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wpseo_admin_bar_menu(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/inc/wpseo-non-ajax-functions.php  
  1. function wpseo_admin_bar_menu() { 
  2. // If the current user can't write posts, this is all of no use, so let's not output an admin menu. 
  3. if ( ! current_user_can( 'edit_posts' ) ) { 
  4. return; 
  5.  
  6. $options = WPSEO_Options::get_options( array( 'wpseo', 'wpseo_ms' ) ); 
  7.  
  8. if ( $options['enable_admin_bar_menu'] !== true ) { 
  9. return; 
  10.  
  11. global $wp_admin_bar, $post; 
  12.  
  13. // Determine is user is admin or network admin. 
  14. $user_is_admin_or_networkadmin = current_user_can( 'manage_options' ); 
  15. if ( ! $user_is_admin_or_networkadmin && is_multisite() ) { 
  16. $user_is_admin_or_networkadmin = ( $options['access'] === 'superadmin' && is_super_admin() ); 
  17.  
  18. $focuskw = ''; 
  19. $score = ''; 
  20. // By default, the top level menu item has no link. 
  21. $seo_url = ''; 
  22. // By default, make the no-link top level menu item focusable. 
  23. $top_level_link_tabindex = '0'; 
  24.  
  25. $analysis_seo = new WPSEO_Metabox_Analysis_SEO(); 
  26. $analysis_readability = new WPSEO_Metabox_Analysis_Readability(); 
  27.  
  28. if ( ( is_singular() || ( is_admin() && WPSEO_Metabox::is_post_edit( $GLOBALS['pagenow'] ) ) ) && isset( $post ) && is_object( $post ) && apply_filters( 'wpseo_use_page_analysis', true ) === true 
  29. ) { 
  30. $focuskw = WPSEO_Meta::get_value( 'focuskw', $post->ID ); 
  31.  
  32. if ( $analysis_seo->is_enabled() ) { 
  33. elseif ( $analysis_readability->is_enabled() ) { 
  34.  
  35. if ( is_category() || is_tag() || (WPSEO_Taxonomy::is_term_edit( $GLOBALS['pagenow'] ) && ! WPSEO_Taxonomy::is_term_overview( $GLOBALS['pagenow'] ) ) || is_tax() ) { 
  36. if ( $analysis_seo->is_enabled() ) { 
  37. elseif ( $analysis_readability->is_enabled() ) { 
  38.  
  39. // Never display notifications for network admin. 
  40. $counter = $alert_popup = ''; 
  41.  
  42. // Set the top level menu item content for admins and network admins. 
  43. if ( $user_is_admin_or_networkadmin ) { 
  44.  
  45. // Link the top level menu item to the Yoast Dashboard page. 
  46. $seo_url = get_admin_url( null, 'admin.php?page=' . WPSEO_Admin::PAGE_IDENTIFIER ); 
  47. // Since admins will get a real link, there's no need for a tabindex attribute. 
  48. $top_level_link_tabindex = false; 
  49.  
  50. if ( '' === $score ) { 
  51.  
  52. // Notification information. 
  53. $notification_center = Yoast_Notification_Center::get(); 
  54. $notification_count = $notification_center->get_notification_count(); 
  55. $new_notifications = $notification_center->get_new_notifications(); 
  56. $new_notifications_count = count( $new_notifications ); 
  57.  
  58. if ( $notification_count > 0 ) { 
  59. // Always show Alerts page when clicking on the main link. 
  60. /** translators: %s: number of notifications */ 
  61. $counter_screen_reader_text = sprintf( _n( '%s notification', '%s notifications', $notification_count, 'wordpress-seo' ), number_format_i18n( $notification_count ) ); 
  62. $counter = sprintf( ' <div class="wp-core-ui wp-ui-notification yoast-issue-counter"><span aria-hidden="true">%d</span><span class="screen-reader-text">%s</span></div>', $notification_count, $counter_screen_reader_text ); 
  63.  
  64. if ( $new_notifications_count ) { 
  65. if ( $new_notifications_count === 1 ) { 
  66. $notification = sprintf( 
  67. __( 'You have a new issue concerning your SEO!', 'wordpress-seo' ),  
  68. $new_notifications_count 
  69. ); 
  70. else { 
  71. $notification = sprintf( 
  72. /** translators: %d resolves to the number of alerts being added. */ 
  73. _n( 'You have %d new issue concerning your SEO!', 'You have %d new issues concerning your SEO!', $new_notifications_count, 'wordpress-seo' ),  
  74. $new_notifications_count 
  75. ); 
  76. $alert_popup = '<div class="yoast-issue-added">' . $notification . '</div>'; 
  77.  
  78. $title = '<div id="yoast-ab-icon" class="ab-item yoast-logo svg"><span class="screen-reader-text">' . __( 'SEO', 'wordpress-seo' ) . '</span></div>'; 
  79.  
  80. $wp_admin_bar->add_menu( array( 
  81. 'id' => 'wpseo-menu',  
  82. 'title' => $title . $score . $counter . $alert_popup,  
  83. 'href' => $seo_url,  
  84. 'meta' => array( 'tabindex' => $top_level_link_tabindex ),  
  85. ) ); 
  86. if ( ! empty( $notification_count ) ) { 
  87. $wp_admin_bar->add_menu( array( 
  88. 'parent' => 'wpseo-menu',  
  89. 'id' => 'wpseo-notifications',  
  90. 'title' => __( 'Notifications', 'wordpress-seo' ) . $counter,  
  91. 'href' => $seo_url,  
  92. 'meta' => array( 'tabindex' => $top_level_link_tabindex ),  
  93. ) ); 
  94. $wp_admin_bar->add_menu( array( 
  95. 'parent' => 'wpseo-menu',  
  96. 'id' => 'wpseo-kwresearch',  
  97. 'title' => __( 'Keyword Research', 'wordpress-seo' ),  
  98. 'meta' => array( 'tabindex' => '0' ),  
  99. ) ); 
  100. $wp_admin_bar->add_menu( array( 
  101. 'parent' => 'wpseo-kwresearch',  
  102. 'id' => 'wpseo-adwordsexternal',  
  103. 'title' => __( 'AdWords External', 'wordpress-seo' ),  
  104. 'href' => 'http://adwords.google.com/keywordplanner',  
  105. 'meta' => array( 'target' => '_blank' ),  
  106. ) ); 
  107. $wp_admin_bar->add_menu( array( 
  108. 'parent' => 'wpseo-kwresearch',  
  109. 'id' => 'wpseo-googleinsights',  
  110. 'title' => __( 'Google Trends', 'wordpress-seo' ),  
  111. 'href' => 'https://www.google.com/trends/explore#q=' . urlencode( $focuskw ),  
  112. 'meta' => array( 'target' => '_blank' ),  
  113. ) ); 
  114. $wp_admin_bar->add_menu( array( 
  115. 'parent' => 'wpseo-kwresearch',  
  116. 'id' => 'wpseo-wordtracker',  
  117. 'title' => __( 'SEO Book', 'wordpress-seo' ),  
  118. 'href' => 'http://tools.seobook.com/keyword-tools/seobook/?keyword=' . urlencode( $focuskw ),  
  119. 'meta' => array( 'target' => '_blank' ),  
  120. ) ); 
  121.  
  122. if ( ! is_admin() ) { 
  123. $url = WPSEO_Frontend::get_instance()->canonical( false ); 
  124.  
  125. if ( is_string( $url ) ) { 
  126. $wp_admin_bar->add_menu( array( 
  127. 'parent' => 'wpseo-menu',  
  128. 'id' => 'wpseo-analysis',  
  129. 'title' => __( 'Analyze this page', 'wordpress-seo' ),  
  130. 'meta' => array( 'tabindex' => '0' ),  
  131. ) ); 
  132. $wp_admin_bar->add_menu( array( 
  133. 'parent' => 'wpseo-analysis',  
  134. 'id' => 'wpseo-inlinks-ose',  
  135. 'title' => __( 'Check Inlinks (OSE)', 'wordpress-seo' ),  
  136. 'href' => '//moz.com/researchtools/ose/links?site=' . urlencode( $url ),  
  137. 'meta' => array( 'target' => '_blank' ),  
  138. ) ); 
  139. $wp_admin_bar->add_menu( array( 
  140. 'parent' => 'wpseo-analysis',  
  141. 'id' => 'wpseo-kwdensity',  
  142. 'title' => __( 'Check Keyword Density', 'wordpress-seo' ),  
  143. // HTTPS not available. 
  144. 'href' => 'http://www.zippy.co.uk/keyworddensity/index.php?url=' . urlencode( $url ) . '&keyword=' . urlencode( $focuskw ),  
  145. 'meta' => array( 'target' => '_blank' ),  
  146. ) ); 
  147. $wp_admin_bar->add_menu( array( 
  148. 'parent' => 'wpseo-analysis',  
  149. 'id' => 'wpseo-cache',  
  150. 'title' => __( 'Check Google Cache', 'wordpress-seo' ),  
  151. 'href' => '//webcache.googleusercontent.com/search?strip=1&q=cache:' . urlencode( $url ),  
  152. 'meta' => array( 'target' => '_blank' ),  
  153. ) ); 
  154. $wp_admin_bar->add_menu( array( 
  155. 'parent' => 'wpseo-analysis',  
  156. 'id' => 'wpseo-header',  
  157. 'title' => __( 'Check Headers', 'wordpress-seo' ),  
  158. 'href' => '//quixapp.com/headers/?r=' . urlencode( $url ),  
  159. 'meta' => array( 'target' => '_blank' ),  
  160. ) ); 
  161. $wp_admin_bar->add_menu( array( 
  162. 'parent' => 'wpseo-analysis',  
  163. 'id' => 'wpseo-structureddata',  
  164. 'title' => __( 'Google Structured Data Test', 'wordpress-seo' ),  
  165. 'href' => 'https://search.google.com/structured-data/testing-tool#url=' . urlencode( $url ),  
  166. 'meta' => array( 'target' => '_blank' ),  
  167. ) ); 
  168. $wp_admin_bar->add_menu( array( 
  169. 'parent' => 'wpseo-analysis',  
  170. 'id' => 'wpseo-facebookdebug',  
  171. 'title' => __( 'Facebook Debugger', 'wordpress-seo' ),  
  172. 'href' => '//developers.facebook.com/tools/debug/og/object?q=' . urlencode( $url ),  
  173. 'meta' => array( 'target' => '_blank' ),  
  174. ) ); 
  175. $wp_admin_bar->add_menu( array( 
  176. 'parent' => 'wpseo-analysis',  
  177. 'id' => 'wpseo-pinterestvalidator',  
  178. 'title' => __( 'Pinterest Rich Pins Validator', 'wordpress-seo' ),  
  179. 'href' => 'https://developers.pinterest.com/tools/url-debugger/?link=' . urlencode( $url ),  
  180. 'meta' => array( 'target' => '_blank' ),  
  181. ) ); 
  182. $wp_admin_bar->add_menu( array( 
  183. 'parent' => 'wpseo-analysis',  
  184. 'id' => 'wpseo-htmlvalidation',  
  185. 'title' => __( 'HTML Validator', 'wordpress-seo' ),  
  186. 'href' => '//validator.w3.org/check?uri=' . urlencode( $url ),  
  187. 'meta' => array( 'target' => '_blank' ),  
  188. ) ); 
  189. $wp_admin_bar->add_menu( array( 
  190. 'parent' => 'wpseo-analysis',  
  191. 'id' => 'wpseo-cssvalidation',  
  192. 'title' => __( 'CSS Validator', 'wordpress-seo' ),  
  193. 'href' => '//jigsaw.w3.org/css-validator/validator?uri=' . urlencode( $url ),  
  194. 'meta' => array( 'target' => '_blank' ),  
  195. ) ); 
  196. $wp_admin_bar->add_menu( array( 
  197. 'parent' => 'wpseo-analysis',  
  198. 'id' => 'wpseo-pagespeed',  
  199. 'title' => __( 'Google Page Speed Test', 'wordpress-seo' ),  
  200. 'href' => '//developers.google.com/speed/pagespeed/insights/?url=' . urlencode( $url ),  
  201. 'meta' => array( 'target' => '_blank' ),  
  202. ) ); 
  203. $wp_admin_bar->add_menu( array( 
  204. 'parent' => 'wpseo-analysis',  
  205. 'id' => 'wpseo-microsoftedge',  
  206. 'title' => __( 'Microsoft Edge Site Scan', 'wordpress-seo' ),  
  207. 'href' => 'https://developer.microsoft.com/en-us/microsoft-edge/tools/staticscan/?url=' . urlencode( $url ),  
  208. 'meta' => array( 'target' => '_blank' ),  
  209. ) ); 
  210. $wp_admin_bar->add_menu( array( 
  211. 'parent' => 'wpseo-analysis',  
  212. 'id' => 'wpseo-google-mobile-friendly',  
  213. 'title' => __( 'Mobile-Friendly Test', 'wordpress-seo' ),  
  214. 'href' => 'https://www.google.com/webmasters/tools/mobile-friendly/?url=' . urlencode( $url ),  
  215. 'meta' => array( 'target' => '_blank' ),  
  216. ) ); 
  217.  
  218. // @todo: add links to bulk title and bulk description edit pages. 
  219. if ( $user_is_admin_or_networkadmin ) { 
  220.  
  221. $advanced_settings = wpseo_advanced_settings_enabled( $options ); 
  222.  
  223. $wp_admin_bar->add_menu( array( 
  224. 'parent' => 'wpseo-menu',  
  225. 'id' => 'wpseo-settings',  
  226. 'title' => __( 'SEO Settings', 'wordpress-seo' ),  
  227. 'meta' => array( 'tabindex' => '0' ),  
  228. ) ); 
  229. $wp_admin_bar->add_menu( array( 
  230. 'parent' => 'wpseo-settings',  
  231. 'id' => 'wpseo-general',  
  232. 'title' => __( 'Dashboard', 'wordpress-seo' ),  
  233. 'href' => admin_url( 'admin.php?page=wpseo_dashboard' ),  
  234. ) ); 
  235. if ( $advanced_settings ) { 
  236. $wp_admin_bar->add_menu( array( 
  237. 'parent' => 'wpseo-settings',  
  238. 'id' => 'wpseo-titles',  
  239. 'title' => __( 'Titles & Metas', 'wordpress-seo' ),  
  240. 'href' => admin_url( 'admin.php?page=wpseo_titles' ),  
  241. ) ); 
  242. $wp_admin_bar->add_menu( array( 
  243. 'parent' => 'wpseo-settings',  
  244. 'id' => 'wpseo-social',  
  245. 'title' => __( 'Social', 'wordpress-seo' ),  
  246. 'href' => admin_url( 'admin.php?page=wpseo_social' ),  
  247. ) ); 
  248. $wp_admin_bar->add_menu( array( 
  249. 'parent' => 'wpseo-settings',  
  250. 'id' => 'wpseo-xml',  
  251. 'title' => __( 'XML Sitemaps', 'wordpress-seo' ),  
  252. 'href' => admin_url( 'admin.php?page=wpseo_xml' ),  
  253. ) ); 
  254. $wp_admin_bar->add_menu( array( 
  255. 'parent' => 'wpseo-settings',  
  256. 'id' => 'wpseo-wpseo-advanced',  
  257. 'title' => __( 'Advanced', 'wordpress-seo' ),  
  258. 'href' => admin_url( 'admin.php?page=wpseo_advanced' ),  
  259. ) ); 
  260. $wp_admin_bar->add_menu( array( 
  261. 'parent' => 'wpseo-settings',  
  262. 'id' => 'wpseo-tools',  
  263. 'title' => __( 'Tools', 'wordpress-seo' ),  
  264. 'href' => admin_url( 'admin.php?page=wpseo_tools' ),  
  265. ) ); 
  266. $wp_admin_bar->add_menu( array( 
  267. 'parent' => 'wpseo-settings',  
  268. 'id' => 'wpseo-search-console',  
  269. 'title' => __( 'Search Console', 'wordpress-seo' ),  
  270. 'href' => admin_url( 'admin.php?page=wpseo_search_console' ),  
  271. ) ); 
  272. $wp_admin_bar->add_menu( array( 
  273. 'parent' => 'wpseo-settings',  
  274. 'id' => 'wpseo-licenses',  
  275. 'title' => __( 'Go Premium', 'wordpress-seo' ),  
  276. 'href' => admin_url( 'admin.php?page=wpseo_licenses' ),  
  277. ) ); 
  278.