Cache Enabler – WordPress Cache - Version 1.0.1

Version Description

  • Added WebP support and expiry directive
Download this release

Release Info

Developer keycdn
Plugin Icon 128x128 Cache Enabler – WordPress Cache
Version 1.0.1
Comparing to
See all releases

Version 1.0.1

cache-enabler.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Cache Enabler
4
+ Text Domain: cache
5
+ Description: Simple and fast WordPress disk caching plugin.
6
+ Author: KeyCDN
7
+ Author URI: https://www.keycdn.com
8
+ License: GPLv2 or later
9
+ Version: 1.0.1
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2015 KeyCDN
14
+
15
+ This program is free software; you can redistribute it and/or modify
16
+ it under the terms of the GNU General Public License as published by
17
+ the Free Software Foundation; either version 2 of the License, or
18
+ (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License along
26
+ with this program; if not, write to the Free Software Foundation, Inc.,
27
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28
+ */
29
+
30
+
31
+ // exit
32
+ defined('ABSPATH') OR exit;
33
+
34
+
35
+ // constants
36
+ define('CE_FILE', __FILE__);
37
+ define('CE_DIR', dirname(__FILE__));
38
+ define('CE_BASE', plugin_basename(__FILE__));
39
+ define('CE_CACHE_DIR', WP_CONTENT_DIR. '/cache/cache-enabler');
40
+
41
+
42
+ // hooks
43
+ add_action(
44
+ 'plugins_loaded',
45
+ array(
46
+ 'Cache_Enabler',
47
+ 'instance'
48
+ )
49
+ );
50
+ register_activation_hook(
51
+ __FILE__,
52
+ array(
53
+ 'Cache_Enabler',
54
+ 'on_activation'
55
+ )
56
+ );
57
+ register_deactivation_hook(
58
+ __FILE__,
59
+ array(
60
+ 'Cache_Enabler',
61
+ 'on_deactivation'
62
+ )
63
+ );
64
+ register_uninstall_hook(
65
+ __FILE__,
66
+ array(
67
+ 'Cache_Enabler',
68
+ 'on_uninstall'
69
+ )
70
+ );
71
+
72
+
73
+ // autoload register
74
+ spl_autoload_register('cache_autoload');
75
+
76
+ // autoload function
77
+ function cache_autoload($class) {
78
+ if ( in_array($class, array('Cache_Enabler', 'Cache_Enabler_Disk')) ) {
79
+ require_once(
80
+ sprintf(
81
+ '%s/inc/%s.class.php',
82
+ CE_DIR,
83
+ strtolower($class)
84
+ )
85
+ );
86
+ }
87
+ }
inc/cache_enabler.class.php ADDED
@@ -0,0 +1,1622 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ // exit
5
+ defined('ABSPATH') OR exit;
6
+
7
+
8
+ /**
9
+ * Cache_Enabler
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+
14
+ final class Cache_Enabler {
15
+
16
+
17
+ /**
18
+ * plugin options
19
+ *
20
+ * @since 1.0.0
21
+ * @var array
22
+ */
23
+
24
+ public static $options;
25
+
26
+
27
+ /**
28
+ * disk cache object
29
+ *
30
+ * @since 1.0.0
31
+ * @var object
32
+ */
33
+
34
+ private static $disk;
35
+
36
+
37
+ /**
38
+ * minify default settings
39
+ *
40
+ * @since 1.0.0
41
+ * @var integer
42
+ */
43
+
44
+ const MINIFY_DISABLED = 0;
45
+ const MINIFY_HTML_ONLY = 1;
46
+ const MINIFY_HTML_JS = 2;
47
+
48
+
49
+ /**
50
+ * constructor wrapper
51
+ *
52
+ * @since 1.0.0
53
+ * @change 1.0.0
54
+ */
55
+
56
+ public static function instance()
57
+ {
58
+ new self();
59
+ }
60
+
61
+
62
+ /**
63
+ * constructor
64
+ *
65
+ * @since 1.0.0
66
+ * @change 1.0.1
67
+ *
68
+ * @param void
69
+ * @return void
70
+ */
71
+
72
+ public function __construct()
73
+ {
74
+ // set default vars
75
+ self::_set_default_vars();
76
+
77
+ // register publish hook
78
+ add_action(
79
+ 'init',
80
+ array(
81
+ __CLASS__,
82
+ 'register_publish_hooks'
83
+ ),
84
+ 99
85
+ );
86
+
87
+ // clear cache hooks
88
+ add_action(
89
+ 'ce_remove_post_cache',
90
+ array(
91
+ __CLASS__,
92
+ 'clear_page_cache_by_post_id'
93
+ )
94
+ );
95
+ add_action(
96
+ 'ce_clear_cache',
97
+ array(
98
+ __CLASS__,
99
+ 'clear_total_cache'
100
+ )
101
+ );
102
+ add_action(
103
+ '_core_updated_successfully',
104
+ array(
105
+ __CLASS__,
106
+ 'clear_total_cache'
107
+ )
108
+ );
109
+ add_action(
110
+ 'switch_theme',
111
+ array(
112
+ __CLASS__,
113
+ 'clear_total_cache'
114
+ )
115
+ );
116
+ add_action(
117
+ 'wp_trash_post',
118
+ array(
119
+ __CLASS__,
120
+ 'clear_total_cache'
121
+ )
122
+ );
123
+
124
+ // add admin clear link
125
+ add_action(
126
+ 'admin_bar_menu',
127
+ array(
128
+ __CLASS__,
129
+ 'add_admin_links'
130
+ ),
131
+ 90
132
+ );
133
+ add_action(
134
+ 'init',
135
+ array(
136
+ __CLASS__,
137
+ 'process_clear_request'
138
+ )
139
+ );
140
+
141
+ // admin
142
+ if ( is_admin() ) {
143
+ add_action(
144
+ 'wpmu_new_blog',
145
+ array(
146
+ __CLASS__,
147
+ 'install_later'
148
+ )
149
+ );
150
+ add_action(
151
+ 'delete_blog',
152
+ array(
153
+ __CLASS__,
154
+ 'uninstall_later'
155
+ )
156
+ );
157
+
158
+ add_action(
159
+ 'admin_init',
160
+ array(
161
+ __CLASS__,
162
+ 'register_textdomain'
163
+ )
164
+ );
165
+ add_action(
166
+ 'admin_init',
167
+ array(
168
+ __CLASS__,
169
+ 'register_settings'
170
+ )
171
+ );
172
+
173
+ add_action(
174
+ 'admin_menu',
175
+ array(
176
+ __CLASS__,
177
+ 'add_settings_page'
178
+ )
179
+ );
180
+ add_action(
181
+ 'admin_enqueue_scripts',
182
+ array(
183
+ __CLASS__,
184
+ 'add_admin_resources'
185
+ )
186
+ );
187
+
188
+ add_action(
189
+ 'transition_comment_status',
190
+ array(
191
+ __CLASS__,
192
+ 'change_comment'
193
+ ),
194
+ 10,
195
+ 3
196
+ );
197
+ add_action(
198
+ 'edit_comment',
199
+ array(
200
+ __CLASS__,
201
+ 'edit_comment'
202
+ )
203
+ );
204
+
205
+ add_filter(
206
+ 'dashboard_glance_items',
207
+ array(
208
+ __CLASS__,
209
+ 'add_dashboard_count'
210
+ )
211
+ );
212
+ add_action(
213
+ 'post_submitbox_misc_actions',
214
+ array(
215
+ __CLASS__,
216
+ 'add_clear_dropdown'
217
+ )
218
+ );
219
+
220
+ add_filter(
221
+ 'plugin_row_meta',
222
+ array(
223
+ __CLASS__,
224
+ 'row_meta'
225
+ ),
226
+ 10,
227
+ 2
228
+ );
229
+ add_filter(
230
+ 'plugin_action_links_' .CE_BASE,
231
+ array(
232
+ __CLASS__,
233
+ 'action_links'
234
+ )
235
+ );
236
+
237
+ // warnings and notices
238
+ add_action(
239
+ 'admin_notices',
240
+ array(
241
+ __CLASS__,
242
+ 'warning_is_permalink'
243
+ )
244
+ );
245
+
246
+ // caching
247
+ } else {
248
+ add_action(
249
+ 'pre_comment_approved',
250
+ array(
251
+ __CLASS__,
252
+ 'new_comment'
253
+ ),
254
+ 99,
255
+ 2
256
+ );
257
+ add_action(
258
+ 'template_redirect',
259
+ array(
260
+ __CLASS__,
261
+ 'handle_cache'
262
+ ),
263
+ 0
264
+ );
265
+ }
266
+ }
267
+
268
+
269
+ /**
270
+ * deactivation hook
271
+ *
272
+ * @since 1.0.0
273
+ * @change 1.0.0
274
+ */
275
+
276
+ public static function on_deactivation() {
277
+ self::clear_total_cache(true);
278
+ }
279
+
280
+
281
+ /**
282
+ * activation hook
283
+ *
284
+ * @since 1.0.0
285
+ * @change 1.0.0
286
+ */
287
+
288
+ public static function on_activation() {
289
+
290
+ // multisite and network
291
+ if ( is_multisite() && ! empty($_GET['networkwide']) ) {
292
+ // blog ids
293
+ $ids = self::_get_blog_ids();
294
+
295
+ // switch to blog
296
+ foreach ($ids as $id) {
297
+ switch_to_blog($id);
298
+ self::_install_backend();
299
+ }
300
+
301
+ // restore blog
302
+ restore_current_blog();
303
+
304
+ } else {
305
+ self::_install_backend();
306
+ }
307
+ }
308
+
309
+
310
+ /**
311
+ * install on multisite setup
312
+ *
313
+ * @since 1.0.0
314
+ * @change 1.0.0
315
+ */
316
+
317
+ public static function install_later($id) {
318
+
319
+ // check if multisite setup
320
+ if ( ! is_plugin_active_for_network(CE_BASE) ) {
321
+ return;
322
+ }
323
+
324
+ // switch to blog
325
+ switch_to_blog($id);
326
+
327
+ // installation
328
+ self::_install_backend();
329
+
330
+ // restore
331
+ restore_current_blog();
332
+ }
333
+
334
+
335
+ /**
336
+ * installation options
337
+ *
338
+ * @since 1.0.0
339
+ * @change 1.0.0
340
+ */
341
+
342
+ private static function _install_backend() {
343
+
344
+ add_option(
345
+ 'cache',
346
+ array()
347
+ );
348
+
349
+ // clear
350
+ self::clear_total_cache(true);
351
+ }
352
+
353
+
354
+ /**
355
+ * uninstall per multisite blog
356
+ *
357
+ * @since 1.0.0
358
+ * @change 1.0.0
359
+ */
360
+
361
+ public static function on_uninstall() {
362
+ global $wpdb;
363
+
364
+ // multisite and network
365
+ if ( is_multisite() && ! empty($_GET['networkwide']) ) {
366
+ // legacy blog
367
+ $old = $wpdb->blogid;
368
+
369
+ // blog id
370
+ $ids = self::_get_blog_ids();
371
+
372
+ // uninstall per blog
373
+ foreach ($ids as $id) {
374
+ switch_to_blog($id);
375
+ self::_uninstall_backend();
376
+ }
377
+
378
+ // restore
379
+ switch_to_blog($old);
380
+ } else {
381
+ self::_uninstall_backend();
382
+ }
383
+ }
384
+
385
+
386
+ /**
387
+ * uninstall for multisite and network
388
+ *
389
+ * @since 1.0.0
390
+ * @change 1.0.0
391
+ */
392
+
393
+ public static function uninstall_later($id) {
394
+
395
+ // check if network plugin
396
+ if ( ! is_plugin_active_for_network(CE_BASE) ) {
397
+ return;
398
+ }
399
+
400
+ // switch
401
+ switch_to_blog($id);
402
+
403
+ // uninstall
404
+ self::_uninstall_backend();
405
+
406
+ // restore
407
+ restore_current_blog();
408
+ }
409
+
410
+
411
+ /**
412
+ * uninstall
413
+ *
414
+ * @since 1.0.0
415
+ * @change 1.0.0
416
+ */
417
+
418
+ private static function _uninstall_backend() {
419
+
420
+ // delete options
421
+ delete_option('cache');
422
+
423
+ // clear cache
424
+ self::clear_total_cache(true);
425
+ }
426
+
427
+
428
+ /**
429
+ * get blog ids
430
+ *
431
+ * @since 1.0.0
432
+ * @change 1.0.0
433
+ *
434
+ * @return array blog ids array
435
+ */
436
+
437
+ private static function _get_blog_ids() {
438
+ global $wpdb;
439
+
440
+ return $wpdb->get_col("SELECT blog_id FROM `$wpdb->blogs`");
441
+ }
442
+
443
+
444
+ /**
445
+ * set default vars
446
+ *
447
+ * @since 1.0.0
448
+ * @change 1.0.0
449
+ */
450
+
451
+ private static function _set_default_vars() {
452
+
453
+ // get options
454
+ self::$options = self::_get_options();
455
+
456
+ // disk cache
457
+ if ( Cache_Enabler_Disk::is_permalink() ) {
458
+ self::$disk = new Cache_Enabler_Disk;
459
+ }
460
+ }
461
+
462
+
463
+ /**
464
+ * get options
465
+ *
466
+ * @since 1.0.0
467
+ * @change 1.0.0
468
+ *
469
+ * @return array options array
470
+ */
471
+
472
+ private static function _get_options() {
473
+
474
+ return wp_parse_args(
475
+ get_option('cache'),
476
+ array(
477
+ 'expires' => 0,
478
+ 'if_loggedin' => 1,
479
+ 'new_comment' => 0,
480
+ 'webp' => 0,
481
+ 'excl_ids' => '',
482
+ 'minify_html' => self::MINIFY_DISABLED,
483
+ )
484
+ );
485
+ }
486
+
487
+
488
+ /**
489
+ * warning if no custom permlinks
490
+ *
491
+ * @since 1.0.0
492
+ * @change 1.0.0
493
+ *
494
+ * @return array options array
495
+ */
496
+
497
+ public static function warning_is_permalink() {
498
+
499
+ if ( !Cache_Enabler_Disk::is_permalink() AND current_user_can('manage_options') ) { ?>
500
+
501
+ <div class="error">
502
+ <p><?php printf( __('The <b>%s</b> plugin requires a custom permalink structure to start caching properly. Please go to <a href="%s">Permalink</a> to enable it.', 'cache'), 'Cache Enabler', admin_url( 'options-permalink.php' ) ); ?></p>
503
+ </div>
504
+
505
+ <?php
506
+ }
507
+ }
508
+
509
+
510
+ /**
511
+ * add action links
512
+ *
513
+ * @since 1.0.0
514
+ * @change 1.0.0
515
+ *
516
+ * @param array $data existing links
517
+ * @return array $data appended links
518
+ */
519
+
520
+ public static function action_links($data) {
521
+
522
+ // check user role
523
+ if ( ! current_user_can('manage_options') ) {
524
+ return $data;
525
+ }
526
+
527
+ return array_merge(
528
+ $data,
529
+ array(
530
+ sprintf(
531
+ '<a href="%s">%s</a>',
532
+ add_query_arg(
533
+ array(
534
+ 'page' => 'cache-enabler'
535
+ ),
536
+ admin_url('options-general.php')
537
+ ),
538
+ __('Settings')
539
+ )
540
+ )
541
+ );
542
+ }
543
+
544
+
545
+ /**
546
+ * cache enabler meta links
547
+ *
548
+ * @since 1.0.0
549
+ * @change 1.0.0
550
+ *
551
+ * @param array $input existing links
552
+ * @param string $page page
553
+ * @return array $data appended links
554
+ */
555
+
556
+ public static function row_meta($input, $page) {
557
+
558
+ // check permissions
559
+ if ( $page != CE_BASE ) {
560
+ return $input;
561
+ }
562
+
563
+ return array_merge(
564
+ $input,
565
+ array(
566
+ '<a href="https://www.keycdn.com/support/" target="_blank">Support Page</a>',
567
+ )
568
+ );
569
+ }
570
+
571
+
572
+ /**
573
+ * add dashboard cache size count
574
+ *
575
+ * @since 1.0.0
576
+ * @change 1.0.0
577
+ *
578
+ * @param array $items initial array with dashboard items
579
+ * @return array $items merged array with dashboard items
580
+ */
581
+
582
+ public static function add_dashboard_count( $items = array() ) {
583
+
584
+ // check user role
585
+ if ( ! current_user_can('manage_options') ) {
586
+ return $items;
587
+ }
588
+
589
+ // get cache size
590
+ $size = self::get_cache_size();
591
+
592
+ // display items
593
+ $items[] = sprintf(
594
+ '<a href="%s" title="Disk Cache">%s Cache Size</a>',
595
+ add_query_arg(
596
+ array(
597
+ 'page' => 'cache-enabler'
598
+ ),
599
+ admin_url('options-general.php')
600
+ ),
601
+ ( empty($size) ? esc_html__('Empty', 'cache') : size_format($size) )
602
+ );
603
+
604
+ return $items;
605
+ }
606
+
607
+
608
+ /**
609
+ * get cache size
610
+ *
611
+ * @since 1.0.0
612
+ * @change 1.0.0
613
+ *
614
+ * @param integer $size cache size (bytes)
615
+ */
616
+
617
+ public static function get_cache_size() {
618
+
619
+ if ( ! $size = get_transient('cache_size') ) {
620
+
621
+ $size = (int) self::$disk->cache_size(CE_CACHE_DIR);
622
+
623
+ // set transient
624
+ set_transient(
625
+ 'cache_size',
626
+ $size,
627
+ 60 * 15
628
+ );
629
+ }
630
+
631
+ return $size;
632
+ }
633
+
634
+
635
+ /**
636
+ * add admin links
637
+ *
638
+ * @since 1.0.0
639
+ * @change 1.0.1
640
+ *
641
+ * @hook mixed
642
+ *
643
+ * @param object menu properties
644
+ */
645
+
646
+ public static function add_admin_links($wp_admin_bar) {
647
+
648
+ // check user role
649
+ if ( ! is_admin_bar_showing() OR ! apply_filters('user_can_clear_cache', current_user_can('manage_options')) ) {
650
+ return;
651
+ }
652
+
653
+ // add admin purge link
654
+ $wp_admin_bar->add_menu(
655
+ array(
656
+ 'id' => 'clear-cache',
657
+ 'href' => wp_nonce_url( add_query_arg('_cache', 'clear'), '_cache__clear_nonce'),
658
+ 'parent' => 'top-secondary',
659
+ 'title' => '<span class="ab-item">Clear Cache</span>',
660
+ 'meta' => array( 'title' => esc_html__('clear Cache', 'cache') )
661
+ )
662
+ );
663
+
664
+ }
665
+
666
+
667
+ /**
668
+ * process clear request
669
+ *
670
+ * @since 1.0.0
671
+ * @change 1.0.0
672
+ *
673
+ * @param array $data array of metadata
674
+ */
675
+
676
+ public static function process_clear_request($data) {
677
+
678
+ // check if clear request
679
+ if ( empty($_GET['_cache']) OR $_GET['_cache'] !== 'clear' ) {
680
+ return;
681
+ }
682
+
683
+ // validate nonce
684
+ if ( empty($_GET['_wpnonce']) OR ! wp_verify_nonce($_GET['_wpnonce'], '_cache__clear_nonce') ) {
685
+ return;
686
+ }
687
+
688
+ // check user role
689
+ if ( ! is_admin_bar_showing() OR ! apply_filters('user_can_clear_cache', current_user_can('manage_options')) ) {
690
+ return;
691
+ }
692
+
693
+ // load if network
694
+ if ( ! function_exists('is_plugin_active_for_network') ) {
695
+ require_once( ABSPATH. 'wp-admin/includes/plugin.php' );
696
+ }
697
+
698
+ // multisite and network setup
699
+ if ( is_multisite() && is_plugin_active_for_network(CE_BASE) ) {
700
+
701
+ // legacy blog
702
+ $legacy = $GLOBALS['wpdb']->blogid;
703
+
704
+ // blog ids
705
+ $ids = self::_get_blog_ids();
706
+
707
+ // switch blogs
708
+ foreach ($ids as $id) {
709
+ switch_to_blog($id);
710
+ self::clear_total_cache();
711
+ }
712
+
713
+ // restore
714
+ switch_to_blog($legacy);
715
+
716
+ // clear notice
717
+ if ( is_admin() ) {
718
+ add_action(
719
+ 'network_admin_notices',
720
+ array(
721
+ __CLASS__,
722
+ 'clear_notice'
723
+ )
724
+ );
725
+ }
726
+ } else {
727
+ // clear cache
728
+ self::clear_total_cache();
729
+
730
+ // clear notice
731
+ if ( is_admin() ) {
732
+ add_action(
733
+ 'admin_notices',
734
+ array(
735
+ __CLASS__,
736
+ 'clear_notice'
737
+ )
738
+ );
739
+ }
740
+ }
741
+
742
+ if ( ! is_admin() ) {
743
+ wp_safe_redirect(
744
+ remove_query_arg(
745
+ '_cache',
746
+ wp_get_referer()
747
+ )
748
+ );
749
+
750
+ exit();
751
+ }
752
+ }
753
+
754
+
755
+ /**
756
+ * notification after clear cache
757
+ *
758
+ * @since 1.0.0
759
+ * @change 1.0.0
760
+ *
761
+ * @hook mixed user_can_clear_cache
762
+ */
763
+
764
+ public static function clear_notice() {
765
+
766
+ // check if admin
767
+ if ( ! is_admin_bar_showing() OR ! apply_filters('user_can_clear_cache', current_user_can('manage_options')) ) {
768
+ return false;
769
+ }
770
+
771
+ echo sprintf(
772
+ '<div class="notice notice-success is-dismissible"><p>%s</p></div>',
773
+ esc_html__('The cache has been deleted.', 'cache')
774
+ );
775
+ }
776
+
777
+
778
+ /**
779
+ * clear cache if edit comment
780
+ *
781
+ * @since 1.0.0
782
+ * @change 1.0.0
783
+ *
784
+ * @param integer $id id of the comment
785
+ */
786
+
787
+ public static function edit_comment($id) {
788
+
789
+ // clear complete cache if option enabled
790
+ if ( self::$options['new_comment'] ) {
791
+ self::clear_total_cache();
792
+ } else {
793
+ self::clear_page_cache_by_post_id(
794
+ get_comment($id)->comment_post_ID
795
+ );
796
+ }
797
+ }
798
+
799
+
800
+ /**
801
+ * clear cache if new comment
802
+ *
803
+ * @since 1.0.0
804
+ * @change 1.0.0
805
+ *
806
+ * @param mixed $approved approval status
807
+ * @param array $comment
808
+ * @return mixed $approved approval status
809
+ */
810
+
811
+ public static function new_comment($approved, $comment) {
812
+
813
+ // check if comment is approved
814
+ if ( $approved === 1 ) {
815
+ if ( self::$options['new_comment'] ) {
816
+ self::clear_total_cache();
817
+ } else {
818
+ self::clear_page_cache_by_post_id( $comment['comment_post_ID'] );
819
+ }
820
+ }
821
+
822
+ return $approved;
823
+ }
824
+
825
+
826
+ /**
827
+ * clear cache if comment changes
828
+ *
829
+ * @since 1.0.0
830
+ * @change 1.0.0
831
+ *
832
+ * @param string $after_status
833
+ * @param string $before_status
834
+ * @param object $comment
835
+ */
836
+
837
+ public static function change_comment($after_status, $before_status, $comment) {
838
+
839
+ // check if changes occured
840
+ if ( $after_status != $before_status ) {
841
+ if ( self::$options['new_comment'] ) {
842
+ self::clear_total_cache();
843
+ } else {
844
+ self::clear_page_cache_by_post_id( $comment->comment_post_ID );
845
+ }
846
+ }
847
+ }
848
+
849
+
850
+ /**
851
+ * register publish hooks for custom post types
852
+ *
853
+ * @since 1.0.0
854
+ * @since 1.0.0
855
+ *
856
+ * @param void
857
+ * @return void
858
+ */
859
+
860
+ public static function register_publish_hooks() {
861
+
862
+ // get post types
863
+ $post_types = get_post_types(
864
+ array('public' => true)
865
+ );
866
+
867
+ // check if empty
868
+ if ( empty($post_types) ) {
869
+ return;
870
+ }
871
+
872
+ // post type actions
873
+ foreach ( $post_types as $post_type ) {
874
+ add_action(
875
+ 'publish_' .$post_type,
876
+ array(
877
+ __CLASS__,
878
+ 'publish_post_types'
879
+ ),
880
+ 10,
881
+ 2
882
+ );
883
+ add_action(
884
+ 'publish_future_' .$post_type,
885
+ array(
886
+ __CLASS__,
887
+ 'clear_total_cache'
888
+ )
889
+ );
890
+ }
891
+ }
892
+
893
+
894
+ /**
895
+ * delete post type cache on post updates
896
+ *
897
+ * @since 1.0.0
898
+ * @change 1.0.0
899
+ *
900
+ * @param integer $post_ID Post ID
901
+ */
902
+
903
+ public static function publish_post_types($post_ID, $post) {
904
+
905
+ // check if post id or post is empty
906
+ if ( empty($post_ID) OR empty($post) ) {
907
+ return;
908
+ }
909
+
910
+ // check post status
911
+ if ( ! in_array( $post->post_status, array('publish', 'future') ) ) {
912
+ return;
913
+ }
914
+
915
+ // purge cache if clean post on update
916
+ if ( ! isset($_POST['_clear_post_cache_on_update']) ) {
917
+ return self::clear_total_cache();
918
+ }
919
+
920
+ // validate nonce
921
+ if ( ! isset($_POST['_cache__status_nonce_' .$post_ID]) OR ! wp_verify_nonce($_POST['_cache__status_nonce_' .$post_ID], CE_BASE) ) {
922
+ return;
923
+ }
924
+
925
+ // validate user role
926
+ if ( ! current_user_can('publish_posts') ) {
927
+ return;
928
+ }
929
+
930
+ // save as integer
931
+ $clear_post_cache = (int)$_POST['_clear_post_cache_on_update'];
932
+
933
+ // save user metadata
934
+ update_user_meta(
935
+ get_current_user_id(),
936
+ '_clear_post_cache_on_update',
937
+ $clear_post_cache
938
+ );
939
+
940
+ // purge complete cache or specific post
941
+ if ( $clear_post_cache ) {
942
+ self::clear_page_cache_by_post_id( $post_ID );
943
+ } else {
944
+ self::clear_total_cache();
945
+ }
946
+ }
947
+
948
+
949
+ /**
950
+ * clear page cache by post id
951
+ *
952
+ * @since 1.0.0
953
+ * @change 1.0.0
954
+ *
955
+ * @param integer $post_ID Post ID
956
+ */
957
+
958
+ public static function clear_page_cache_by_post_id($post_ID) {
959
+
960
+ // is int
961
+ if ( ! $post_ID = (int)$post_ID ) {
962
+ return;
963
+ }
964
+
965
+ // clear cache by URL
966
+ self::clear_page_cache_by_url(
967
+ get_permalink( $post_ID )
968
+ );
969
+ }
970
+
971
+
972
+ /**
973
+ * clear page cache by url
974
+ *
975
+ * @since 1.0.0
976
+ * @change 1.0.0
977
+ *
978
+ * @param string $url url of a page
979
+ */
980
+
981
+ public static function clear_page_cache_by_url($url) {
982
+
983
+ // validate string
984
+ if ( ! $url = (string)$url ) {
985
+ return;
986
+ }
987
+
988
+ call_user_func(
989
+ array(
990
+ self::$disk,
991
+ 'delete_asset'
992
+ ),
993
+ $url
994
+ );
995
+ }
996
+
997
+
998
+ /**
999
+ * explode on comma
1000
+ *
1001
+ * @since 1.0.0
1002
+ * @change 1.0.0
1003
+ *
1004
+ * @param string $input input string
1005
+ * @return array array of strings
1006
+ */
1007
+
1008
+ private static function _preg_split($input) {
1009
+ return (array)preg_split('/,/', $input, -1, PREG_SPLIT_NO_EMPTY);
1010
+ }
1011
+
1012
+
1013
+ /**
1014
+ * check if index.php
1015
+ *
1016
+ * @since 1.0.0
1017
+ * @change 1.0.0
1018
+ *
1019
+ * @return boolean true if index.php
1020
+ */
1021
+
1022
+ private static function _is_index() {
1023
+ return basename($_SERVER['SCRIPT_NAME']) != 'index.php';
1024
+ }
1025
+
1026
+
1027
+ /**
1028
+ * check if mobile
1029
+ *
1030
+ * @since 1.0.0
1031
+ * @change 1.0.0
1032
+ *
1033
+ * @return boolean true if mobile
1034
+ */
1035
+
1036
+ private static function _is_mobile() {
1037
+ return ( strpos(TEMPLATEPATH, 'wptouch') OR strpos(TEMPLATEPATH, 'carrington') OR strpos(TEMPLATEPATH, 'jetpack') OR strpos(TEMPLATEPATH, 'handheld') );
1038
+ }
1039
+
1040
+
1041
+ /**
1042
+ * check if logged in
1043
+ *
1044
+ * @since 1.0.0
1045
+ * @change 1.0.0
1046
+ *
1047
+ * @return boolean true if logged in or cookie set
1048
+ */
1049
+
1050
+ private static function _is_logged_in() {
1051
+
1052
+ // check if logged in
1053
+ if ( is_user_logged_in() ) {
1054
+ return true;
1055
+ }
1056
+
1057
+ // check cookie
1058
+ if ( empty($_COOKIE) ) {
1059
+ return false;
1060
+ }
1061
+
1062
+ // check cookie values
1063
+ foreach ( $_COOKIE as $k => $v) {
1064
+ if ( preg_match('/^(wp-postpass|wordpress_logged_in|comment_author)_/', $k) ) {
1065
+ return true;
1066
+ }
1067
+ }
1068
+ }
1069
+
1070
+
1071
+ /**
1072
+ * definitaion of cache expection
1073
+ *
1074
+ * @since 1.0.0
1075
+ * @change 1.0.0
1076
+ *
1077
+ * @return boolean true if exception
1078
+ *
1079
+ * @hook boolean skip_cache
1080
+ */
1081
+
1082
+ private static function _bypass_cache() {
1083
+
1084
+ // skip cache hook
1085
+ if ( apply_filters('skip_cache', false) ) {
1086
+ return true;
1087
+ }
1088
+
1089
+ // conditional tags
1090
+ if ( self::_is_index() OR is_search() OR is_404() OR is_feed() OR is_trackback() OR is_robots() OR is_preview() OR post_password_required() ) {
1091
+ return true;
1092
+ }
1093
+
1094
+ // DONOTCACHEPAGE check e.g. woocommerce
1095
+ if ( defined('DONOTCACHEPAGE') && DONOTCACHEPAGE ) {
1096
+ return true;
1097
+ }
1098
+
1099
+ // cache enabler options
1100
+ $options = self::$options;
1101
+
1102
+ // Request method GET
1103
+ if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || $_SERVER['REQUEST_METHOD'] != 'GET' ) {
1104
+ return true;
1105
+ }
1106
+
1107
+ // if logged in
1108
+ if ( $options['if_loggedin'] && self::_is_logged_in() ) {
1109
+ return true;
1110
+ }
1111
+
1112
+ // if mobile request
1113
+ if ( self::_is_mobile() ) {
1114
+ return true;
1115
+ }
1116
+
1117
+ // if post id excluded
1118
+ if ( $options['excl_ids'] && is_singular() ) {
1119
+ if ( in_array( $GLOBALS['wp_query']->get_queried_object_id(), self::_preg_split($options['excl_ids']) ) ) {
1120
+ return true;
1121
+ }
1122
+ }
1123
+
1124
+ return false;
1125
+ }
1126
+
1127
+
1128
+ /**
1129
+ * minify html
1130
+ *
1131
+ * @since 1.0.0
1132
+ * @change 1.0.0
1133
+ *
1134
+ * @param string $data minify request data
1135
+ * @return string $data minify response data
1136
+ *
1137
+ * @hook array cache_minify_ignore_tags
1138
+ */
1139
+
1140
+ private static function _minify_cache($data) {
1141
+
1142
+ // check if disabled
1143
+ if ( ! self::$options['minify_html'] ) {
1144
+ return $data;
1145
+ }
1146
+
1147
+ // strlen limit
1148
+ if ( strlen($data) > 700000) {
1149
+ return $data;
1150
+ }
1151
+
1152
+ // ignore this tags
1153
+ $ignore_tags = (array)apply_filters(
1154
+ 'cache_minify_ignore_tags',
1155
+ array(
1156
+ 'textarea',
1157
+ 'pre'
1158
+ )
1159
+ );
1160
+
1161
+ // ignore JS if selected
1162
+ if ( self::$options['minify_html'] !== self::MINIFY_HTML_JS ) {
1163
+ $ignore_tags[] = 'script';
1164
+ }
1165
+
1166
+ // return of no ignore tags
1167
+ if ( ! $ignore_tags ) {
1168
+ return $data;
1169
+ }
1170
+
1171
+ // stringify
1172
+ $ignore_regex = implode('|', $ignore_tags);
1173
+
1174
+ // regex minification
1175
+ $cleaned = preg_replace(
1176
+ array(
1177
+ '/<!--[^\[><](.*?)-->/s',
1178
+ '#(?ix)(?>[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:' .$ignore_regex. ')\b))*+)(?:<(?>' .$ignore_regex. ')\b|\z))#'
1179
+ ),
1180
+ array(
1181
+ '',
1182
+ ' '
1183
+ ),
1184
+ $data
1185
+ );
1186
+
1187
+ // something went wrong
1188
+ if ( strlen($cleaned) <= 1 ) {
1189
+ return $data;
1190
+ }
1191
+
1192
+ return $cleaned;
1193
+ }
1194
+
1195
+
1196
+ /**
1197
+ * clear complete cache
1198
+ *
1199
+ * @since 1.0.0
1200
+ * @change 1.0.0
1201
+ */
1202
+
1203
+ public static function clear_total_cache() {
1204
+
1205
+ // clear disk cache
1206
+ Cache_Enabler_Disk::clear_cache();
1207
+
1208
+ // delete transient
1209
+ delete_transient('cache_size');
1210
+ }
1211
+
1212
+
1213
+ /**
1214
+ * set cache
1215
+ *
1216
+ * @since 1.0.0
1217
+ * @change 1.0.0
1218
+ *
1219
+ * @param string $data content of a page
1220
+ * @return string $data content of a page
1221
+ */
1222
+
1223
+ public static function set_cache($data) {
1224
+
1225
+ // check if empty
1226
+ if ( empty($data) ) {
1227
+ return '';
1228
+ }
1229
+
1230
+ // store as asset
1231
+ call_user_func(
1232
+ array(
1233
+ self::$disk,
1234
+ 'store_asset'
1235
+ ),
1236
+ self::_minify_cache($data)
1237
+ );
1238
+
1239
+ return $data;
1240
+ }
1241
+
1242
+
1243
+ /**
1244
+ * handle cache
1245
+ *
1246
+ * @since 1.0.0
1247
+ * @change 1.0.1
1248
+ */
1249
+
1250
+ public static function handle_cache() {
1251
+
1252
+ // bypass cache
1253
+ if ( self::_bypass_cache() ) {
1254
+ return;
1255
+ }
1256
+
1257
+ // get asset cache status
1258
+ $cached = call_user_func(
1259
+ array(
1260
+ self::$disk,
1261
+ 'check_asset'
1262
+ )
1263
+ );
1264
+
1265
+ // check if cache empty
1266
+ if ( empty($cached) ) {
1267
+ ob_start('Cache_Enabler::set_cache');
1268
+ return;
1269
+ }
1270
+
1271
+ // get expiry status
1272
+ $expired = call_user_func(
1273
+ array(
1274
+ self::$disk,
1275
+ 'check_expiry'
1276
+ )
1277
+ );
1278
+
1279
+ // check if expired
1280
+ if ( $expired ) {
1281
+ ob_start('Cache_Enabler::set_cache');
1282
+ return;
1283
+ }
1284
+
1285
+ // return cached asset
1286
+ call_user_func(
1287
+ array(
1288
+ self::$disk,
1289
+ 'get_asset'
1290
+ )
1291
+ );
1292
+ }
1293
+
1294
+
1295
+ /**
1296
+ * add clear option dropdown on post publish widget
1297
+ *
1298
+ * @since 1.0.0
1299
+ * @change 1.0.0
1300
+ */
1301
+
1302
+ public static function add_clear_dropdown() {
1303
+
1304
+ // on published post page only
1305
+ if ( empty($GLOBALS['pagenow']) OR $GLOBALS['pagenow'] !== 'post.php' OR empty($GLOBALS['post']) OR ! is_object($GLOBALS['post']) OR $GLOBALS['post']->post_status !== 'publish' ) {
1306
+ return;
1307
+ }
1308
+
1309
+ // check user role
1310
+ if ( ! current_user_can('publish_posts') ) {
1311
+ return;
1312
+ }
1313
+
1314
+ // validate nonce
1315
+ wp_nonce_field(CE_BASE, '_cache__status_nonce_' .$GLOBALS['post']->ID);
1316
+
1317
+ // get current action
1318
+ $current_action = (int)get_user_meta(
1319
+ get_current_user_id(),
1320
+ '_clear_post_cache_on_update',
1321
+ true
1322
+ );
1323
+
1324
+ // init variables
1325
+ $dropdown_options = '';
1326
+ $available_options = array(
1327
+ esc_html__('Completely', 'cache'),
1328
+ esc_html__('Page specific', 'cache')
1329
+ );
1330
+
1331
+ // set dropdown options
1332
+ foreach( $available_options as $key => $value ) {
1333
+ $dropdown_options .= sprintf(
1334
+ '<option value="%1$d" %3$s>%2$s</option>',
1335
+ $key,
1336
+ $value,
1337
+ selected($key, $current_action, false)
1338
+ );
1339
+ }
1340
+
1341
+ // output drowdown
1342
+ echo sprintf(
1343
+ '<div class="misc-pub-section" style="border-top:1px solid #eee">
1344
+ <label for="cache_action">
1345
+ %1$s: <span id="output-cache-action">%2$s</span>
1346
+ </label>
1347
+ <a href="#" class="edit-cache-action hide-if-no-js">%3$s</a>
1348
+
1349
+ <div class="hide-if-js">
1350
+ <select name="_clear_post_cache_on_update" id="cache_action">
1351
+ %4$s
1352
+ </select>
1353
+
1354
+ <a href="#" class="save-cache-action hide-if-no-js button">%5$s</a>
1355
+ <a href="#" class="cancel-cache-action hide-if-no-js button-cancel">%6$s</a>
1356
+ </div>
1357
+ </div>',
1358
+ esc_html__('Clear cache', 'cache'),
1359
+ $available_options[$current_action],
1360
+ esc_html__('Edit'),
1361
+ $dropdown_options,
1362
+ esc_html__('OK'),
1363
+ esc_html__('Cancel')
1364
+ );
1365
+ }
1366
+
1367
+
1368
+ /**
1369
+ * enqueue scripts
1370
+ *
1371
+ * @since 1.0.0
1372
+ * @change 1.0.0
1373
+ */
1374
+
1375
+ public static function add_admin_resources($hook) {
1376
+
1377
+ // hook check
1378
+ if ( $hook !== 'index.php' AND $hook !== 'post.php' ) {
1379
+ return;
1380
+ }
1381
+
1382
+ // plugin data
1383
+ $plugin_data = get_plugin_data(CE_FILE);
1384
+
1385
+ // enqueue scripts
1386
+ switch($hook) {
1387
+
1388
+ case 'post.php':
1389
+ wp_enqueue_script(
1390
+ 'cache-post',
1391
+ plugins_url('js/post.js', CE_FILE),
1392
+ array('jquery'),
1393
+ $plugin_data['Version'],
1394
+ true
1395
+ );
1396
+ break;
1397
+
1398
+ default:
1399
+ break;
1400
+ }
1401
+ }
1402
+
1403
+
1404
+ /**
1405
+ * add settings page
1406
+ *
1407
+ * @since 1.0.0
1408
+ * @change 1.0.0
1409
+ */
1410
+
1411
+ public static function add_settings_page() {
1412
+
1413
+ add_options_page(
1414
+ 'Cache Enabler',
1415
+ 'Cache Enabler',
1416
+ 'manage_options',
1417
+ 'cache-enabler',
1418
+ array(
1419
+ __CLASS__,
1420
+ 'settings_page'
1421
+ )
1422
+ );
1423
+ }
1424
+
1425
+
1426
+ /**
1427
+ * minify caching dropdown
1428
+ *
1429
+ * @since 1.0.0
1430
+ * @change 1.0.0
1431
+ *
1432
+ * @return array Key => value array
1433
+ */
1434
+
1435
+ private static function _minify_select() {
1436
+
1437
+ return array(
1438
+ self::MINIFY_DISABLED => esc_html__('Disabled', 'cache'),
1439
+ self::MINIFY_HTML_ONLY => 'HTML',
1440
+ self::MINIFY_HTML_JS => 'HTML & Inline JS'
1441
+ );
1442
+ }
1443
+
1444
+
1445
+ /**
1446
+ * register textdomain
1447
+ *
1448
+ * @since 1.0.0
1449
+ * @change 1.0.0
1450
+ */
1451
+
1452
+ public static function register_textdomain() {
1453
+
1454
+ load_plugin_textdomain(
1455
+ 'cache',
1456
+ false,
1457
+ 'cache-enabler/lang'
1458
+ );
1459
+ }
1460
+
1461
+
1462
+ /**
1463
+ * register settings
1464
+ *
1465
+ * @since 1.0.0
1466
+ * @change 1.0.0
1467
+ */
1468
+
1469
+ public static function register_settings() {
1470
+
1471
+ register_setting(
1472
+ 'cache-enabler',
1473
+ 'cache',
1474
+ array(
1475
+ __CLASS__,
1476
+ 'validate_settings'
1477
+ )
1478
+ );
1479
+ }
1480
+
1481
+
1482
+ /**
1483
+ * validate settings
1484
+ *
1485
+ * @since 1.0.0
1486
+ * @change 1.0.1
1487
+ *
1488
+ * @param array $data array form data
1489
+ * @return array array form data valid
1490
+ */
1491
+
1492
+ public static function validate_settings($data) {
1493
+
1494
+ // check if empty
1495
+ if ( empty($data) ) {
1496
+ return;
1497
+ }
1498
+
1499
+ // clear complete cache
1500
+ self::clear_total_cache(true);
1501
+
1502
+ return array(
1503
+ 'expires' => (int)$data['expires'],
1504
+ 'if_loggedin' => (int)(!empty($data['if_loggedin'])),
1505
+ 'new_comment' => (int)(!empty($data['new_comment'])),
1506
+ 'webp' => (int)(!empty($data['webp'])),
1507
+ 'excl_ids' => (string)sanitize_text_field(@$data['excl_ids']),
1508
+ 'minify_html' => (int)$data['minify_html']
1509
+ );
1510
+ }
1511
+
1512
+
1513
+ /**
1514
+ * settings page
1515
+ *
1516
+ * @since 1.0.0
1517
+ * @change 1.0.1
1518
+ */
1519
+
1520
+ public static function settings_page() { ?>
1521
+
1522
+ <div class="wrap" id="cache-settings">
1523
+ <h2>
1524
+ <?php _e("Cache Enabler Settings", "cache") ?>
1525
+ </h2>
1526
+
1527
+ <p><?php $size=self::get_cache_size(); printf( __("Current cache size: <b>%s</b>", "cache"), ( empty($size) ? esc_html__("Empty", "cache") : size_format($size) ) ); ?></p>
1528
+
1529
+
1530
+ <form method="post" action="options.php">
1531
+ <?php settings_fields('cache-enabler') ?>
1532
+
1533
+ <?php $options = self::_get_options() ?>
1534
+
1535
+ <table class="form-table">
1536
+ <tr valign="top">
1537
+ <th scope="row">
1538
+ <?php _e("Cache Expiry", "cache") ?>
1539
+ </th>
1540
+ <td>
1541
+ <fieldset>
1542
+ <label for="cache_expires">
1543
+ <input type="text" name="cache[expires]" id="cache_expires" value="<?php echo esc_attr($options['expires']) ?>" />
1544
+ <p class="description"><?php _e("Cache expiry in hours. An expiry time of 0 means that the cache never expires.", "cache"); ?></p>
1545
+ </label>
1546
+ </fieldset>
1547
+ </td>
1548
+ </tr>
1549
+ <tr valign="top">
1550
+ <th scope="row">
1551
+ <?php _e("Cache Behavior", "cache") ?>
1552
+ </th>
1553
+ <td>
1554
+ <fieldset>
1555
+ <label for="cache_if_loggedin">
1556
+ <input type="checkbox" name="cache[if_loggedin]" id="cache_if_loggedin" value="1" <?php checked('1', $options['if_loggedin']); ?> />
1557
+ <?php _e("Disable caching if logged in.", "cache") ?>
1558
+ </label>
1559
+
1560
+ <br />
1561
+
1562
+ <label for="cache_new_comment">
1563
+ <input type="checkbox" name="cache[new_comment]" id="cache_new_comment" value="1" <?php checked('1', $options['new_comment']); ?> />
1564
+ <?php _e("Clear the complete cache if a new comment has been posted (instead of only the page specific cache).", "cache") ?>
1565
+ </label>
1566
+
1567
+ <br />
1568
+
1569
+ <label for="cache_webp">
1570
+ <input type="checkbox" name="cache[webp]" id="cache_webp" value="1" <?php checked('1', $options['webp']); ?> />
1571
+ <?php _e("Create an additional cached version for WebP image support. Convert your images to WebP with <a href=\"https://optimus.io/en/\" target=\"_blank\">Optimus</a>.", "cache") ?>
1572
+ </label>
1573
+ </fieldset>
1574
+ </td>
1575
+ </tr>
1576
+
1577
+ <tr valign="top">
1578
+ <th scope="row">
1579
+ <?php _e("Cache Exclusions", "cache") ?>
1580
+ </th>
1581
+ <td>
1582
+ <fieldset>
1583
+ <label for="cache_excl_ids">
1584
+ <input type="text" name="cache[excl_ids]" id="cache_excl_ids" value="<?php echo esc_attr($options['excl_ids']) ?>" />
1585
+ <p class="description"><?php _e("Post or Pages IDs separated by a <code>,</code> that should not be cached.", "cache"); ?></p>
1586
+ </label>
1587
+ </fieldset>
1588
+ </td>
1589
+ </tr>
1590
+
1591
+ <tr valign="top">
1592
+ <th scope="row">
1593
+ <?php _e("Cache Minification", "cache") ?>
1594
+ </th>
1595
+ <td>
1596
+ <label for="cache_minify_html">
1597
+ <select name="cache[minify_html]" id="cache_minify_html">
1598
+ <?php foreach( self::_minify_select() as $k => $v ) { ?>
1599
+ <option value="<?php echo esc_attr($k) ?>" <?php selected($options['minify_html'], $k); ?>>
1600
+ <?php echo esc_html($v) ?>
1601
+ </option>
1602
+ <?php } ?>
1603
+ </select>
1604
+ </label>
1605
+ </td>
1606
+ </tr>
1607
+
1608
+ <tr valign="top">
1609
+ <th scope="row">
1610
+ <?php submit_button() ?>
1611
+ </th>
1612
+ <td>
1613
+ <p class="description"><?php _e("Saving these settings will clear the complete cache.","cache") ?></p>
1614
+ </td>
1615
+ </tr>
1616
+ </table>
1617
+ </form>
1618
+ <p class="description"><?php _e("It is recommended to enable HTTP/2 on your origin server and use a CDN that supports HTTP/2. Avoid domain sharding and concatenation of your assets to benefit from parallelism of HTTP/2.","cache") ?></p>
1619
+
1620
+ </div><?php
1621
+ }
1622
+ }
inc/cache_enabler_disk.class.php ADDED
@@ -0,0 +1,505 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ // exit
5
+ defined('ABSPATH') OR exit;
6
+
7
+
8
+ /**
9
+ * Cache_Enabler_Disk
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+
14
+ final class Cache_Enabler_Disk {
15
+
16
+
17
+ /**
18
+ * permalink check
19
+ *
20
+ * @since 1.0.0
21
+ * @change 1.0.0
22
+ *
23
+ * @return boolean true if installed
24
+ */
25
+
26
+ public static function is_permalink() {
27
+ return get_option('permalink_structure');
28
+ }
29
+
30
+
31
+ /**
32
+ * store asset
33
+ *
34
+ * @since 1.0.0
35
+ * @change 1.0.0
36
+ *
37
+ * @param string $data content of the asset
38
+ */
39
+
40
+ public static function store_asset($data) {
41
+
42
+ // check if empty
43
+ if ( empty($data) ) {
44
+ wp_die('Asset is empty.');
45
+ }
46
+
47
+ // save asset
48
+ self::_create_files(
49
+ $data . self::_cache_signatur()
50
+ );
51
+
52
+ }
53
+
54
+
55
+ /**
56
+ * check asset
57
+ *
58
+ * @since 1.0.0
59
+ * @change 1.0.0
60
+ *
61
+ * @return boolean true if asset exists
62
+ */
63
+
64
+ public static function check_asset() {
65
+ return is_readable(
66
+ self::_file_html()
67
+ );
68
+ }
69
+
70
+
71
+ /**
72
+ * check expiry
73
+ *
74
+ * @since 1.0.1
75
+ * @change 1.0.1
76
+ *
77
+ * @return boolean true if asset expired
78
+ */
79
+
80
+ public static function check_expiry() {
81
+
82
+ // cache enabler options
83
+ $options = Cache_Enabler::$options;
84
+
85
+ // check if expires is active
86
+ if ($options['expires'] == 0) {
87
+ return false;
88
+ }
89
+
90
+ $now = time();
91
+ $expires_seconds = 3600*$options['expires'];
92
+
93
+ // check if asset has expired
94
+ if ( ( filemtime(self::_file_html()) + $expires_seconds ) <= $now ) {
95
+ return true;
96
+ }
97
+
98
+ return false;
99
+
100
+ }
101
+
102
+
103
+ /**
104
+ * delete asset
105
+ *
106
+ * @since 1.0.0
107
+ * @change 1.0.0
108
+ *
109
+ * @param string $url url of cached asset
110
+ */
111
+
112
+ public static function delete_asset($url) {
113
+
114
+ // check if url empty
115
+ if ( empty($url) ) {
116
+ wp_die('URL is empty.');
117
+ }
118
+
119
+ // delete
120
+ self::_clear_dir(
121
+ self::_file_path($url)
122
+ );
123
+ }
124
+
125
+
126
+ /**
127
+ * clear cache
128
+ *
129
+ * @since 1.0.0
130
+ * @change 1.0.0
131
+ */
132
+
133
+ public static function clear_cache() {
134
+ self::_clear_dir(
135
+ CE_CACHE_DIR
136
+ );
137
+ }
138
+
139
+
140
+ /**
141
+ * get asset
142
+ *
143
+ * @since 1.0.0
144
+ * @change 1.0.0
145
+ */
146
+
147
+ public static function get_asset() {
148
+
149
+ // get if-modified request headers
150
+ if ( function_exists( 'apache_request_headers' ) ) {
151
+ $headers = apache_request_headers();
152
+ $http_if_modified_since = ( isset( $headers[ 'If-Modified-Since' ] ) ) ? $headers[ 'If-Modified-Since' ] : '';
153
+ $http_accept = ( isset( $headers[ 'Accept' ] ) ) ? $headers[ 'Accept' ] : '';
154
+ } else {
155
+ $http_if_modified_since = ( isset( $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ] ) ) ? $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ] : '';
156
+ $http_accept = ( isset( $_SERVER[ 'HTTP_ACCEPT' ] ) ) ? $_SERVER[ 'HTTP_ACCEPT' ] : '';
157
+ }
158
+
159
+ // check modified since with cached file and return 304 if no difference
160
+ if ( $http_if_modified_since && ( strtotime( $http_if_modified_since ) == filemtime( self::_file_html() ) ) ) {
161
+ header( $_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified', true, 304 );
162
+ exit;
163
+ }
164
+
165
+ //var_dump($http_accept);
166
+
167
+ // check webp support
168
+ if ( $http_accept && ( strpos($http_accept, 'webp') !== false ) ) {
169
+ header('Content-Encoding: gzip');
170
+ readfile( self::_file_webp() );
171
+ exit;
172
+ }
173
+
174
+ // deliver cached file
175
+ readfile( self::_file_html() );
176
+ exit;
177
+ }
178
+
179
+
180
+ /**
181
+ * create signature
182
+ *
183
+ * @since 1.0.0
184
+ * @change 1.0.0
185
+ *
186
+ * @return string signature
187
+ */
188
+
189
+ private static function _cache_signatur() {
190
+ return sprintf(
191
+ "\n\n<!-- %s @ %s -->",
192
+ 'Cache Enabler by KeyCDN',
193
+ date_i18n(
194
+ 'd.m.Y H:i:s',
195
+ current_time('timestamp')
196
+ )
197
+ );
198
+ }
199
+
200
+
201
+ /**
202
+ * create files
203
+ *
204
+ * @since 1.0.0
205
+ * @change 1.0.0
206
+ *
207
+ * @param string $data html content
208
+ */
209
+
210
+ private static function _create_files($data) {
211
+
212
+ // create folder
213
+ if ( ! wp_mkdir_p( self::_file_path() ) ) {
214
+ wp_die('Unable to create directory.');
215
+ }
216
+
217
+ // create files
218
+ self::_create_file( self::_file_html(), $data );
219
+ self::_create_file( self::_file_gzip(), gzencode($data."\n<!-- (gzip) -->", 9) );
220
+
221
+ // cache enabler options
222
+ $options = Cache_Enabler::$options;
223
+
224
+ // create webp supported files
225
+ if ($options['webp']) {
226
+ self::_create_file( self::_file_webp(), gzencode(self::_convert_webp($data)."\n<!-- (webp) -->", 9) );
227
+ }
228
+
229
+ }
230
+
231
+
232
+ /**
233
+ * create file
234
+ *
235
+ * @since 1.0.0
236
+ * @change 1.0.0
237
+ *
238
+ * @param string $file file path
239
+ * @param string $data content of the html
240
+ */
241
+
242
+ private static function _create_file($file, $data) {
243
+
244
+ // open file handler
245
+ if ( ! $handle = @fopen($file, 'wb') ) {
246
+ wp_die('Can not write to file.');
247
+ }
248
+
249
+ // write
250
+ @fwrite($handle, $data);
251
+ fclose($handle);
252
+ clearstatcache();
253
+
254
+ // set permissions
255
+ $stat = @stat( dirname($file) );
256
+ $perms = $stat['mode'] & 0007777;
257
+ $perms = $perms & 0000666;
258
+ @chmod($file, $perms);
259
+ clearstatcache();
260
+ }
261
+
262
+
263
+ /**
264
+ * clear directory
265
+ *
266
+ * @since 1.0.0
267
+ * @change 1.0.0
268
+ *
269
+ * @param string $dir directory
270
+ */
271
+
272
+ private static function _clear_dir($dir) {
273
+
274
+ // remove slashes
275
+ $dir = untrailingslashit($dir);
276
+
277
+ // check if dir
278
+ if ( ! is_dir($dir) ) {
279
+ return;
280
+ }
281
+
282
+ // get dir data
283
+ $objects = array_diff(
284
+ scandir($dir),
285
+ array('..', '.')
286
+ );
287
+
288
+ if ( empty($objects) ) {
289
+ return;
290
+ }
291
+
292
+ foreach ( $objects as $object ) {
293
+ // full path
294
+ $object = $dir. DIRECTORY_SEPARATOR .$object;
295
+
296
+ // check if directory
297
+ if ( is_dir($object) ) {
298
+ self::_clear_dir($object);
299
+ } else {
300
+ unlink($object);
301
+ }
302
+ }
303
+
304
+ // delete
305
+ @rmdir($dir);
306
+
307
+ // clears file status cache
308
+ clearstatcache();
309
+ }
310
+
311
+
312
+ /**
313
+ * get cache size
314
+ *
315
+ * @since 1.0.0
316
+ * @change 1.0.0
317
+ *
318
+ * @param string $dir folder path
319
+ * @return mixed $size size in bytes
320
+ */
321
+
322
+ public static function cache_size($dir = '.') {
323
+
324
+ // check if not dir
325
+ if ( ! is_dir($dir) ) {
326
+ return;
327
+ }
328
+
329
+ // get dir data
330
+ $objects = array_diff(
331
+ scandir($dir),
332
+ array('..', '.')
333
+ );
334
+
335
+ if ( empty($objects) ) {
336
+ return;
337
+ }
338
+
339
+ $size = 0;
340
+
341
+ foreach ( $objects as $object ) {
342
+ // full path
343
+ $object = $dir. DIRECTORY_SEPARATOR .$object;
344
+
345
+ // check if dir
346
+ if ( is_dir($object) ) {
347
+ $size += self::cache_size($object);
348
+ } else {
349
+ $size += filesize($object);
350
+ }
351
+ }
352
+
353
+ return $size;
354
+ }
355
+
356
+
357
+ /**
358
+ * cache path
359
+ *
360
+ * @since 1.0.0
361
+ * @change 1.0.0
362
+ *
363
+ * @param string $path uri or permlink
364
+ * @return string $diff path to cached asset
365
+ */
366
+
367
+ private static function _file_path($path = NULL) {
368
+
369
+ $path = sprintf(
370
+ '%s%s%s%s',
371
+ CE_CACHE_DIR,
372
+ DIRECTORY_SEPARATOR,
373
+ parse_url(
374
+ 'http://' .strtolower($_SERVER['HTTP_HOST']),
375
+ PHP_URL_HOST
376
+ ),
377
+ parse_url(
378
+ ( $path ? $path : $_SERVER['REQUEST_URI'] ),
379
+ PHP_URL_PATH
380
+ )
381
+ );
382
+
383
+ if ( validate_file($path) > 0 ) {
384
+ wp_die('Path is not valid.');
385
+ }
386
+
387
+ return trailingslashit($path);
388
+ }
389
+
390
+
391
+ /**
392
+ * get file path
393
+ *
394
+ * @since 1.0.0
395
+ * @change 1.0.0
396
+ *
397
+ * @return string path to the html file
398
+ */
399
+
400
+ private static function _file_html() {
401
+ return self::_file_path(). 'index.html';
402
+ }
403
+
404
+
405
+ /**
406
+ * get gzip file path
407
+ *
408
+ * @since 1.0.1
409
+ * @change 1.0.1
410
+ *
411
+ * @return string path to the gzipped html file
412
+ */
413
+
414
+ private static function _file_gzip() {
415
+ return self::_file_path(). 'index.html.gz';
416
+ }
417
+
418
+
419
+ /**
420
+ * get webp file path
421
+ *
422
+ * @since 1.0.1
423
+ * @change 1.0.1
424
+ *
425
+ * @return string path to the webp gzipped html file
426
+ */
427
+
428
+ private static function _file_webp() {
429
+ return self::_file_path(). 'index.html.webp';
430
+ }
431
+
432
+
433
+ /**
434
+ * convert to webp
435
+ *
436
+ * @since 1.0.1
437
+ * @change 1.0.1
438
+ *
439
+ * @return string converted HTML file
440
+ */
441
+
442
+ private static function _convert_webp($data) {
443
+
444
+ $dom = new DOMDocument();
445
+ $dom->loadHTML($data);
446
+
447
+ $imgs = $dom->getElementsByTagName("img");
448
+
449
+ foreach($imgs as $img){
450
+
451
+ $src = $img->getAttribute('src');
452
+ $src_webp = self::_convert_webp_src($src);
453
+ if ($src != $src_webp) {
454
+ $img->setAttribute('src' , $src_webp);
455
+ }
456
+
457
+ }
458
+
459
+ $img_links = $dom->getElementsByTagName("a");
460
+
461
+ foreach($img_links as $img_link){
462
+
463
+ $src = $img_link->getAttribute('href');
464
+ $src_webp = self::_convert_webp_src($src);
465
+ if ($src != $src_webp) {
466
+ $img_link->setAttribute('href' , $src_webp);
467
+ }
468
+
469
+ }
470
+
471
+ return $dom->saveHtml();
472
+
473
+ }
474
+
475
+
476
+ /**
477
+ * convert to webp source
478
+ *
479
+ * @since 1.0.1
480
+ * @change 1.0.1
481
+ *
482
+ * @return string converted webp source
483
+ */
484
+
485
+ private static function _convert_webp_src($src) {
486
+ if ( strpos($src, 'wp-content') !== false ) {
487
+
488
+ $src_webp = str_replace('.jpg', '.webp', $src);
489
+ $src_webp = str_replace('.png', '.webp', $src_webp);
490
+
491
+ $relative_path = str_replace(get_site_url().'/wp-content/uploads', '', $src_webp);
492
+
493
+ $upload_path = wp_upload_dir();
494
+ $base_dir = $upload_path['basedir'];
495
+
496
+ if ( file_exists($base_dir.$relative_path) ) {
497
+ return $src_webp;
498
+ }
499
+
500
+ }
501
+
502
+ return $src;
503
+ }
504
+
505
+ }
js/post.js ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(
2
+ function($) {
3
+
4
+ $('.edit-cache-action', '#misc-publishing-actions').click(
5
+ function(e) {
6
+ $(this)
7
+ .next(':hidden')
8
+ .slideDown('fast')
9
+ .end()
10
+ .hide();
11
+
12
+ e.preventDefault();
13
+ }
14
+ );
15
+
16
+ $('.save-cache-action', '#misc-publishing-actions').click(
17
+ function(e) {
18
+ $(this)
19
+ .parent()
20
+ .slideUp('fast')
21
+ .prev(':hidden')
22
+ .show();
23
+
24
+ $('#output-cache-action').text(
25
+ $('#cache_action').children('option:selected').text()
26
+ );
27
+
28
+ e.preventDefault();
29
+ }
30
+ );
31
+
32
+ $('.cancel-cache-action', '#misc-publishing-actions').click(
33
+ function(e) {
34
+ $(this)
35
+ .parent()
36
+ .slideUp('fast')
37
+ .prev(':hidden')
38
+ .show();
39
+
40
+ e.preventDefault();
41
+ }
42
+ );
43
+ }
44
+ );
readme.txt ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Cache Enabler - WordPress Caching ===
2
+ Contributors: keycdn
3
+ Tags: cache, caching, performance
4
+ Requires at least: 3.8
5
+ Tested up to: 4.3
6
+ Stable tag: trunk
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+
11
+
12
+ A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files.
13
+
14
+
15
+
16
+ == Description ==
17
+
18
+
19
+ The Cache Enabler plugin creates static HTML files and stores them on the servers disk. The web server will deliver the static HTML file and avoids the resource intensive backend processes (core, plugins and database). This will improve the performance of your WordPress installation.
20
+
21
+
22
+ = Features =
23
+ * Efficient and fast disk cache engine
24
+ * Automated and/or manual clearing of the cache
25
+ * Display of the actual cache size
26
+ * Minification of the HTML doc
27
+ * WordPress multisite support
28
+ * Custom Post Type support
29
+
30
+
31
+ = Support =
32
+ Just [contact us](https://www.keycdn.com/contacts "Support Request") directly to get support on this plugin.
33
+
34
+
35
+ = System Requirements =
36
+ * PHP >=5.3
37
+ * WordPress >=3.8
38
+
39
+
40
+ = Website =
41
+ * [Cache Enabler by KeyCDN](https://www.keycdn.com "KeyCDN")
42
+
43
+
44
+ = Autor =
45
+ * [Twitter](https://twitter.com/keycdn)
46
+ * [Google+](https://plus.google.com/+Keycdn "Google+")
47
+ * [KeyCDN](https://www.keycdn.com "KeyCDN")
48
+
49
+
50
+
51
+
52
+ == Changelog ==
53
+
54
+ = 1.0.1 =
55
+ * Added WebP support and expiry directive
56
+
57
+ = 1.0.0 =
58
+ * Initial Release