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

Yoast / wordpress-seo / 5066322038

pending completion
5066322038

push

github

GitHub
Merge pull request #20316 from Yoast/JRF/ghactions-run-more-selectively

2550 of 29012 relevant lines covered (8.79%)

0.32 hits per line

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

0.0
/src/integrations/admin/old-premium-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations\Admin;
4

5
use WPSEO_Admin_Asset_Manager;
6
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
7
use Yoast\WP\SEO\Helpers\Capability_Helper;
8
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
9
use Yoast\WP\SEO\Helpers\Options_Helper;
10
use Yoast\WP\SEO\Helpers\Product_Helper;
11
use Yoast\WP\SEO\Integrations\Integration_Interface;
12
use Yoast\WP\SEO\Presenters\Admin\Notice_Presenter;
13

14
/**
15
 * Old_Premium_Integration class
16
 */
17
class Old_Premium_Integration implements Integration_Interface {
18

19
        /**
20
         * The minimum Premium version.
21
         */
22
        const MINIMUM_PREMIUM_VERSION = '20.1-RC0';
23

24
        /**
25
         * The options' helper.
26
         *
27
         * @var Options_Helper
28
         */
29
        private $options_helper;
30

31
        /**
32
         * The product helper.
33
         *
34
         * @var Product_Helper
35
         */
36
        private $product_helper;
37

38
        /**
39
         * The capability helper.
40
         *
41
         * @var Capability_Helper
42
         */
43
        private $capability_helper;
44

45
        /**
46
         * The admin asset manager.
47
         *
48
         * @var WPSEO_Admin_Asset_Manager
49
         */
50
        private $admin_asset_manager;
51

52
        /**
53
         * The Current_Page_Helper.
54
         *
55
         * @var Current_Page_Helper
56
         */
57
        private $current_page_helper;
58

59
        /**
60
         * {@inheritDoc}
61
         */
62
        public static function get_conditionals() {
63
                return [ Admin_Conditional::class ];
×
64
        }
65

66
        /**
67
         * Old_Premium_Integration constructor.
68
         *
69
         * @param Options_Helper            $options_helper      The options helper.
70
         * @param Product_Helper            $product_helper      The product helper.
71
         * @param Capability_Helper         $capability_helper   The capability helper.
72
         * @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
73
         * @param Current_Page_Helper       $current_page_helper The Current_Page_Helper.
74
         */
75
        public function __construct(
76
                Options_Helper $options_helper,
77
                Product_Helper $product_helper,
78
                Capability_Helper $capability_helper,
79
                WPSEO_Admin_Asset_Manager $admin_asset_manager,
80
                Current_Page_Helper $current_page_helper
81
        ) {
82
                $this->options_helper      = $options_helper;
×
83
                $this->product_helper      = $product_helper;
×
84
                $this->capability_helper   = $capability_helper;
×
85
                $this->admin_asset_manager = $admin_asset_manager;
×
86
                $this->current_page_helper = $current_page_helper;
×
87
        }
88

89
        /**
90
         * {@inheritDoc}
91
         */
92
        public function register_hooks() {
93
                \add_action( 'admin_notices', [ $this, 'old_premium_notice' ] );
×
94
                \add_action( 'wp_ajax_dismiss_old_premium_notice', [ $this, 'dismiss_old_premium_notice' ] );
×
95
        }
96

97
        /**
98
         * Shows a notice if Premium is older than 20.0-RC1 so Settings might be missing from the UI.
99
         *
100
         * @return void
101
         */
102
        public function old_premium_notice() {
103
                global $pagenow;
×
104
                if ( $pagenow === 'update.php' ) {
×
105
                        return;
×
106
                }
107

108
                if ( $this->notice_was_dismissed_after_current_min_premium_version() ) {
×
109
                        return;
×
110
                }
111

112
                if ( ! $this->capability_helper->current_user_can( 'wpseo_manage_options' ) ) {
×
113
                        return;
×
114
                }
115

116
                if ( $this->premium_is_old() ) {
×
117
                        $this->admin_asset_manager->enqueue_style( 'monorepo' );
×
118

119
                        $is_plugins_page = $this->current_page_helper->get_current_admin_page() === 'plugins.php';
×
120
                        $content         = \sprintf(
×
121
                                /* translators: 1: Yoast SEO Premium, 2 and 3: opening and closing anchor tag. */
122
                                \esc_html__( 'Please %2$supdate %1$s to the latest version%3$s to ensure you can fully use all Premium settings and features.', 'wordpress-seo' ),
×
123
                                'Yoast SEO Premium',
×
124
                                ( $is_plugins_page ) ? '' : '<a href="' . \esc_url( \self_admin_url( 'plugins.php' ) ) . '">',
×
125
                                ( $is_plugins_page ) ? '' : '</a>'
×
126
                        );
×
127
                        // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Output of the title escaped in the Notice_Presenter.
128
                        echo new Notice_Presenter(
×
129
                                /* translators: 1: Yoast SEO Premium */
130
                                \sprintf( \__( 'Update to the latest version of %1$s!', 'wordpress-seo' ), 'Yoast SEO Premium' ),
×
131
                                $content,
×
132
                                null,
×
133
                                null,
×
134
                                true,
×
135
                                'yoast-old-premium-notice'
×
136
                        );
×
137
                        // phpcs:enable
138

139
                        // Enable permanently dismissing the notice.
140
                        echo "<script>
×
141
                function dismiss_old_premium_notice(){
142
                    var data = {
143
                    'action': 'dismiss_old_premium_notice',
144
                    };
145

146
                    jQuery.post( ajaxurl, data, function( response ) {
147
                        jQuery( '#yoast-old-premium-notice' ).hide();
148
                    });
149
                }
150

151
                jQuery( document ).ready( function() {
152
                    jQuery( 'body' ).on( 'click', '#yoast-old-premium-notice .notice-dismiss', function() {
153
                        dismiss_old_premium_notice();
154
                    } );
155
                } );
156
            </script>";
×
157
                }
158
        }
159

160
        /**
161
         * Dismisses the old premium notice.
162
         *
163
         * @return bool
164
         */
165
        public function dismiss_old_premium_notice() {
166
                return $this->options_helper->set( 'dismiss_old_premium_version_notice', self::MINIMUM_PREMIUM_VERSION );
×
167
        }
168

169
        /**
170
         * Returns whether Premium is installed but older than the minimum premium version.
171
         *
172
         * @return bool Whether premium is installed but older than minimum premium version.
173
         */
174
        protected function premium_is_old() {
175
                $premium_version = $this->product_helper->get_premium_version();
×
176
                if ( ! \is_null( $premium_version ) ) {
×
177
                        return \version_compare( $premium_version, self::MINIMUM_PREMIUM_VERSION, '<' );
×
178
                }
179

180
                return false;
×
181
        }
182

183
        /**
184
         * Returns whether the notification was dismissed in a version later than the minimum premium version.
185
         *
186
         * @return bool Whether the notification was dismissed in a version later than the minimum premium version.
187
         */
188
        protected function notice_was_dismissed_after_current_min_premium_version() {
189
                $dismissed_notification_version = $this->options_helper->get( 'dismiss_old_premium_version_notice', '' );
×
190
                if ( ! empty( $dismissed_notification_version ) ) {
×
191
                        return \version_compare( $dismissed_notification_version, self::MINIMUM_PREMIUM_VERSION, '>=' );
×
192
                }
193

194
                return false;
×
195
        }
196
}
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