• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / ad4f5d1decd5ba72026241af5b5f9afbe1d92e93

04 Dec 2025 12:38PM UTC coverage: 52.391%. First build
ad4f5d1decd5ba72026241af5b5f9afbe1d92e93

push

github

thijsoo
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into feature/schema_aggregator

# Conflicts:
#	admin/tracking/class-tracking-settings-data.php
#	inc/options/class-wpseo-option-wpseo.php

8706 of 16076 branches covered (54.16%)

Branch coverage included in aggregate %.

158 of 860 new or added lines in 78 files covered. (18.37%)

32437 of 62454 relevant lines covered (51.94%)

46168.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/plans/user-interface/upgrade-sidebar-menu-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\Plans\User_Interface;
4

5
use WPSEO_Addon_Manager;
6
use WPSEO_Shortlinker;
7
use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait;
8
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
9
use Yoast\WP\SEO\General\User_Interface\General_Page_Integration;
10
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
11
use Yoast\WP\SEO\Helpers\Product_Helper;
12
use Yoast\WP\SEO\Integrations\Integration_Interface;
13
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
14

15
/**
16
 * Adds the plans page to the Yoast admin menu.
17
 */
18
class Upgrade_Sidebar_Menu_Integration implements Integration_Interface {
19

20
        use Admin_Conditional_Trait;
21

22
        /**
23
         * The page name.
24
         */
25
        public const PAGE = 'wpseo_upgrade_sidebar';
26

27
        /**
28
         * The WooCommerce conditional.
29
         *
30
         * @var WooCommerce_Conditional
31
         */
32
        private $woocommerce_conditional;
33

34
        /**
35
         * The shortlinker.
36
         *
37
         * @var WPSEO_Shortlinker
38
         */
39
        private $shortlinker;
40

41
        /**
42
         * The product helper.
43
         *
44
         * @var Product_Helper
45
         */
46
        private $product_helper;
47

48
        /**
49
         * The current page helper.
50
         *
51
         * @var Current_Page_Helper
52
         */
53
        private $current_page_helper;
54

55
        /**
56
         * The promotion manager.
57
         *
58
         * @var Promotion_Manager
59
         */
60
        private $promotion_manager;
61

62
        /**
63
         * The addon manager.
64
         *
65
         * @var WPSEO_Addon_Manager
66
         */
67
        private $addon_manager;
68

69
        /**
70
         * Constructor.
71
         *
72
         * @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce conditional.
73
         * @param WPSEO_Shortlinker       $shortlinker             The shortlinker.
74
         * @param Product_Helper          $product_helper          The product helper.
75
         * @param Current_Page_Helper     $current_page_helper     The current page helper.
76
         * @param Promotion_Manager       $promotion_manager       The promotion manager.
77
         * @param WPSEO_Addon_Manager     $addon_manager           The addon manager.
78
         */
79
        public function __construct(
×
80
                WooCommerce_Conditional $woocommerce_conditional,
81
                WPSEO_Shortlinker $shortlinker,
82
                Product_Helper $product_helper,
83
                Current_Page_Helper $current_page_helper,
84
                Promotion_Manager $promotion_manager,
85
                WPSEO_Addon_Manager $addon_manager
86
        ) {
87
                $this->woocommerce_conditional = $woocommerce_conditional;
×
88
                $this->shortlinker             = $shortlinker;
×
89
                $this->product_helper          = $product_helper;
×
90
                $this->current_page_helper     = $current_page_helper;
×
91
                $this->promotion_manager       = $promotion_manager;
×
NEW
92
                $this->addon_manager           = $addon_manager;
×
93
        }
94

95
        /**
96
         * Initializes the integration.
97
         *
98
         * This is the place to register hooks and filters.
99
         *
100
         * @return void
101
         */
102
        public function register_hooks() {
×
103
                // Add page with PHP_INT_MAX - 1 to allow other items (like Brand Insights) to be positioned after.
NEW
104
                \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ], ( \PHP_INT_MAX - 1 ) );
×
NEW
105
                \add_filter( 'wpseo_network_submenu_pages', [ $this, 'add_page' ], ( \PHP_INT_MAX - 1 ) );
×
106
                \add_action( 'admin_init', [ $this, 'do_redirect' ], 1 );
×
107
        }
108

109
        /**
110
         * Adds the page to the (currently) last position in the array.
111
         *
112
         * @param array<string, array<string, array<static|string>>> $pages The pages.
113
         *
114
         * @return array<string, array<string, array<static|string>>> The pages.
115
         */
116
        public function add_page( $pages ) {
×
117
                // Don't show the Upgrade button if Yoast SEO WooCommerce addon is active.
NEW
118
                if ( $this->addon_manager->is_installed( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) ) {
×
NEW
119
                        return $pages;
×
120
                }
121

122
                // Don't show the Upgrade button if Premium is active without the WooCommerce plugin.
NEW
123
                if ( $this->product_helper->is_premium() && ! $this->woocommerce_conditional->is_met() ) {
×
NEW
124
                        return $pages;
×
125
                }
126

127
                $button_content = \__( 'Upgrade', 'wordpress-seo' );
×
128

129
                if ( $this->promotion_manager->is( 'black-friday-promotion' ) ) {
×
130
                        $button_content = ( $this->product_helper->is_premium() ) ? \__( 'Get 30% off', 'wordpress-seo' ) : \__( '30% off - BF Sale', 'wordpress-seo' );
×
131
                }
132

133
                $pages[] = [
×
134
                        General_Page_Integration::PAGE,
×
135
                        '',
×
136
                        '<span class="yst-root"><span class="yst-button yst-w-full yst-whitespace-nowrap yst-button--upsell yst-button--small">' . $button_content . ' </span></span>',
×
137
                        'wpseo_manage_options',
×
138
                        self::PAGE,
×
139
                        static function () {
×
140
                                echo 'redirecting...';
×
141
                        },
×
142
                ];
×
143

144
                return $pages;
×
145
        }
146

147
        /**
148
         * Redirects to the yoast.com.
149
         *
150
         * @return void
151
         */
152
        public function do_redirect(): void {
×
153

154
                if ( $this->current_page_helper->get_current_yoast_seo_page() !== self::PAGE ) {
×
155
                        return;
×
156
                }
157
                $link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-premium' );
×
NEW
158
                if ( $this->woocommerce_conditional->is_met() ) {
×
159
                        $link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-woocommerce' );
×
160
                }
161

162
                \wp_redirect( $link );//phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Safe redirect is used here.
×
163
                exit;
×
164
        }
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc