55 * @package WPSEO
66 */
77
8- use WPSEO_Shortlinker ;
98use Yoast \WP \SEO \Helpers \Product_Helper ;
109use Yoast \WP \SEO \Helpers \Score_Icon_Helper ;
1110use Yoast \WP \SEO \Models \Indexable ;
@@ -80,6 +79,13 @@ class WPSEO_Admin_Bar_Menu implements WPSEO_WordPress_Integration {
8079 */
8180 protected $ product_helper ;
8281
82+ /**
83+ * Holds the shortlinker instance.
84+ *
85+ * @var WPSEO_Shortlinker
86+ */
87+ protected $ shortlinker ;
88+
8389 /**
8490 * Whether SEO Score is enabled.
8591 *
@@ -108,12 +114,14 @@ class WPSEO_Admin_Bar_Menu implements WPSEO_WordPress_Integration {
108114 * @param Indexable_Repository|null $indexable_repository Optional. The Indexable_Repository.
109115 * @param Score_Icon_Helper|null $score_icon_helper Optional. The Score_Icon_Helper.
110116 * @param Product_Helper|null $product_helper Optional. The product helper.
117+ * @param WPSEO_Shortlinker|null $shortlinker The shortlinker.
111118 */
112119 public function __construct (
113120 WPSEO_Admin_Asset_Manager $ asset_manager = null ,
114121 Indexable_Repository $ indexable_repository = null ,
115122 Score_Icon_Helper $ score_icon_helper = null ,
116- Product_Helper $ product_helper = null
123+ Product_Helper $ product_helper = null ,
124+ WPSEO_Shortlinker $ shortlinker = null
117125 ) {
118126 if ( ! $ asset_manager ) {
119127 $ asset_manager = new WPSEO_Admin_Asset_Manager ();
@@ -127,11 +135,15 @@ public function __construct(
127135 if ( ! $ product_helper ) {
128136 $ product_helper = YoastSEO ()->helpers ->product ;
129137 }
138+ if ( ! $ shortlinker ) {
139+ $ shortlinker = new WPSEO_Shortlinker ();
140+ }
130141
131142 $ this ->product_helper = $ product_helper ;
132143 $ this ->asset_manager = $ asset_manager ;
133144 $ this ->indexable_repository = $ indexable_repository ;
134145 $ this ->score_icon_helper = $ score_icon_helper ;
146+ $ this ->shortlinker = $ shortlinker ;
135147 }
136148
137149 /**
@@ -246,7 +258,7 @@ public function add_menu( WP_Admin_Bar $wp_admin_bar ) {
246258 [
247259 'parent ' => self ::MENU_IDENTIFIER ,
248260 'id ' => 'wpseo-frontend-inspector ' ,
249- 'href ' => 'https://yoa.st/admin-bar-frontend-inspector ' ,
261+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-frontend-inspector ' ) ,
250262 'title ' => __ ( 'Front-end SEO inspector ' , 'wordpress-seo ' ) . new Premium_Badge_Presenter ( 'wpseo-frontend-inspector-badge ' ),
251263 'meta ' => [
252264 'tabindex ' => '0 ' ,
@@ -461,17 +473,17 @@ protected function add_seo_tools_submenu( WP_Admin_Bar $wp_admin_bar ) {
461473 [
462474 'id ' => 'wpseo-semrush ' ,
463475 'title ' => 'Semrush ' ,
464- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-semrush ' ),
476+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-semrush ' ),
465477 ],
466478 [
467479 'id ' => 'wpseo-wincher ' ,
468480 'title ' => 'Wincher ' ,
469- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-wincher ' ),
481+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-wincher ' ),
470482 ],
471483 [
472484 'id ' => 'wpseo-google-trends ' ,
473485 'title ' => 'Google trends ' ,
474- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-gtrends ' ),
486+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-gtrends ' ),
475487 ],
476488 ];
477489
@@ -498,17 +510,17 @@ protected function add_how_to_submenu( WP_Admin_Bar $wp_admin_bar ) {
498510 [
499511 'id ' => 'wpseo-learn-seo ' ,
500512 'title ' => __ ( 'Learn more SEO ' , 'wordpress-seo ' ),
501- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-learn-more-seo ' ),
513+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-learn-more-seo ' ),
502514 ],
503515 [
504516 'id ' => 'wpseo-improve-blogpost ' ,
505517 'title ' => __ ( 'Improve your blog post ' , 'wordpress-seo ' ),
506- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-improve-blog-post ' ),
518+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-improve-blog-post ' ),
507519 ],
508520 [
509521 'id ' => 'wpseo-write-better-content ' ,
510522 'title ' => __ ( 'Write better content ' , 'wordpress-seo ' ),
511- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-write-better ' ),
523+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-write-better ' ),
512524 ],
513525 ];
514526
@@ -535,22 +547,22 @@ protected function add_get_help_submenu( WP_Admin_Bar $wp_admin_bar ) {
535547 [
536548 'id ' => 'wpseo-yoast-help ' ,
537549 'title ' => __ ( 'Yoast.com help section ' , 'wordpress-seo ' ),
538- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-yoast-help ' ),
550+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-yoast-help ' ),
539551 ],
540552 [
541553 'id ' => 'wpseo-premium-support ' ,
542554 'title ' => __ ( 'Yoast Premium support ' , 'wordpress-seo ' ),
543- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-premium-support ' ),
555+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-premium-support ' ),
544556 ],
545557 [
546558 'id ' => 'wpseo-wp-support-forums ' ,
547559 'title ' => __ ( 'WordPress.org support forums ' , 'wordpress-seo ' ),
548- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-wp-support-forums ' ),
560+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-wp-support-forums ' ),
549561 ],
550562 [
551563 'id ' => 'wpseo-learn-seo-2 ' ,
552564 'title ' => __ ( 'Learn more SEO ' , 'wordpress-seo ' ),
553- 'href ' => WPSEO_Shortlinker:: get ( 'https://yoa.st/admin-bar-learn-more-seo-help ' ),
565+ 'href ' => $ this -> shortlinker -> build_shortlink ( 'https://yoa.st/admin-bar-learn-more-seo-help ' ),
554566 ],
555567 ];
556568
@@ -569,11 +581,14 @@ protected function add_premium_link( WP_Admin_Bar $wp_admin_bar ) {
569581 [
570582 'parent ' => self ::MENU_IDENTIFIER ,
571583 'id ' => 'wpseo-get-premium ' ,
572- 'title ' => __ ( 'Get Yoast SEO Premium ' , 'wordpress-seo ' ) . ' » ' ,
573- 'href ' => WPSEO_Shortlinker::get ( 'https://yoa.st/admin-bar-get-premium ' ),
584+ // Circumvent an issue in the WP admin bar API in order to pass `data` attributes. See https://core.trac.wordpress.org/ticket/38636.
585+ 'title ' => sprintf (
586+ '<a href="%1$s" target="_blank" data-action="load-nfd-ctb" data-ctb-id="57d6a568-783c-45e2-a388-847cff155897" style="padding:0;">%2$s »</a> ' ,
587+ $ this ->shortlinker ->build_shortlink ( 'https://yoa.st/admin-bar-get-premium ' ),
588+ __ ( 'Get Yoast SEO Premium ' , 'wordpress-seo ' )
589+ ),
574590 'meta ' => [
575591 'tabindex ' => '0 ' ,
576- 'target ' => '_blank ' ,
577592 ],
578593 ]
579594 );
0 commit comments