Skip to content

Commit ae1e5d8

Browse files
authored
Merge pull request #51 from imjuniper/develop
Fix all Plugin Check errors
2 parents e6263f0 + 2ff526b commit ae1e5d8

8 files changed

Lines changed: 49 additions & 35 deletions

File tree

assets/js/admin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ window.addEventListener("DOMContentLoaded", (_evt) => {
4848
headers: { "Content-Type": "application/x-www-form-urlencoded" },
4949
body: new URLSearchParams({
5050
action: "hestia_nginx_cache_manual_purge",
51-
wp_nonce: nonce.textContent,
51+
_wpnonce: nonce.textContent,
5252
}),
5353
});
5454

hestia-nginx-cache.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Plugin Name: Hestia Nginx Cache
1212
* Description: Hestia Nginx Cache Integration for WordPress. Auto-purges the Nginx cache when needed.
1313
* Plugin URI: https://github.com/imjuniper/hestia-nginx-cache
14-
* Version: 2.4.3
14+
* Version: 2.4.4
1515
* Requires at least: 4.8
1616
* Requires PHP: 5.4
1717
* Author: Juniper Bouchard
@@ -28,7 +28,7 @@
2828
class Hestia_Nginx_Cache
2929
{
3030
public const NAME = 'hestia-nginx-cache';
31-
public const VERSION = '2.4.3';
31+
public const VERSION = '2.4.4';
3232

3333
private static $instance = null;
3434
public static $plugin_basename = null;
@@ -86,8 +86,6 @@ public static function get_instance()
8686

8787
public function init()
8888
{
89-
load_plugin_textdomain(self::NAME, false, self::NAME . '/languages');
90-
9189
// Register site_health
9290
if (is_admin()) {
9391
require_once __DIR__ . '/includes/site_health.php';

includes/admin.php

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function validate_options($input)
8989

9090
$input['port'] = trim($input['port']);
9191
$input['secret_key'] = trim($input['secret_key']);
92-
$input['domain'] = parse_url($input['domain'], PHP_URL_HOST) ?: $input['domain'];
92+
$input['domain'] = wp_parse_url($input['domain'], PHP_URL_HOST) ?: $input['domain'];
9393

9494
if (!preg_match('/^\d{1,5}$/i', $input['port'])) {
9595
$input['port'] = '';
@@ -110,45 +110,45 @@ public function api_settings_text()
110110
public function api_setting_host()
111111
{
112112
$options = get_option($this->plugin::NAME);
113-
$host = $this->plugin::$is_configured ? esc_attr($options["host"]) : "";
114-
echo '<input id="api_setting_host" name="' . $this->plugin::NAME . '[host]" type="text" value="' . $host . '" required />';
113+
$host = $this->plugin::$is_configured ? $options["host"] : "";
114+
echo '<input id="api_setting_host" name="' . esc_attr($this->plugin::NAME) . '[host]" type="text" value="' . esc_attr($host) . '" required />';
115115
}
116116

117117
public function api_setting_port()
118118
{
119119
$options = get_option($this->plugin::NAME);
120-
$port = $this->plugin::$is_configured ? esc_attr($options["port"]) : "";
121-
echo '<input id="api_setting_port" name="' . $this->plugin::NAME . '[port]" type="text" value="' . $port . '" required />';
120+
$port = $this->plugin::$is_configured ? $options["port"] : "";
121+
echo '<input id="api_setting_port" name="' . esc_attr($this->plugin::NAME) . '[port]" type="text" value="' . esc_attr($port) . '" required />';
122122
}
123123

124124
public function api_setting_access_key()
125125
{
126126
$options = get_option($this->plugin::NAME);
127-
$access_key = $this->plugin::$is_configured ? esc_attr($options["access_key"]) : "";
128-
echo '<input id="api_setting_access_key" name="' . $this->plugin::NAME . '[access_key]" type="text" value="' . $access_key . '" required />';
127+
$access_key = $this->plugin::$is_configured ? $options["access_key"] : "";
128+
echo '<input id="api_setting_access_key" name="' . esc_attr($this->plugin::NAME) . '[access_key]" type="text" value="' . esc_attr($access_key) . '" required />';
129129
}
130130

131131
public function api_setting_secret_key()
132132
{
133133
$options = get_option($this->plugin::NAME);
134134
$secret_key = $this->plugin::$is_configured ? $options["secret_key"] : "";
135135
$secret_key = $secret_key != "" ? '#secret_key_PLACEHOLDER#' : '';
136-
echo '<input id="api_setting_secret_key" name="' . $this->plugin::NAME . '[secret_key]" type="password" value="' . $secret_key . '" required />';
136+
echo '<input id="api_setting_secret_key" name="' . esc_attr($this->plugin::NAME) . '[secret_key]" type="password" value="' . esc_attr($secret_key) . '" required />';
137137
}
138138

139139
public function api_setting_user()
140140
{
141141
$options = get_option($this->plugin::NAME);
142-
$user = $this->plugin::$is_configured ? esc_attr($options["user"]) : "";
143-
echo '<input id="api_setting_user" name="' . $this->plugin::NAME . '[user]" type="text" value="' . $user . '" required />';
142+
$user = $this->plugin::$is_configured ? $options["user"] : "";
143+
echo '<input id="api_setting_user" name="' . esc_attr($this->plugin::NAME) . '[user]" type="text" value="' . esc_attr($user) . '" required />';
144144
}
145145

146146
public function api_setting_domain()
147147
{
148148
$options = get_option($this->plugin::NAME);
149-
$domain = $this->plugin::$is_configured ? esc_attr($options["domain"]) : "";
150-
$domain = $domain != "" ? $domain : parse_url(get_site_url(), PHP_URL_HOST);
151-
echo '<input id="api_setting_domain" name="' . $this->plugin::NAME . '[domain]" type="text" value="' . $domain . '" required />';
149+
$domain = $this->plugin::$is_configured ? $options["domain"] : "";
150+
$domain = $domain != "" ? $domain : wp_parse_url(get_site_url(), PHP_URL_HOST);
151+
echo '<input id="api_setting_domain" name="' . esc_attr($this->plugin::NAME) . '[domain]" type="text" value="' . esc_attr($domain) . '" required />';
152152
}
153153

154154
public function plugin_settings_text()
@@ -165,14 +165,14 @@ public function plugin_setting_show_purge_button()
165165
$show_adminbar_button = $options["show_adminbar_button"];
166166
}
167167
}
168-
echo '<input id="plugin_setting_show_purge_button" name="' . $this->plugin::NAME . '[show_adminbar_button]" type="checkbox" value="1" ' . checked(1, $show_adminbar_button, false) . ' />';
168+
echo '<input id="plugin_setting_show_purge_button" name="' . esc_attr($this->plugin::NAME) . '[show_adminbar_button]" type="checkbox" value="1" ' . checked(1, $show_adminbar_button, false) . ' />';
169169
}
170170

171171
public function plugin_setting_purge_button_text()
172172
{
173173
$options = get_option($this->plugin::NAME);
174-
$adminbar_button_text = $this->plugin::$is_configured ? esc_attr($options["adminbar_button_text"]) : "";
175-
echo '<input id="plugin_setting_purge_button_text" placeholder="' . esc_html__('Leave empty for default', 'hestia-nginx-cache') . '" name="' . $this->plugin::NAME . '[adminbar_button_text]" type="text" value="' . $adminbar_button_text . '" />';
174+
$adminbar_button_text = $this->plugin::$is_configured ? $options["adminbar_button_text"] : "";
175+
echo '<input id="plugin_setting_purge_button_text" placeholder="' . esc_attr__('Leave empty for default', 'hestia-nginx-cache') . '" name="' . esc_attr($this->plugin::NAME) . '[adminbar_button_text]" type="text" value="' . esc_attr($adminbar_button_text) . '" />';
176176
}
177177

178178
function plugin_setting_automatic_purge(){
@@ -183,7 +183,7 @@ function plugin_setting_automatic_purge(){
183183
$disable_automatic_purge = $options["disable_automatic_purge"];
184184
}
185185
}
186-
echo '<input id="plugin_setting_automatic_purge" name="' . $this->plugin::NAME . '[disable_automatic_purge]" type="checkbox" value="1" ' . checked(1, $disable_automatic_purge, false) . ' />';
186+
echo '<input id="plugin_setting_automatic_purge" name="' . esc_attr($this->plugin::NAME) . '[disable_automatic_purge]" type="checkbox" value="1" ' . checked(1, $disable_automatic_purge, false) . ' />';
187187
}
188188

