old-premium-integration.php
5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
namespace Yoast\WP\SEO\Integrations\Admin;
use WPSEO_Admin_Asset_Manager;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Helpers\Capability_Helper;
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Product_Helper;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\Presenters\Admin\Notice_Presenter;
/**
* Old_Premium_Integration class
*/
class Old_Premium_Integration implements Integration_Interface {
/**
* The minimum Premium version.
*/
const MINIMUM_PREMIUM_VERSION = '20.1-RC0';
/**
* The options' helper.
*
* @var Options_Helper
*/
private $options_helper;
/**
* The product helper.
*
* @var Product_Helper
*/
private $product_helper;
/**
* The capability helper.
*
* @var Capability_Helper
*/
private $capability_helper;
/**
* The admin asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
private $admin_asset_manager;
/**
* The Current_Page_Helper.
*
* @var Current_Page_Helper
*/
private $current_page_helper;
/**
* {@inheritDoc}
*/
public static function get_conditionals() {
return [ Admin_Conditional::class ];
}
/**
* Old_Premium_Integration constructor.
*
* @param Options_Helper $options_helper The options helper.
* @param Product_Helper $product_helper The product helper.
* @param Capability_Helper $capability_helper The capability helper.
* @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
* @param Current_Page_Helper $current_page_helper The Current_Page_Helper.
*/
public function __construct(
Options_Helper $options_helper,
Product_Helper $product_helper,
Capability_Helper $capability_helper,
WPSEO_Admin_Asset_Manager $admin_asset_manager,
Current_Page_Helper $current_page_helper
) {
$this->options_helper = $options_helper;
$this->product_helper = $product_helper;
$this->capability_helper = $capability_helper;
$this->admin_asset_manager = $admin_asset_manager;
$this->current_page_helper = $current_page_helper;
}
/**
* {@inheritDoc}
*/
public function register_hooks() {
\add_action( 'admin_notices', [ $this, 'old_premium_notice' ] );
\add_action( 'wp_ajax_dismiss_old_premium_notice', [ $this, 'dismiss_old_premium_notice' ] );
}
/**
* Shows a notice if Premium is older than 20.0-RC1 so Settings might be missing from the UI.
*
* @return void
*/
public function old_premium_notice() {
global $pagenow;
if ( $pagenow === 'update.php' ) {
return;
}
if ( $this->notice_was_dismissed_after_current_min_premium_version() ) {
return;
}
if ( ! $this->capability_helper->current_user_can( 'wpseo_manage_options' ) ) {
return;
}
if ( $this->premium_is_old() ) {
$this->admin_asset_manager->enqueue_style( 'monorepo' );
$is_plugins_page = $this->current_page_helper->get_current_admin_page() === 'plugins.php';
$content = \sprintf(
/* translators: 1: Yoast SEO Premium, 2 and 3: opening and closing anchor tag. */
\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' ),
'Yoast SEO Premium',
( $is_plugins_page ) ? '' : '<a href="' . \esc_url( \self_admin_url( 'plugins.php' ) ) . '">',
( $is_plugins_page ) ? '' : '</a>'
);
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Output of the title escaped in the Notice_Presenter.
echo new Notice_Presenter(
/* translators: 1: Yoast SEO Premium */
\sprintf( \__( 'Update to the latest version of %1$s!', 'wordpress-seo' ), 'Yoast SEO Premium' ),
$content,
null,
null,
true,
'yoast-old-premium-notice'
);
// phpcs:enable
// Enable permanently dismissing the notice.
echo "<script>
function dismiss_old_premium_notice(){
var data = {
'action': 'dismiss_old_premium_notice',
};
jQuery.post( ajaxurl, data, function( response ) {
jQuery( '#yoast-old-premium-notice' ).hide();
});
}
jQuery( document ).ready( function() {
jQuery( 'body' ).on( 'click', '#yoast-old-premium-notice .notice-dismiss', function() {
dismiss_old_premium_notice();
} );
} );
</script>";
}
}
/**
* Dismisses the old premium notice.
*
* @return bool
*/
public function dismiss_old_premium_notice() {
return $this->options_helper->set( 'dismiss_old_premium_version_notice', self::MINIMUM_PREMIUM_VERSION );
}
/**
* Returns whether Premium is installed but older than the minimum premium version.
*
* @return bool Whether premium is installed but older than minimum premium version.
*/
protected function premium_is_old() {
$premium_version = $this->product_helper->get_premium_version();
if ( ! \is_null( $premium_version ) ) {
return \version_compare( $premium_version, self::MINIMUM_PREMIUM_VERSION, '<' );
}
return false;
}
/**
* Returns whether the notification was dismissed in a version later than the minimum premium version.
*
* @return bool Whether the notification was dismissed in a version later than the minimum premium version.
*/
protected function notice_was_dismissed_after_current_min_premium_version() {
$dismissed_notification_version = $this->options_helper->get( 'dismiss_old_premium_version_notice', '' );
if ( ! empty( $dismissed_notification_version ) ) {
return \version_compare( $dismissed_notification_version, self::MINIMUM_PREMIUM_VERSION, '>=' );
}
return false;
}
}