@@ -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 ' )
0 commit comments