189189
public function add_settings_page()
@@ -220,10 +220,19 @@ public function render_settings_page()
220220

221221
public function add_scripts_and_styles()
222222
{
223-
wp_register_style($this->plugin::NAME, plugins_url('assets/css/admin.css', dirname(__FILE__)));
223+
wp_register_style(
224+
$this->plugin::NAME,
225+
plugins_url('assets/css/admin.css', dirname(__FILE__)),
226+
array(),
227+
$this->plugin::VERSION);
224228
wp_enqueue_style($this->plugin::NAME);
225229

226-
wp_register_script($this->plugin::NAME, plugins_url('assets/js/admin.js', dirname(__FILE__)));
230+
wp_register_script(
231+
$this->plugin::NAME,
232+
plugins_url('assets/js/admin.js', dirname(__FILE__)),
233+
array(),
234+
$this->plugin::VERSION,
235+
array('in_footer' => false));
227236
wp_enqueue_script($this->plugin::NAME);
228237
wp_localize_script(
229238
$this->plugin::NAME,
@@ -252,7 +261,7 @@ public function add_purge_button($wp_admin_bar)
252261
public function embed_wp_nonce()
253262
{
254263
echo '<span id="hestia-nginx-cache-purge-wp-nonce">'
255-
. wp_create_nonce('hestia-nginx-cache-purge-wp-nonce')
264+
. esc_html(wp_create_nonce('hestia-nginx-cache-purge-wp-nonce'))
256265
. '</span>';
257266
}
258267

@@ -270,7 +279,11 @@ public function purge()
270279
]);
271280
}
272281

