Skip to content

Commit 0b67ac5

Browse files
committed
Update redirect mechanism
1 parent 1b1c84f commit 0b67ac5

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/plans/user-interface/upgrade-sidebar-menu-integration.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait;
77
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
88
use Yoast\WP\SEO\General\User_Interface\General_Page_Integration;
9+
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
910
use Yoast\WP\SEO\Helpers\Product_Helper;
1011
use Yoast\WP\SEO\Integrations\Integration_Interface;
1112

@@ -42,21 +43,31 @@ class Upgrade_Sidebar_Menu_Integration implements Integration_Interface {
4243
*/
4344
private $product_helper;
4445

46+
/**
47+
* The current page helper.
48+
*
49+
* @var Current_Page_Helper
50+
*/
51+
private $current_page_helper;
52+
4553
/**
4654
* Constructor.
4755
*
4856
* @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce conditional.
4957
* @param WPSEO_Shortlinker $shortlinker The shortlinker.
5058
* @param Product_Helper $product_helper The product helper.
59+
* @param Current_Page_Helper $current_page_helper The current page helper.
5160
*/
5261
public function __construct(
5362
WooCommerce_Conditional $woocommerce_conditional,
5463
WPSEO_Shortlinker $shortlinker,
55-
Product_Helper $product_helper
64+
Product_Helper $product_helper,
65+
Current_Page_Helper $current_page_helper
5666
) {
5767
$this->woocommerce_conditional = $woocommerce_conditional;
5868
$this->shortlinker = $shortlinker;
5969
$this->product_helper = $product_helper;
70+
$this->current_page_helper = $current_page_helper;
6071
}
6172

6273
/**
@@ -70,6 +81,7 @@ public function register_hooks() {
7081
// Add page with PHP_INT_MAX so its always the last item.
7182
\add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ], \PHP_INT_MAX );
7283
\add_filter( 'wpseo_network_submenu_pages', [ $this, 'add_page' ], \PHP_INT_MAX );
84+
\add_action( 'admin_init', [ $this, 'do_redirect' ], 1 );
7385
}
7486

7587
/**
@@ -88,7 +100,9 @@ public function add_page( $pages ) {
88100
'<span class="yst-root"><span class="yst-button yst-w-full yst-button--upsell yst-button--small">' . \__( 'Upgrade', 'wordpress-seo' ) . ' </span></span>',
89101
'wpseo_manage_options',
90102
self::PAGE,
91-
[ $this, 'do_redirect' ],
103+
static function () {
104+
echo 'redirecting...';
105+
},
92106
];
93107
}
94108

@@ -100,8 +114,11 @@ public function add_page( $pages ) {
100114
*
101115
* @return void
102116
*/
103-
public function do_redirect() {
117+
public function do_redirect(): void {
104118

119+
if ( $this->current_page_helper->get_current_yoast_seo_page() !== self::PAGE ) {
120+
return;
121+
}
105122
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-premium' );
106123
if ( $this->woocommerce_conditional->is_met() ) {
107124
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-woocommerce' );

0 commit comments

Comments
 (0)