DeprecatedWordPress.php
4.39 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
<?php
namespace AIOSEO\Plugin\Common\Admin\Notices;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WordPress Deprecated Notice.
*
* @since 4.1.2
*/
class DeprecatedWordPress {
/**
* Class Constructor.
*
* @since 4.1.2
*/
public function __construct() {
add_action( 'wp_ajax_aioseo-dismiss-deprecated-wordpress-notice', [ $this, 'dismissNotice' ] );
}
/**
* Go through all the checks to see if we should show the notice.
*
* @since 4.1.2
*
* @return void
*/
public function maybeShowNotice() {
global $wp_version;
$dismissed = get_option( '_aioseo_deprecated_wordpress_dismissed', true );
if ( '1' === $dismissed ) {
return;
}
// Only show to users that interact with our pluign.
if ( ! current_user_can( 'publish_posts' ) ) {
return;
}
// Only show if WordPress version is deprecated.
if ( version_compare( $wp_version, '5.3', '>=' ) ) {
return;
}
$this->showNotice();
// Print the script to the footer.
add_action( 'admin_footer', [ $this, 'printScript' ] );
}
/**
* Actually show the review plugin.
*
* @since 4.1.2
*
* @return void
*/
public function showNotice() {
$medium = false !== strpos( AIOSEO_PHP_VERSION_DIR, 'pro' ) ? 'proplugin' : 'liteplugin';
?>
<div class="notice notice-warning aioseo-deprecated-wordpress-notice is-dismissible">
<p>
<?php
echo wp_kses(
sprintf(
// Translators: 1 - Opening HTML bold tag, 2 - Closing HTML bold tag.
__( 'Your site is running an %1$soutdated version%2$s of WordPress. We recommend using the latest version of WordPress in order to keep your site secure.', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
'<strong>',
'</strong>'
),
[
'strong' => [],
]
);
?>
<br><br>
<?php
echo wp_kses(
sprintf(
// Translators: 1 - Opening HTML bold tag, 2 - Closing HTML bold tag, 3 - The plugin name ("All in One SEO"), 4 - Opening HTML link tag, 5 - Closing HTML link tag.
__( '%1$sNote:%2$s %3$s will be discontinuing support for WordPress versions older than version 5.3 by the end of %4$s. %5$sRead more for additional information.%6$s', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
'<strong>',
'</strong>',
'AIOSEO',
date( 'Y' ),
'<a href="https://aioseo.com/docs/update-wordpress/?utm_source=WordPress&utm_medium=' . $medium . '&utm_campaign=outdated-wordpress-notice" target="_blank" rel="noopener noreferrer">', // phpcs:ignore Generic.Files.LineLength.MaxExceeded
'</a>'
),
[
'a' => [
'href' => [],
'target' => [],
'rel' => [],
],
'strong' => [],
]
);
?>
</p>
</div>
<?php
// In case this is on plugin activation.
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
/**
* Print the script for dismissing the notice.
*
* @since 4.1.2
*
* @return void
*/
public function printScript() {
// Create a nonce.
$nonce = wp_create_nonce( 'aioseo-dismiss-deprecated-wordpress' );
?>
<script>
window.addEventListener('load', function () {
var dismissBtn
// Add an event listener to the dismiss button.
dismissBtn = document.querySelector('.aioseo-deprecated-wordpress-notice .notice-dismiss')
dismissBtn.addEventListener('click', function (event) {
var httpRequest = new XMLHttpRequest(),
postData = ''
// Build the data to send in our request.
postData += '&action=aioseo-dismiss-deprecated-wordpress-notice'
postData += '&nonce=<?php echo esc_html( $nonce ); ?>'
httpRequest.open('POST', '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>')
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
httpRequest.send(postData)
})
});
</script>
<?php
}
/**
* Dismiss the deprecated WordPress notice.
*
* @since 4.1.2
*
* @return WP_Response The successful response.
*/
public function dismissNotice() {
// Early exit if we're not on a aioseo-dismiss-deprecated-wordpress-notice action.
if ( ! isset( $_POST['action'] ) || 'aioseo-dismiss-deprecated-wordpress-notice' !== $_POST['action'] ) {
return;
}
check_ajax_referer( 'aioseo-dismiss-deprecated-wordpress', 'nonce' );
update_option( '_aioseo_deprecated_wordpress_dismissed', true );
return wp_send_json_success();
}
}