273-
if (!wp_verify_nonce($_POST['wp_nonce'], 'hestia-nginx-cache-purge-wp-nonce')) {
282+
$query_arg = '_wpnonce';
283+
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
284+
$valid_nonce = isset( $_REQUEST[ $query_arg ] ) ? wp_verify_nonce( $_REQUEST[ $query_arg ], 'hestia-nginx-cache-purge-wp-nonce' ) : false;
285+
286+
if (!$valid_nonce) {
274287
wp_send_json_error([
275288
'message' => esc_html__('The Hestia Nginx Cache could not be purged!', 'hestia-nginx-cache'),
276289
'error' => esc_html__('Invalid nonce.', 'hestia-nginx-cache')

languages/hestia-nginx-cache-fr_CA.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
msgid ""
22
msgstr ""
3-
"Project-Id-Version: Hestia Nginx Cache 2.4.3\n"
3+
"Project-Id-Version: Hestia Nginx Cache 2.4.4\n"
44
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hestia-nginx-cache\n"
55
"Last-Translator: Juniper Bouchard <juniper@bchrd.ca>\n"
66
"Language-Team: Unknown\n"

languages/hestia-nginx-cache-pt_BR.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
msgid ""
22
msgstr ""
3-
"Project-Id-Version: Hestia Nginx Cache 2.4.3\n"
3+
"Project-Id-Version: Hestia Nginx Cache 2.4.4\n"
44
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hestia-nginx-"
55
"cache\n"
66
"Last-Translator: Maison da Silva\n"

languages/hestia-nginx-cache.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is distributed under the GPL v3.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: Hestia Nginx Cache 2.4.3\n"
5+
"Project-Id-Version: Hestia Nginx Cache 2.4.4\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hestia-nginx-cache\n"
77
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
88
"Language-Team: LANGUAGE <LL@li.org>\n"

readme.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Contributors: imjuniper, jaapmarcus
33
Tags: cache, flush, purge, hestia, nginx
44
Requires at least: 4.8
5-
Tested up to: 6.8
5+
Tested up to: 7.1
66
Requires PHP: 5.4
7-
Stable tag: 2.4.3
7+
Stable tag: 2.4.4
88
License: GPL v3
99
License URI: http://www.gnu.org/licenses/gpl-3.0.txt
1010

@@ -71,6 +71,9 @@ You can report security bugs through the Patchstack Vulnerability Disclosure Pro
7171

7272
== Changelog ==
7373

74+
= 2.4.4 =
75+
* Fix warnings & errors from Plugin Check
76+
7477
= 2.4.3 =
7578
* Update translations for Brazilian Portuguese
7679

wp-cli.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

33
if (!defined('ABSPATH')) {
4-
die();
4+
die();
55
}
66

77
if (!defined('WP_CLI')) return;
88

9-
class WP_CLI_WP_Hestia_Nginx_Cache extends WP_CLI_Command {
9+
class Hestia_Nginx_Cache_CLI_Command extends WP_CLI_Command {
1010

1111
public function __construct(){
1212
$this -> plugin = Hestia_Nginx_Cache::get_instance();
@@ -45,11 +45,11 @@ public function setup($args, $assoc_args){
4545
}
4646
//validate
4747
$port = intval($port);
48-
$domain = parse_url($domain, PHP_URL_HOST) ?: $domain;
48+
$domain = wp_parse_url($domain, PHP_URL_HOST) ?: $domain;
4949

5050
$options = array('access_key' => $access_key, 'secret_key' => $secret_key, 'user' => $user, 'domain' => $domain, 'host' => $host, 'port' => $port, 'disable_automatic_purge' => $disable_automatic_purge);
5151
update_option(Hestia_Nginx_Cache::NAME, $options);
5252
}
5353
}
5454

55-
WP_CLI::add_command('hestia-cache', 'WP_CLI_WP_Hestia_Nginx_Cache');
55+
WP_CLI::add_command('hestia-cache', 'Hestia_Nginx_Cache_CLI_Command');

0 commit comments

Comments
 (0)