PluginProbe
ezCache / 1.3.10
ezCache v1.3.10
2.6.5 2.6.4 2.6.2 2.6.3 2.6.1 2.6.0 2.5.6 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5 2.2.1 2.2.2 trunk 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.3 1.3.1 1.3.10 1.3.11 All 49 releases
ezcache / includes / Admin.php

Admin.php in ezCache 1.3.10, at includes/Admin.php

695 lines 34.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Upress\EzCache;
4
5 use WP_Admin_Bar;
6 use wpdb;
7
8 class Admin {
9 /** @var Plugin */
10 private $plugin;
11 protected static $svg = '<svg viewBox="0 0 480 480" version="1.1" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" xmlns:serif="http://www.serif.com/" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2">
12 <g id="Camada-1" serif:id="Camada 1" fill-rule="nonzero">
13 <path d="M206.088 138.266l-90.584 127.353h115.3l-67.078 160.647 201.096-213.077H254.006l53.292-74.923h-101.21z" fill="#fc0"/>
14 <path d="M205.088 138.266l-90.585 127.352h115.3l-67.078 160.647L285.68 239.266H180.327l75.364-101h-50.603z" fill="url(#_Linear1)"/>
15 </g>
16 <defs>
17 <linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(171.176 0 0 -171.176 114.504 282.266)">
18 <stop offset="0" stop-color="#deb203" stop-opacity="1"/>
19 <stop offset="1" stop-color="#fc0" stop-opacity="1"/>
20 </linearGradient>
21 </defs>
22 </svg> ';
23
24 function __construct( $plugin ) {
25 $this->plugin = $plugin;
26
27 // skip any admin related stuff when doing ajax, cron or rest
28 if ( (defined( 'DOING_AJAX' ) && DOING_AJAX) || (defined( 'DOING_CRON' ) && DOING_CRON) || (defined( 'REST_REQUEST' ) && REST_REQUEST) ) {
29 return;
30 }
31
32 add_action( 'admin_init', [ $this, 'start_session' ] );
33 add_action( 'admin_init', [ $this, 'register_settings' ] );
34 add_action( 'admin_menu', [ $this, 'register_menu' ] );
35 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
36 add_action( 'plugin_action_links_' . plugin_basename( $this->plugin->plugin_file ), [
37 $this,
38 'plugin_action_links'
39 ] );
40 add_action( 'admin_notices', [ $this, 'maybe_show_advanced_cache_notice' ] );
41
42 add_action( 'admin_bar_menu', [ $this, 'add_admin_bar_button' ], 999 );
43 add_action( 'admin_post_wpb_clear_cache', [ $this, 'admin_clear_cache' ] );
44 add_action( 'admin_post_nopriv_wpb_clear_cache', [ $this, 'admin_clear_cache' ] );
45 add_action( 'admin_post_wpb_repair_install', [ $this, 'admin_repair_installation' ] );
46 add_action( 'delete_attachment', [ $this, 'delete_webp_image' ] );
47
48 add_action( 'init', [ $this, 'register_post_meta' ] );
49 add_action( 'add_meta_boxes', [ $this, 'post_cache_metabox' ] );
50 add_action( 'save_post', [ $this, 'save_post_cache_metabox' ] );
51 }
52
53 /**
54 * Delete the webp versions when the image is deleted
55 *
56 * @param int $attachment_id
57 */
58 function delete_webp_image( $attachment_id ) {
59 /** @var wpdb $wpdb */
60 global $wpdb;
61
62 $upload_dir = wp_upload_dir()['basedir'];
63
64 $meta = wp_get_attachment_metadata( $attachment_id );
65 if ( ! $meta || ! isset( $meta['file'] ) ) {
66 return;
67 }
68
69 if ( ! isset( $meta['sizes'] ) ) {
70 $meta['sizes'] = [];
71 }
72
73 $meta['sizes'][] = [ 'file' => $meta['file'] ];
74
75 $hashes = [];
76 foreach ( $meta['sizes'] as $size ) {
77 $image_path = trailingslashit( $upload_dir ) . $meta['file'];
78 $ext = pathinfo( $image_path, PATHINFO_EXTENSION );
79 $image_webp_path = preg_replace( '/^(.+)\.' . preg_quote( $ext, '/' ) . '$/u', '$1.webp', $image_path );
80
81 $hashes[] = sha1( $image_path );
82
83 if ( file_exists( $image_webp_path ) ) {
84 unlink( $image_webp_path );
85 }
86 }
87
88 $wpdb->query(
89 $wpdb->prepare(
90 "DELETE FROM `{$wpdb->prefix}ezcache_webp_images` WHERE `uid` IN (" . substr( str_repeat( "%d, ", count( $hashes ) ), 0, - 2 ) . ")",
91 $hashes
92 )
93 );
94
95 $wpdb->query( "OPTIMIZE TABLE `{$wpdb->prefix}ezcache_webp_images`" );
96 }
97
98 /**
99 * Register the post meta fields
100 */
101 function register_post_meta() {
102 if ( function_exists( 'register_post_meta' ) ) {
103 register_post_meta( 'post', '_ezcache_do_not_cache_post', [
104 'show_in_rest' => true,
105 'single' => true,
106 'type' => 'bool',
107 'auth_callback' => function () {
108 return current_user_can( 'edit_posts' );
109 }
110 ] );
111 }
112 }
113
114 /**
115 * Register the meta box
116 */
117 function post_cache_metabox() {
118 global $post_type;
119
120 if ( 'attachement' == $post_type ) {
121 return;
122 }
123
124 add_meta_box(
125 'ezcache_metabox',
126 __( 'Caching', 'ezcache' ),
127 [ $this, 'post_cache_metabox_output' ],
128 null,
129 'side'
130 );
131 }
132
133 /**
134 * Render the post meta box
135 *
136 * @param $post
137 */
138 function post_cache_metabox_output( $post ) {
139 global $post_type_object;
140
141 $value = get_post_meta( $post->ID, '_ezcache_do_not_cache_post', true );
142 wp_nonce_field( 'ezcache_metabox', '_eznonce' );
143 ?>
144 <div class="components-panel__row">
145 <div class="components-base-control">
146 <input type="checkbox"
147 id="ezcache_no_cache"
148 name="ezcache_no_cache"
149 class="components-checkbox-control__input"
150 <?php checked( $value ); ?>
151 >
152 <label class="components-checkbox-control__label" for="ezcache_no_cache">
153 <?php echo 'page' == $post_type_object->capability_type ? esc_html__( 'Do not cache this page', 'ezcache' ) : esc_html__( 'Do not cache this post', 'ezcache' ); ?>
154 </label>
155 </div>
156 </div>
157 <?php
158 }
159
160 /**
161 * Save the meta box settings
162 *
163 * @param $post_id
164 */
165 function save_post_cache_metabox( $post_id ) {
166 if ( ! isset( $_POST['_eznonce'] ) || ! wp_verify_nonce( $_POST['_eznonce'], 'ezcache_metabox' ) ) {
167 return;
168 }
169
170 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
171 return;
172 }
173
174 if ( ! current_user_can( 'edit_post', $post_id ) ) {
175 return;
176 }
177
178 if ( isset( $_POST['ezcache_no_cache'] ) ) {
179 update_post_meta( $post_id, '_ezcache_do_not_cache_post', true );
180 Cache::instance()->clear_cache_single( $post_id );
181 } else {
182 delete_post_meta( $post_id, '_ezcache_do_not_cache_post' );
183 }
184 }
185
186 /**
187 * Add settings link to the plugin action links
188 *
189 * @param array $links
190 *
191 * @return array
192 */
193 function plugin_action_links( $links ) {
194 $links[] = sprintf(
195 '<a href="%s">%s</a>',
196 admin_url( 'admin.php?page=ezcache' ),
197 __( 'Settings' )
198 );
199
200 return $links;
201 }
202
203 /**
204 * Add the menu to the admin bar
205 *
206 * @param WP_Admin_Bar $wp_admin_bar
207 */
208 function add_admin_bar_button( $wp_admin_bar ) {
209 if ( ! current_user_can( 'manage_options' ) ) {
210 return;
211 }
212
213 $referer = rawurlencode( wp_unslash( remove_query_arg( 'fl_builder', $_SERVER['REQUEST_URI'] ) ) );
214 $svg = preg_replace( '/<svg(\s+?)(?:(?:style=[\'"]([\s\S]+?);?[\'"]([\s\S]*?))|([\s\S]*?))>/i', '<svg class="ab-icon" style="height:1em;width:auto;color:#a0a5aa;color:rgba(240,245,250,.6);$2" $3$4>', self::$svg );
215
216 $wp_admin_bar->add_menu( [
217 'id' => 'ezcache',
218 'title' => $svg . __( 'ezCache', 'ezcache' ),
219 'href' => admin_url( 'admin.php?page=ezcache' ),
220 ] );
221
222 $wp_admin_bar->add_menu( [
223 'id' => 'ezcache-settings',
224 'parent' => 'ezcache',
225 'title' => __( 'Settings', 'ezcache' ),
226 'href' => admin_url( 'admin.php?page=ezcache' ),
227 ] );
228
229 $wp_admin_bar->add_menu( [
230 'id' => 'ezcache-clear-cache',
231 'parent' => 'ezcache',
232 'title' => __( 'Clear Cache', 'ezcache' ),
233 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=wpb_clear_cache&_wp_http_referer=' . $referer ), 'wpb-clear-cache' ),
234 ] );
235 }
236
237 /**
238 * Make sure we have a session
239 */
240 function start_session() {
241 if ( session_status() == PHP_SESSION_NONE ) {
242 session_start();
243 }
244 }
245
246 /**
247 * Register settings for the plugin
248 */
249 function register_settings() {
250 register_setting( $this->plugin->plugin_settings_key . '_group', $this->plugin->plugin_settings_key );
251 }
252
253 /**
254 * Add the menu under the 'Settings' sidebar item
255 */
256 function register_menu() {
257 global $submenu;
258
259 add_menu_page(
260 __( 'ezCache' ),
261 __( 'ezCache' ),
262 'manage_options',
263 'ezcache',
264 [ $this, 'settings_page' ],
265 'data:image/svg+xml;base64,' . base64_encode( self::$svg )
266 );
267
268 $urls = [
269 __( 'Statistics', 'ezcache' ) => '/',
270 __( 'Settings', 'ezcache' ) => '/settings',
271 __( 'Advanced Settings', 'ezcache' ) => '/advanced',
272 __( 'License', 'ezcache' ) => '/license',
273 ];
274
275 if ( ! isset( $submenu['ezcache'] ) ) {
276 $submenu['ezcache'] = [];
277 }
278
279 foreach ( $urls as $title => $url ) {
280 $submenu['ezcache'][] = [ $title, 'manage_options', admin_url( 'admin.php?page=ezcache' ) . '#' . $url ];
281 }
282 }
283
284 /**
285 * Render the settings page
286 */
287 function settings_page() {
288 $trans = $this->getJsTraslations();
289 ?>
290 <div class="wrap"><h1 aria-hidden="true"><!-- WordPress notices trap --></h1></div>
291 <div id="ezcache-options" class="wrap ezcache-options">
292 <!--suppress HtmlUnknownTag -->
293 <ezc-options>
294 <div class="ezcache-options--preload" aria-hidden="true">
295 <header class="ezcache-header">
296 <h1>
297 <svg viewBox="0 0 360 68" version="1.1" xmlns="http://www.w3.org/2000/svg"
298 xml:space="preserve" fill-rule="evenodd"
299 clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" class="logo">
300 <g id="Camada-1" fill-rule="nonzero">
301 <path d="M51.154 53.752H13.691V37.239h22.056l9.144-12.855h-31.2V13.378H52.72L62.235 0H0v67.338h45.91l5.244-13.586z"
302 fill="#1e1e1e"></path>
303 <path d="M72.596 24.521h21.219L53.38 67.338h58.228V54.797H80.976l39.09-41.42H80.389l-7.794 11.144z"
304 fill="#1e1e1e"></path>
305 <path d="M57.073 13.378L40.101 37.239h21.603l-12.568 30.1 37.678-39.923H66.051l9.985-14.038H57.073z"
306 fill="#fc0"></path>
307 <path d="M57.074 13.378L40.102 37.239h21.602L49.136 67.338l23.038-35.036H52.435l14.12-18.924h-9.481z"
308 fill="url(#_Linear1)"></path>
309 <path d="M200.202 47.707h-19.221l9.611-22.993 9.61 22.993zm8.279 19.631h10.645l-23.212-53.965h-10.645l-23.213 53.965h10.572l4.435-10.163h27.056l4.362 10.163z"
310 fill="gray"></path>
311 <path d="M313.541 67.338V13.373h-9.684V36.29h-25.43V13.373h-9.758v53.965h9.758v-22.03h25.43v22.03h9.684z"
312 fill="gray"></path>
313 <path d="M360 57.728h-29.053V44.865h16.255l3.911-9.092h-20.166V22.835h24.983l4.07-9.461h-38.736v53.964H360v-9.61z"
314 fill="gray"></path>
315 <path d="M143.812 13.373h15.746v9.314h-15.746c-12.493 0-17.89 9.315-17.815 17.964.073 8.575 5.026 17.52 17.815 17.52h15.659l-3.943 9.167H143.812c-19.22 0-27.352-13.233-27.426-26.687-.073-13.528 8.723-27.278 27.426-27.278z"
316 fill="gray"></path>
317 <path d="M245.201 13.373h15.746v9.314H245.201c-12.493 0-17.89 9.315-17.816 17.964.074 8.575 5.027 17.52 17.816 17.52h15.746v9.167H245.201c-19.221 0-27.352-13.233-27.426-26.687-.074-13.528 8.723-27.278 27.426-27.278"
318 fill="gray"></path>
319 </g>
320 <defs>
321 <linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0"
322 gradientUnits="userSpaceOnUse"
323 gradientTransform="matrix(32.072 0 0 -32.072 40.101 40.358)">
324 <stop offset="0" stop-color="#deb203" stop-opacity="1"></stop>
325 <stop offset="1" stop-color="#fc0" stop-opacity="1"></stop>
326 </linearGradient>
327 </defs>
328 </svg>
329 </h1>
330 </header>
331 <div class="row">
332 <div class="col-12 order-first col-sm-4 col-md-3 col-xl-2">
333 <nav class="ezcache-nav">
334 <a href="#" class="nav-item">
335 <?php echo str_repeat( 'â– ', mb_strlen( $trans['stats'] ) ); ?>
336 </a>
337 <a href="#" class="nav-item">
338 <?php echo str_repeat( 'â– ', mb_strlen( $trans['settings'] ) ); ?>
339 </a>
340 <a href="#" class="nav-item">
341 <?php echo str_repeat( 'â– ', mb_strlen( $trans['advanced_settings'] ) ); ?>
342 </a>
343 <a href="#" class="nav-item">
344 <?php echo str_repeat( 'â– ', mb_strlen( $trans['license'] ) ); ?>
345 </a>
346 </nav>
347 </div>
348 <div class="col-12 col-sm-4 order-sm-last col-md-3 col-xl-2 mb-4">
349 <div class="ezcache-nav mt-1">
350 <button type="button" class="wpb-button" disabled>
351 <svg viewBox="0 0 24 24">
352 <path d="M19,8L15,12H18A6,6 0 0,1 12,18C11,18 10.03,17.75 9.2,17.3L7.74,18.76C8.97,19.54 10.43,20 12,20A8,8 0 0,0 20,12H23M6,12A6,6 0 0,1 12,6C13,6 13.97,6.25 14.8,6.7L16.26,5.24C15.03,4.46 13.57,4 12,4A8,8 0 0,0 4,12H1L5,16L9,12"></path>
353 </svg>
354 <?php echo str_repeat( 'â– ', mb_strlen( $trans['clear_cache'] ) ); ?>
355 </button>
356 <a href="#" target="_blank" class="mt-2 wpb-button wpb-button-outlined disabled">
357 <svg viewBox="0 0 24 24">
358 <path d="M12,16A3,3 0 0,1 9,13C9,11.88 9.61,10.9 10.5,10.39L20.21,4.77L14.68,14.35C14.18,15.33 13.17,16 12,16M12,3C13.81,3 15.5,3.5 16.97,4.32L14.87,5.53C14,5.19 13,5 12,5A8,8 0 0,0 4,13C4,15.21 4.89,17.21 6.34,18.65H6.35C6.74,19.04 6.74,19.67 6.35,20.06C5.96,20.45 5.32,20.45 4.93,20.07V20.07C3.12,18.26 2,15.76 2,13A10,10 0 0,1 12,3M22,13C22,15.76 20.88,18.26 19.07,20.07V20.07C18.68,20.45 18.05,20.45 17.66,20.06C17.27,19.67 17.27,19.04 17.66,18.65V18.65C19.11,17.2 20,15.21 20,13C20,12 19.81,11 19.46,10.1L20.67,8C21.5,9.5 22,11.18 22,13Z"></path>
359 </svg>
360 <?php echo str_repeat( 'â– ', mb_strlen( $trans['run_speed_test'] ) ); ?>
361 </a>
362 </div>
363 <div class="side-links">
364 <a href="#" target="_blank" class="side-links-item disabled">
365 <?php echo str_repeat( 'â– ', mb_strlen( $trans['documentation'] ) ); ?>
366 </a>
367 <a href="#" target="_blank" class="side-links-item disabled">
368 <?php echo str_repeat( 'â– ', mb_strlen( $trans['knowledgebase'] ) ); ?>
369 </a>
370 </div>
371 </div>
372 <div class="col-12 col-sm-4 order-sm-first col-md-6 col-xl-8">
373 <section class="ezcache-main">
374 <div>
375 <header class="ezcache-screen-header">
376 <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
377 </svg>
378 <?php echo str_repeat( 'â– ', mb_strlen( $trans['stats'] ) ); ?>
379 </header>
380 <div class="row">
381 </div>
382 </div>
383 </section>
384 </div>
385 </div>
386 </div>
387 <noscript>
388 <p class="text-center">
389 <strong><?php esc_html_e( 'This application requires JavaScript to run', 'ezcache' ); ?></strong>
390 </p>
391 </noscript>
392 </ezc-options>
393 </div>
394 <?php
395 }
396
397 /**
398 * Queue up the options page scripts
399 */
400 public function enqueue_scripts() {
401 $screen = get_current_screen();
402
403 if ( 'toplevel_page_ezcache' != $screen->id ) {
404 return;
405 }
406
407 $ver = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : $this->plugin->plugin_version;
408
409 wp_enqueue_script( 'ezcache-options', $this->plugin->plugin_url . '/assets/dist/js/options.js', [], $ver, true );
410 wp_enqueue_style( 'ezcache-options', $this->plugin->plugin_url . '/assets/dist/css/options.css', [], $ver );
411
412 wp_localize_script( 'ezcache-options', 'ezcache', [
413 'assets_url' => esc_url_raw( EZCACHE_URL . '/assets' ),
414 'ajax_url' => esc_url_raw( admin_url( 'admin-ajax.php' ) ),
415 'rest_url' => esc_url_raw( rest_url() ),
416 'ajax_nonce' => wp_create_nonce( 'ezcache-options' ),
417 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
418 'is_rtl' => is_rtl(),
419 'site_url' => esc_url_raw( untrailingslashit( site_url() ) ),
420 'trans' => $this->getJsTraslations(),
421 'is_https_2' => $this->check_https_2_support(),
422 ] );
423 }
424
425 /**
426 * Check if current website supports HTTPS/2
427 *
428 * @return bool
429 */
430 protected function check_https_2_support() {
431 if ( ! is_ssl() ) {
432 return false;
433 }
434
435 $supports = get_transient( 'ezcache_https_2_support' );
436
437 if ( ! $supports ) {
438 $response = wp_safe_remote_head( home_url(), [
439 'httpversion' => '2.0'
440 ] );
441
442 $supports = false;
443 if ( ! is_wp_error( $response ) ) {
444 $response = $response['http_response']->get_response_object();
445 $supports = $response->protocol_version == 2;
446 }
447
448 set_transient( 'ezcache_https_2_support', [ 'has_support' => $supports ], DAY_IN_SECONDS );
449 }
450
451 return isset( $supports['has_support'] ) ? $supports['has_support'] : false;
452 }
453
454 /**
455 * Get the trnaslations required for the javascript frontend
456 *
457 * @return array
458 */
459 protected function getJsTraslations() {
460 return [
461 'select_all' => __( 'Select All', 'ezcache' ),
462 'select_none' => __( 'Select None', 'ezcache' ),
463 'ezcache' => __( 'ezCache', 'ezcache' ),
464 'enabled' => __( 'Enabled', 'ezcache' ),
465 'disabled' => __( 'Disabled', 'ezcache' ),
466 'run_speed_test' => __( 'Run a Speed Test', 'ezcache' ),
467 'save_settings' => __( 'Save Settings', 'ezcache' ),
468 'settings_saved' => __( 'Settings updated.', 'ezcache' ),
469 'error_saving_settings' => __( 'Could not save settings.', 'ezcache' ),
470 'clear_cache' => __( 'Clear Cache', 'ezcache' ),
471 'cache_cleared' => __( 'Cache has been cleared.', 'ezcache' ),
472 'documentation' => __( 'Documentation', 'ezcache' ),
473 'knowledgebase' => __( 'Knowledgebase', 'ezcache' ),
474 'settings' => __( 'Settings', 'ezcache' ),
475 'advanced_settings' => __( 'Advanced Settings', 'ezcache' ),
476 'stats' => __( 'Statistics', 'ezcache' ),
477 'license' => __( 'License', 'ezcache' ),
478 'recommended' => __( 'Recommended', 'ezcache' ),
479 'basic_settings' => __( 'Basic Settings', 'ezcache' ),
480 'no_cache_known_users' => __( 'Don\'t cache pages for known users', 'ezcache' ),
481 'no_cache_known_users_description' => __( 'This disables cache for logged in users or visitors who left comments on posts.', 'ezcache' ),
482 'cache_expiry' => __( 'Cache Expiry', 'ezcache' ),
483 'cache_lifetime' => __( 'Cache Timeout', 'ezcache' ),
484 'cache_lifetime_description' => __( 'How long to keep the cached data, the recommended and effective starting point is one day.', 'ezcache' ),
485 'cache_expiry_interval' => __( 'Check for stale cache every', 'ezcache' ),
486 'cache_expiry_interval_description' => __( 'Automatically check for stale cache files and delete them at a set interval.', 'ezcache' ),
487 'interval' => __( 'Interval', 'ezcache' ),
488 'every' => __( 'Every', 'ezcache' ),
489 'seconds' => __( 'Seconds', 'ezcache' ),
490 'cache_schedule_type_time' => __( 'At Time', 'ezcache' ),
491 'cache_schedule_interval' => __( 'Interval', 'ezcache' ),
492 'weekly' => __( 'Weekly', 'ezcache' ),
493 'daily' => __( 'Daily', 'ezcache' ),
494 'twicedaily' => __( 'Twice Daily', 'ezcache' ),
495 'hourly' => __( 'Hourly', 'ezcache' ),
496 'at' => __( 'At', 'ezcache' ),
497 'cache_bypass' => __( 'Cache Bypass', 'ezcache' ),
498 'no_cache_query_params' => __( 'Don\'t cache pages where the URLs contain parameters in the query string', 'ezcache' ),
499 'no_cache_query_params_description' => __( 'Don\'t save cache when the URL contains query string parameters, such as ?page_id=15 at the end of the URL.', 'ezcache' ),
500 'separate_mobile_cache' => __( 'Separate cache for mobile devices', 'ezcache' ),
501 'separate_mobile_cache_description' => __( 'Save separate cache files for mobile browsers and a separate file for desktop browsers, you should only enable this option if your theme is not responsive and you use a theme or a plugin that produces a separate mobile version of the website.', 'ezcache' ),
502 'cache_clear_on_post_edit' => __( 'Clear cache when a post or page is published or updated', 'ezcache' ),
503 'cache_clear_on_post_edit_description' => __( 'Make sure your visitors read the latest posts by clearing the cache when you update or publish a post.', 'ezcache' ),
504 'bypass_cache_title' => __( 'Disable caching for the following pages', 'ezcache' ),
505 'bypass_cache_single' => __( 'Single Posts', 'ezcache' ),
506 'bypass_cache_pages' => __( 'Pages', 'ezcache' ),
507 'bypass_cache_frontpage' => __( 'Front Page', 'ezcache' ),
508 'bypass_cache_home' => __( 'Home', 'ezcache' ),
509 'bypass_cache_archives' => __( 'Archives', 'ezcache' ),
510 'bypass_cache_tag' => __( 'Tags', 'ezcache' ),
511 'bypass_cache_category' => __( 'Categories', 'ezcache' ),
512 'bypass_cache_feed' => __( 'Feeds', 'ezcache' ),
513 'bypass_cache_search' => __( 'Search Results', 'ezcache' ),
514 'bypass_cache_author' => __( 'Author Pages', 'ezcache' ),
515 'rejected_uri' => __( 'Links (URLs) which will never get cached', 'ezcache' ),
516 'rejected_uri_description' => __( 'Do not serve cached content if the URL matches any link in the following list', 'ezcache' ),
517 'rejected_uri_wildcard' => __( 'The domain part of the URL will be stripped automatically. Use * wildcard character to match multiple characters at this position (eg. /product/*).', 'ezcache' ),
518 'rejected_user_agent' => __( 'User Agents which will never receive cached data', 'ezcache' ),
519 'rejected_user_agent_description' => __( 'Do not serve cached content to the following useragents', 'ezcache' ),
520 'rejected_cookies' => __( 'Cookies which will prevent pages from getting cached', 'ezcache' ),
521 'rejected_cookies_description' => __( 'Specify the cookies that when set in the visitor\'s browser, should prevent a page from getting cached (one per line)', 'ezcache' ),
522 'rejected_cookies_placeholder' => _x( 'wordpress_logged_in_', 'rejected cookies example', 'ezcache' ),
523 'n_minutes' => __( '%s Minutes', 'ezcache' ),
524 'n_hours' => __( '%s Hours', 'ezcache' ),
525 'n_days' => __( '%s Days', 'ezcache' ),
526 'never_expire' => __( 'Never Expire', 'ezcache' ),
527 'cache_disabled' => __( 'WP_CACHE is disabled in your wp-config.php, caching will not work.', 'ezcache' ),
528 'adv_cache_not_exists' => __( 'advanced-cache.php is missing from your wp-content folder, caching will not work.', 'ezcache' ),
529 'plugin_badly_installed' => __( 'Plugin is not installed properly, please reinstall, caching will not work.', 'ezcache' ),
530 'desktop' => _x( 'Desktop', 'statistics block title', 'ezcache' ),
531 'mobile' => _x( 'Mobile', 'statistics block title', 'ezcache' ),
532 'expired' => _x( 'Expire Cache', 'statistics block title', 'ezcache' ),
533 'javascript' => _x( 'JavaScript Files', 'statistics block title', 'ezcache' ),
534 'css' => _x( 'CSS Files', 'statistics block title', 'ezcache' ),
535 'webp_images' => _x( 'WebP Images', 'statistics block title', 'ezcache' ),
536 'cache_usage' => __( 'ezCache Cache Usage', 'ezcache' ),
537 'webp_stats_description' => __( 'Images optimized with WebP.', 'ezcache' ),
538 'cache_bypass_settings' => _x( 'Cache Bypass', 'settings block title', 'ezcache' ),
539 'cache_settings' => _x( 'Caching', 'settings block title', 'ezcache' ),
540 'performance_settings' => _x( 'Performance', 'settings block title', 'ezcache' ),
541 'cache_expiry_settings' => _x( 'Cache Expiration', 'settings block title', 'ezcache' ),
542 'optimize_google_fonts' => __( 'Optimize Google fonts', 'ezcache' ),
543 'optimize_google_fonts_description' => __( 'Combine multiple Google Fonts declerations into one.', 'ezcache' ),
544 'minify_html' => __( 'Minify HTML', 'ezcache' ),
545 'minify_html_description' => __( 'Minify the cached HTML to make cached files smaller.', 'ezcache' ),
546 'minify_inline_js' => __( 'Minify Inline JavaScript', 'ezcache' ),
547 'minify_inline_js_description' => __( 'Include JavaScript embedded in the HTML in the minification process.', 'ezcache' ),
548 'minify_inline_css' => __( 'Minify Inline CSS', 'ezcache' ),
549 'minify_inline_css_description' => __( 'Include CSS embedded in the HTML in the minification process.', 'ezcache' ),
550 'minify_js' => __( 'Minify JavaScript', 'ezcache' ),
551 'minify_js_description' => __( 'Minify JavaScript files to reduce their size.', 'ezcache' ),
552 'minify_html_comments' => __( 'Remove HTML comments', 'ezcache' ),
553 'minify_html_comments_description' => __( 'Remove embeded comments from minified HTML.', 'ezcache' ),
554 'combine_head_js' => __( 'Combine JavaScript in Head', 'ezcache' ),
555 'combine_head_js_description' => __( 'Combine multiple JavaScript files found in the head section of the HTML into one file.', 'ezcache' ),
556 'combine_body_js' => __( 'Combine JavaScript in Body', 'ezcache' ),
557 'combine_body_js_description' => __( 'Combine multiple JavaScript files found in the body section of the HTML into one file.', 'ezcache' ),
558 'minify_css' => __( 'Minify CSS', 'ezcache' ),
559 'minify_css_description' => __( 'Minify CSS files to reduce their size.', 'ezcache' ),
560 'combine_css' => __( 'Combine CSS', 'ezcache' ),
561 'combine_css_description' => __( 'Combine multiple CSS files into one to reduce HTTP requests.', 'ezcache' ),
562 'disable_wp_emoji' => __( 'Disable WordPress Emoji', 'ezcache' ),
563 'disable_wp_emoji_description' => __( 'Remove extra code related to Emoji from WordPress which was added recently to support Emoji in an older browsers.', 'ezcache' ),
564 'not_recommended_https2' => __( 'Your server supports HTTP/2 which benefits from having this option kept disabled', 'ezcache' ),
565 'enable_webp_support' => __( 'Optimize Images With WebP', 'ezcache' ),
566 'enable_webp_support_description' => __( 'WebP is a modern image format that provides superior lossless and lossy compression for images on the web. WebP lossless images are 26% smaller in size compared to PNGs, and 25-34% smaller than comparable JPEG images.', 'ezcache' ),
567 'requries_premium_license' => __( 'Requires a premium license', 'ezcache' ),
568 'rejected_user_agent_placeholder' => _x( 'Googlebot', 'user agent example', 'ezcache' ),
569 'rejected_uri_placeholder' => _x( '/products/*', 'rejected uri example', 'ezcache' ),
570 'css_stats_description' => __( 'Optimized and cached CSS files.', 'ezcache' ),
571 'javascript_stats_description' => __( 'Optimized and cached JavaScript files.', 'ezcache' ),
572 'expired_stats_description' => __( 'Cache data that has expired and waiting to be cleaned up.', 'ezcache' ),
573 'mobile_stats_description' => __( 'Cache data for pages viewed from mobile devices.', 'ezcache' ),
574 'desktop_stats_description' => __( 'Cache data for pages viewed from desktop computers.', 'ezcache' ),
575 'general_advanced_settings' => __( 'General', 'ezcache' ),
576 'cache_clear_delete_webp' => __( 'Clear Cache also delete WebP images', 'ezcache' ),
577 'cache_clear_delete_webp_description' => __( 'Delete all saved WebP images when clearing the cache.', 'ezcache' ),
578
579 'license_key' => __( 'License Key', 'ezcache' ),
580 'license_key_description' => __( 'ezCache pro license will allow you to use the WebP image optimization without limits.', 'ezcache' ),
581 'deactivate_license' => __( 'Deactivate License', 'ezcache' ),
582 'activate_license' => __( 'Activate License', 'ezcache' ),
583 'license_valid' => __( 'License is valid', 'ezcache' ),
584 'license_invalid' => __( 'License is invalid', 'ezcache' ),
585 'license_expires_at' => __( 'License expires at %s', 'ezcache' ),
586 'unknown' => __( 'Unknown', 'ezcache' ),
587 'license_status' => __( 'Status', 'ezcache' ),
588 'license_details' => __( 'License Details', 'ezcache' ),
589 'license_type' => __( 'License Type', 'ezcache' ),
590 'trial_license' => _x( 'Trial', 'license type', 'ezcache' ),
591 'regular_license' => _x( 'Pro', 'license type', 'ezcache' ),
592 'expires_in' => __( 'Expires In', 'ezcache' ),
593 'expires_at' => __( 'Expires At', 'ezcache' ),
594 'uses_left' => __( 'Convertions Left', 'ezcache' ),
595 'trial_not_started' => __( '%s days after first usage', 'ezcache' ),
596 'purchase_license' => __( 'Get a Pro License', 'ezcache' ),
597 'license_expired' => __( 'Expired', 'ezcache' ),
598 'no_expiry_while_upress_client' => __( 'Will not expire while hosted on uPress', 'ezcache' ),
599
600 'upress_ad' => __( 'uPress Premium WordPress Hosting', 'ezcache' ),
601 'upress_domain' => __( 'www.upress.io', 'ezcache' ),
602 'upress_ad_link' => __( 'https://www.upress.io/?utm_source=wordpress&utm_medium=cpc&utm_campaign=ezcache', 'ezcache' ),
603 'speed_test_url' => __( 'https://speedom.net/?url=%s&location=US-NY&utm_source=wordpress&utm_medium=cpc&utm_campaign=ezcache', 'ezcache' ),
604 'ezcache_docs_link' => __( 'https://ezcache.app/documentation?utm_source=wordpress&utm_medium=cpc&utm_campaign=ezcache', 'ezcache' ),
605 'ezcache_knowledgebase_link' => __( 'https://ezcache.app/knowledgebase?utm_source=wordpress&utm_medium=cpc&utm_campaign=ezcache', 'ezcache' ),
606 'ezcache_pricing_link' => __( 'https://ezcache.app/pricing?utm_source=wordpress&utm_medium=cpc&utm_campaign=ezcache', 'ezcache' ),
607 ];
608 }
609
610 /**
611 * Show cache status admin notices when needed
612 */
613 function maybe_show_advanced_cache_notice() {
614 $webp_queue = get_site_option( 'ezcache_convert_images_to_webp_reprocess_queue' );
615 if ( ! $webp_queue ) {
616 $webp_queue = [];
617 }
618 $count_pending = array_reduce( $webp_queue, function ( $count, $images ) {
619 return $count + count( $images );
620 }, 0 );
621
622 if ( $count_pending > 0 ) {
623 echo '<div class="notice notice-info"><p><strong>' . esc_html__( 'ezCache', 'ezcache' ) . ':</strong> ' . sprintf( esc_html__( 'WebP Processing is currently running, %d images remaining.', 'ezcache' ), $count_pending ) . '</p></div>';
624 }
625
626 if ( isset( $_SESSION['EZCACHE_REPAIRED'] ) ) {
627 unset( $_SESSION['EZCACHE_REPAIRED'] );
628 echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'ezCache installation repaired.', 'ezcache' ) . '</p></div>';
629
630 return;
631 }
632
633 if ( ! get_site_option( 'ezcache_first_run', false ) ) {
634 update_site_option( 'ezcache_first_run', 1 );
635 return;
636 }
637
638 $status = $this->plugin->ezcache->get_status();
639
640 $messages = [];
641 if ( ! $status['cache_enabled'] ) {
642 $messages[] = __( 'WP_CACHE is disabled in your wp-config.php', 'ezcache' );
643 }
644 if ( ! $status['adv_cache_exists'] ) {
645 $messages[] = __( 'advanced-cache.php is missing from your wp-content folder', 'ezcache' );
646 }
647 if ( $status['adv_cache_exists'] && ! $status['correct_cache_exists'] ) {
648 $messages[] = __( 'Invalid advanced-cache.php file detected', 'ezcache' );
649 }
650 if ( ! $status['webp_table_exists'] ) {
651 $messages[] = __( 'WebP images database table is missing or corrupt', 'ezcache' );
652 }
653
654 if ( ! count( $messages ) ) {
655 return;
656 }
657
658 $referer = rawurlencode( wp_unslash( remove_query_arg( 'fl_builder', $_SERVER['REQUEST_URI'] ) ) );
659
660 echo '<div class="notice notice-error"><p>';
661 esc_html_e( 'ezCache detected the following configuration problems:', 'ezcache' );
662 echo '<br>';
663 echo implode( ', ', $messages );
664 echo '<br>';
665 echo '<a class="button button-sm button-secondary" href="' . wp_nonce_url( admin_url( 'admin-post.php?action=wpb_repair_install&_wp_http_referer=' . $referer ), 'wpb-repair-install' ) . '">' . esc_html__( 'Repair ezCache Installation', 'ezcache' ) . '</a>';
666 echo '</p></div>';
667 }
668
669 function admin_clear_cache() {
670 if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'wpb-clear-cache' ) ) {
671 wp_nonce_ays( 'wpb-clear-cache' );
672 }
673
674 $this->plugin->ezcache->clear_cache();
675
676 wp_redirect( wp_get_referer() );
677 exit;
678 }
679
680 /**
681 * Repaire the plugin installation when POST variable is set
682 */
683 function admin_repair_installation() {
684 if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'wpb-repair-install' ) ) {
685 wp_nonce_ays( 'wpb-repair-install' );
686 }
687
688 $this->plugin->activation_hook();
689
690 $_SESSION['EZCACHE_REPAIRED'] = true;
691 wp_redirect( wp_get_referer() );
692 exit;
693 }
694 }
695