6
6
use Yoast \WP \SEO \Conditionals \Traits \Admin_Conditional_Trait ;
7
7
use Yoast \WP \SEO \Conditionals \WooCommerce_Conditional ;
8
8
use Yoast \WP \SEO \General \User_Interface \General_Page_Integration ;
9
+ use Yoast \WP \SEO \Helpers \Current_Page_Helper ;
9
10
use Yoast \WP \SEO \Helpers \Product_Helper ;
10
11
use Yoast \WP \SEO \Integrations \Integration_Interface ;
11
12
@@ -42,21 +43,31 @@ class Upgrade_Sidebar_Menu_Integration implements Integration_Interface {
42
43
*/
43
44
private $ product_helper ;
44
45
46
+ /**
47
+ * The current page helper.
48
+ *
49
+ * @var Current_Page_Helper
50
+ */
51
+ private $ current_page_helper ;
52
+
45
53
/**
46
54
* Constructor.
47
55
*
48
56
* @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce conditional.
49
57
* @param WPSEO_Shortlinker $shortlinker The shortlinker.
50
58
* @param Product_Helper $product_helper The product helper.
59
+ * @param Current_Page_Helper $current_page_helper The current page helper.
51
60
*/
52
61
public function __construct (
53
62
WooCommerce_Conditional $ woocommerce_conditional ,
54
63
WPSEO_Shortlinker $ shortlinker ,
55
- Product_Helper $ product_helper
64
+ Product_Helper $ product_helper ,
65
+ Current_Page_Helper $ current_page_helper
56
66
) {
57
67
$ this ->woocommerce_conditional = $ woocommerce_conditional ;
58
68
$ this ->shortlinker = $ shortlinker ;
59
69
$ this ->product_helper = $ product_helper ;
70
+ $ this ->current_page_helper = $ current_page_helper ;
60
71
}
61
72
62
73
/**
@@ -70,6 +81,7 @@ public function register_hooks() {
70
81
// Add page with PHP_INT_MAX so its always the last item.
71
82
\add_filter ( 'wpseo_submenu_pages ' , [ $ this , 'add_page ' ], \PHP_INT_MAX );
72
83
\add_filter ( 'wpseo_network_submenu_pages ' , [ $ this , 'add_page ' ], \PHP_INT_MAX );
84
+ \add_action ( 'admin_init ' , [ $ this , 'do_redirect ' ], 1 );
73
85
}
74
86
75
87
/**
@@ -88,7 +100,9 @@ public function add_page( $pages ) {
88
100
'<span class="yst-root"><span class="yst-button yst-w-full yst-button--upsell yst-button--small"> ' . \__ ( 'Upgrade ' , 'wordpress-seo ' ) . ' </span></span> ' ,
89
101
'wpseo_manage_options ' ,
90
102
self ::PAGE ,
91
- [ $ this , 'do_redirect ' ],
103
+ static function () {
104
+ echo 'redirecting... ' ;
105
+ },
92
106
];
93
107
}
94
108
@@ -100,8 +114,11 @@ public function add_page( $pages ) {
100
114
*
101
115
* @return void
102
116
*/
103
- public function do_redirect () {
117
+ public function do_redirect (): void {
104
118
119
+ if ( $ this ->current_page_helper ->get_current_yoast_seo_page () !== self ::PAGE ) {
120
+ return ;
121
+ }
105
122
$ link = $ this ->shortlinker ->build_shortlink ( 'https://yoa.st/wordpress-menu-upgrade-premium ' );
106
123
if ( $ this ->woocommerce_conditional ->is_met () ) {
107
124
$ link = $ this ->shortlinker ->build_shortlink ( 'https://yoa.st/wordpress-menu-upgrade-woocommerce ' );
0 commit comments