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

Yoast / wordpress-seo / 993f259bead15d3b90dcff95657b8a588f66ed76

21 Nov 2025 02:03PM UTC coverage: 52.891% (-0.5%) from 53.366%
993f259bead15d3b90dcff95657b8a588f66ed76

Pull #22743

github

web-flow
Merge 8ea181540 into 530e8fcfb
Pull Request #22743: Redesign ai brand insights button & change behavior of upgrade button

8318 of 15589 branches covered (53.36%)

Branch coverage included in aggregate %.

2 of 46 new or added lines in 4 files covered. (4.35%)

2 existing lines in 2 files now uncovered.

31815 of 60289 relevant lines covered (52.77%)

47826.41 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_Shortlinker;
6
use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait;
7
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
8
use Yoast\WP\SEO\General\User_Interface\General_Page_Integration;
9
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
10
use Yoast\WP\SEO\Helpers\Product_Helper;
11
use Yoast\WP\SEO\Integrations\Integration_Interface;
12
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
13

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

19
        use Admin_Conditional_Trait;
20

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

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

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

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

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

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

61
        /**
62
         * Constructor.
63
         *
64
         * @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce conditional.
65
         * @param WPSEO_Shortlinker       $shortlinker             The shortlinker.
66
         * @param Product_Helper          $product_helper          The product helper.
67
         * @param Current_Page_Helper     $current_page_helper     The current page helper.
68
         * @param Promotion_Manager       $promotion_manager       The promotion manager.
69
         */
70
        public function __construct(
×
71
                WooCommerce_Conditional $woocommerce_conditional,
72
                WPSEO_Shortlinker $shortlinker,
73
                Product_Helper $product_helper,
74
                Current_Page_Helper $current_page_helper,
75
                Promotion_Manager $promotion_manager
76
        ) {
77
                $this->woocommerce_conditional = $woocommerce_conditional;
×
78
                $this->shortlinker             = $shortlinker;
×
79
                $this->product_helper          = $product_helper;
×
80
                $this->current_page_helper     = $current_page_helper;
×
81
                $this->promotion_manager       = $promotion_manager;
×
82
        }
83

84
        /**
85
         * Initializes the integration.
86
         *
87
         * This is the place to register hooks and filters.
88
         *
89
         * @return void
90
         */
91
        public function register_hooks() {
×
92
                // Add page with PHP_INT_MAX - 1 to allow other items (like Brand Insights) to be positioned after.
NEW
93
                \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ], ( \PHP_INT_MAX - 1 ) );
×
NEW
94
                \add_filter( 'wpseo_network_submenu_pages', [ $this, 'add_page' ], ( \PHP_INT_MAX - 1 ) );
×
UNCOV
95
                \add_action( 'admin_init', [ $this, 'do_redirect' ], 1 );
×
96
        }
97

98
        /**
99
         * Adds the page to the (currently) last position in the array.
100
         *
101
         * @param array<string, array<string, array<static|string>>> $pages The pages.
102
         *
103
         * @return array<string, array<string, array<static|string>>> The pages.
104
         */
105
        public function add_page( $pages ) {
×
106
                // Check if the Yoast SEO WooCommerce addon is active.
NEW
107
                $woo_seo_plugin_active = \is_plugin_active( 'wpseo-woocommerce/wpseo-woocommerce.php' );
×
108

109
                // Don't show the Upgrade button if Yoast SEO WooCommerce addon is active.
NEW
110
                if ( $woo_seo_plugin_active ) {
×
NEW
111
                        return $pages;
×
112
                }
113

114
                // Don't show the Upgrade button if Premium is active without the WooCommerce plugin.
NEW
115
                if ( $this->product_helper->is_premium() && ! $this->woocommerce_conditional->is_met() ) {
×
NEW
116
                        return $pages;
×
117
                }
118

119
                $button_content = \__( 'Upgrade', 'wordpress-seo' );
×
120

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

125
                $pages[] = [
×
126
                        General_Page_Integration::PAGE,
×
127
                        '',
×
128
                        '<span class="yst-root"><span class="yst-button yst-w-full yst-whitespace-nowrap yst-button--upsell yst-button--small">' . $button_content . ' </span></span>',
×
129
                        'wpseo_manage_options',
×
130
                        self::PAGE,
×
131
                        static function () {
×
132
                                echo 'redirecting...';
×
133
                        },
×
134
                ];
×
135

136
                return $pages;
×
137
        }
138

139
        /**
140
         * Redirects to the yoast.com.
141
         *
142
         * @return void
143
         */
144
        public function do_redirect(): void {
×
145

146
                if ( $this->current_page_helper->get_current_yoast_seo_page() !== self::PAGE ) {
×
147
                        return;
×
148
                }
149
                $link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-premium' );
×
NEW
150
                if ( $this->product_helper->is_premium() && $this->woocommerce_conditional->is_met() ) {
×
NEW
151
                        $link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-woocommerce' );
×
152
                }
153
                elseif ( $this->woocommerce_conditional->is_met() ) {
×
154
                        $link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-woocommerce' );
×
155
                }
156

157
                \wp_redirect( $link );//phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Safe redirect is used here.
×
158
                exit;
×
159
        }
160
}
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

© 2025 Coveralls, Inc