-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathConstans.php
562 lines (431 loc) · 17.4 KB
/
Constans.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<?php
/**
* Docket Cache.
*
* @author Nawawi Jamili
* @license MIT
*
* @see https://github.com/nawawi/docket-cache
*/
namespace Nawawi\DocketCache;
\defined('ABSPATH') || exit;
final class Constans
{
public function __construct()
{
$this->register_default();
}
public function px($name)
{
return nwdcx_constfx($name);
}
public function is_false($name)
{
return !\defined($name) || !\constant($name);
}
public function is_true($name)
{
return \defined($name) && \constant($name);
}
public function value($name)
{
$value = '';
if (\defined($name)) {
$value = \constant($name);
}
return $value;
}
public function is_array($name)
{
$value = $this->value($name);
return !empty($value) && \is_array($value);
}
public function is_int($name)
{
$value = $this->value($name);
return !empty($value) && \is_int($value);
}
public function is($name, $value)
{
return \defined($name) && $value === \constant($name);
}
public function is_dctrue($name, $reload = false)
{
$key = $this->px($name);
if ($reload) {
$this->maybe_define($key, false, true);
}
return $this->is_true($key);
}
public function is_dcfalse($name, $reload = false)
{
$key = $this->px($name);
if ($reload) {
$this->maybe_define($key, false, true);
}
return $this->is_false($key);
}
public function is_dcarray($name, &$value = '', $reload = false)
{
$key = $this->px($name);
if ($reload) {
$this->maybe_define($key, false, true);
}
$value = '';
if ($this->is_array($key)) {
$value = $this->value($key);
return true;
}
return false;
}
public function is_dcint($name, &$value = '', $reload = false)
{
$key = $this->px($name);
if ($reload) {
$this->maybe_define($key, false, true);
}
$value = '';
if ($this->is_int($key)) {
$value = $this->value($key);
return true;
}
return false;
}
public function dcvalue($name, $reload = false)
{
$key = $this->px($name);
if ($reload) {
$this->maybe_define($key, '', true);
}
return $this->value($key);
}
public function maybe_define($name, $value, $user_config = true)
{
if (!\defined($name)) {
if ($user_config && class_exists('Nawawi\\DocketCache\\Canopt')) {
$nv = Canopt::init()->get($name);
if (!empty($nv) && 'default' !== $nv) {
switch ($nv) {
case 'enable':
$nv = true;
break;
case 'disable':
$nv = false;
break;
}
$value = $nv;
}
}
return @\define($name, $value);
}
// mark defined constants
if (empty($GLOBALS['DOCKET_CACHE_RUNTIME'])) {
$GLOBALS['DOCKET_CACHE_RUNTIME'] = [];
}
$GLOBAL['DOCKET_CACHE_RUNTIME'][$this->px($name.'_FALSE')] = 1;
return false;
}
public function register_default()
{
// compat
$this->maybe_define('WP_CONTENT_DIR', nwdcx_normalizepath(ABSPATH).'wp-content', false);
$this->maybe_define('WP_PLUGIN_DIR', nwdcx_normalizepath(WP_CONTENT_DIR).'/plugins', false);
$this->maybe_define('DOCKET_CACHE_CONTENT_PATH', nwdcx_normalizepath(WP_CONTENT_DIR), false);
// data dir
$this->maybe_define($this->px('DATA_PATH'), DOCKET_CACHE_CONTENT_PATH.'/docket-cache-data/', false);
// cache dir
$this->maybe_define($this->px('PATH'), DOCKET_CACHE_CONTENT_PATH.'/cache/docket-cache/', false);
// object max size: 3MB, 1MB = 1048576 bytes (binary) = 1000000 bytes (decimal)
// Only numbers between 1000000 and 10485760 are accepted
$this->maybe_define($this->px('MAXSIZE'), 3145728);
// cache file max size total: 500MB, 1MB = 1048576 bytes (binary) = 1000000 bytes (decimal)
// minimum 100MB
$this->maybe_define($this->px('MAXSIZE_DISK'), 524288000);
// cache file max accelerated files: Only numbers between 200 and 200000 are accepted
$this->maybe_define($this->px('MAXFILE'), 50000);
// check cache file limit in real-time
$this->maybe_define($this->px('MAXFILE_LIVECHECK'), false);
// cache maxttl: cache lifespan. Only seconds between 86400 and 2419200 are accepted
$this->maybe_define($this->px('MAXTTL'), 345600); // 4d
// log on/off
$this->maybe_define($this->px('LOG'), false);
// log all on/off
$this->maybe_define($this->px('LOG_ALL'), \defined('WP_DEBUG') ? WP_DEBUG : false);
// log file
$this->maybe_define($this->px('LOG_FILE'), DOCKET_CACHE_CONTENT_PATH.'/.object-cache.log');
// empty file when cache flushed
$this->maybe_define($this->px('LOG_FLUSH'), true);
// log time format: utc, local
$this->maybe_define($this->px('LOG_TIME'), 'utc');
// log file max size: 10MB, 1MB = 1048576 bytes (binary) = 1000000 bytes (decimal)
$this->maybe_define($this->px('LOG_SIZE'), 10485760);
// truncate or delete cache file
$this->maybe_define($this->px('FLUSH_DELETE'), false);
// flush cache when deactivate/uninstall
$this->maybe_define($this->px('FLUSH_SHUTDOWN'), true);
// flush wc_cache / advanced post cache / wp stale cache
$this->maybe_define($this->px('FLUSH_STALECACHE'), false);
// split a cache file into smaller directory
$this->maybe_define($this->px('CHUNKCACHEDIR'), false);
// ignore stale cache
$this->maybe_define($this->px('STALECACHE_IGNORE'), false);
// ignore empty cache
$this->maybe_define($this->px('EMPTYCACHE_IGNORE'), false);
// optimize db
$this->maybe_define($this->px('CRONOPTMZDB'), 'never');
// option autoload
$this->maybe_define($this->px('WPOPTALOAD'), false);
// global cache group for multisite
$this->maybe_define(
$this->px('GLOBAL_GROUPS'),
[
'blog-details',
'blog-id-cache',
'blog-lookup',
'global-posts',
'networks',
'network-queries',
'rss',
'sites',
'site-details',
'site-lookup',
'site-options',
'site-queries',
'site-transient',
'users',
'useremail',
'userlogins',
'usermeta',
'user_meta',
'userslugs',
]
);
// cache ignored groups
$this->maybe_define(
$this->px('IGNORED_GROUPS'),
[
'themes',
'counts',
'plugins',
]
);
// @private
// cache ignored keys
// @note: dnh_dismissed_notices -> https://github.com/julien731/WP-Dismissible-Notices-Handler
$this->maybe_define($this->px('IGNORED_KEYS'), ['dnh_dismissed_notices']);
// @private
// cache ignored group => key, group => [key1, key2]
$this->maybe_define($this->px('IGNORED_GROUPKEY'), []);
// @private
// this option private for right now
$this->maybe_define(
$this->px('FILTERED_GROUPS'),
[
'counts' => [
'posts-page',
'posts-post',
],
]
);
// precache
$this->maybe_define($this->px('PRECACHE'), false);
// precache maxfile
$this->maybe_define($this->px('PRECACHE_MAXFILE'), 100);
// precache max key
$this->maybe_define($this->px('PRECACHE_MAXKEY'), 20);
// precache max group
$this->maybe_define($this->px('PRECACHE_MAXGROUP'), 20);
// @private
// cache ignored precache
$this->maybe_define(
$this->px('IGNORED_PRECACHE'),
[
'freemius' => 'fs_accounts',
'options' => [
'uninstall_plugins',
'auto_update_plugins',
'active_plugins',
'cron',
'litespeed_messages',
'litespeed.admin_display.messages',
],
'site-options' => [
'1:auto_update_plugins',
'1:active_sitewide_plugins',
],
]
);
// transient in DB.
$this->maybe_define($this->px('TRANSIENTDB'), false);
// exclude transient in DB.
$this->maybe_define($this->px('IGNORED_TRANSIENTDB'),
[
'doing_cron',
'update_plugins',
'update_themes',
'update_core',
]
);
// misc tweaks
$this->maybe_define($this->px('MISC_TWEAKS'), true);
// woocommerce tweaks
$this->maybe_define($this->px('WOOTWEAKS'), true);
// woocommerce admin
$this->maybe_define($this->px('WOOADMINOFF'), false);
// woocommerce dashboard status meta box
$this->maybe_define($this->px('WOOWPDASHBOARDOFF'), false);
// woocommerce widget
$this->maybe_define($this->px('WOOWIDGETOFF'), false);
// woocommerce cart fragments
$this->maybe_define($this->px('WOOCARTFRAGSOFF'), false);
// woocommerce robots crawling add-to-cart links
$this->maybe_define($this->px('WOOADDTOCHARTCRAWLING'), true);
// woocommerce marketplace / my subscription menu page
$this->maybe_define($this->px('WOOEXTENSIONPAGEOFF'), false);
// post missed schedule
$this->maybe_define($this->px('POSTMISSEDSCHEDULE'), false);
// optimize term count
$this->maybe_define($this->px('OPTERMCOUNT'), true);
// translation mo file cache
$this->maybe_define($this->px('MOCACHE'), false);
// menu cache
$this->maybe_define($this->px('MENUCACHE'), false);
// menu cache ttl: 1209600 = 14 days
$this->maybe_define($this->px('MENUCACHE_TTL'), 1209600);
// @private
// wp-cli
$this->maybe_define($this->px('WPCLI'), \defined('WP_CLI') && WP_CLI);
// banner
$this->maybe_define($this->px('SIGNATURE'), true);
// preload
$this->maybe_define($this->px('PRELOAD'), false);
// page loader
$this->maybe_define($this->px('PAGELOADER'), true);
// docket cronbot
$this->maybe_define($this->px('CRONBOT'), true);
// docket cronbot
$this->maybe_define($this->px('CRONBOT_MAX'), 10);
// opcviewer
$this->maybe_define($this->px('OPCVIEWER'), false);
// opcviewer show all
$this->maybe_define($this->px('OPCVIEWER_SHOWALL'), false);
// cache stats
$this->maybe_define($this->px('STATS'), true);
// gc action button
$this->maybe_define($this->px('GCACTION'), false);
// additional flush cache button
$this->maybe_define($this->px('FLUSHACTION'), false);
// check version
$this->maybe_define($this->px('CHECKVERSION'), false);
// / @private: auto update
// 28012023: DOCKET_CACHE_AUTOUPDATE only to force WP auto_update_plugin filter.
// DOCKET_CACHE_AUTOUPDATE_TOGGLE will sync with WP auto_update_plugins option.
// $this->maybe_define($this->px('AUTOUPDATE'), false);
$this->maybe_define($this->px('AUTOUPDATE_TOGGLE'), false);
// flush opcache when deactivate
$this->maybe_define($this->px('OPCSHUTDOWN'), false);
// optimize post query
$this->maybe_define($this->px('OPTWPQUERY'), true);
// limit bulk edit
$this->maybe_define($this->px('LIMITBULKEDIT'), false);
// limit bulk edit bulk limit
$this->maybe_define($this->px('LIMITBULKEDIT_LIMIT'), 100);
// xmlrpc pingbacks
$this->maybe_define($this->px('PINGBACK'), true);
// header junk
$this->maybe_define($this->px('HEADERJUNK'), true);
// wp emoji
$this->maybe_define($this->px('WPEMOJI'), false);
// wp embed
$this->maybe_define($this->px('WPEMBED'), false);
// wp feed
$this->maybe_define($this->px('WPFEED'), false);
// wp lazyload
$this->maybe_define($this->px('WPLAZYLOAD'), false);
// wp sitemap
$this->maybe_define($this->px('WPSITEMAP'), false);
// wp sitemap
$this->maybe_define($this->px('WPDASHBOARDNEWS'), false);
// wp application password: wp >= 5.6
$this->maybe_define($this->px('WPAPPPASSWORD'), false);
// limit http request from uncommon page.
$this->maybe_define($this->px('LIMITHTTPREQUEST'), false);
// whitelist host from limit http request.
$this->maybe_define($this->px('LIMITHTTPREQUEST_WHITELIST'), []/* ['feeds.feedburner.com'] */);
// wp browse-happy
$this->maybe_define($this->px('WPBROWSEHAPPY'), false);
// wp serve-happy
$this->maybe_define($this->px('WPSERVEHAPPY'), false);
// post vis email
$this->maybe_define($this->px('POSTVIAEMAIL'), false);
// cache http response from wp_remote_request.
$this->maybe_define($this->px('CACHEHTTPRESPONSE'), false);
// cache http response ttl: 300 = 5 minutes.
$this->maybe_define($this->px('CACHEHTTPRESPONS_TTL'), 300);
// cache http include list, if empty any url will include.
$this->maybe_define($this->px('CACHEHTTPRESPONS_INCLUDE'), []);
// cache http exclude list.
$this->maybe_define($this->px('CACHEHTTPRESPONS_EXCLUDE'), []);
// @compat: wp version < 6.1 || < 5.8
if (isset($GLOBALS['wp_version'])) {
if (version_compare($GLOBALS['wp_version'], '6.1', '<')) {
// advanced post cache
$this->maybe_define($this->px('ADVCPOST'), false);
// advanced post cache allow post type
$this->maybe_define(
$this->px('ADVCPOST_POSTTYPE'),
[
'post',
'page',
'attachment',
'revision',
'nav_menu_item',
'custom_css',
'customize_changeset',
'oembed_cache',
'user_request',
'wp_block',
'wp_template',
'wp_template_part',
'wp_global_styles',
'wp_navigation',
]
);
// advanced post cache allow all post type
$this->maybe_define($this->px('ADVCPOST_POSTTYPE_ALL'), false);
}
if (version_compare($GLOBALS['wp_version'], '5.8', '<')) {
// curl "Expect" header performance tweak
$this->maybe_define($this->px('HTTPHEADERSEXPECT'), false);
}
}
// @private: auto save interval.
$this->maybe_define($this->px('RTPOSTAUTOSAVE'), 1);
// @private: post revision.
$this->maybe_define($this->px('RTPOSTREVISION'), 'on');
// @private: empty trash.
$this->maybe_define($this->px('RTPOSTEMPTYTRASH'), 30);
// @private: plugin / theme editor.
$this->maybe_define($this->px('RTPLUGINTHEMEEDITOR'), \defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT ? 'on' : 'off');
// @private: plugin / theme install.
$this->maybe_define($this->px('RTPLUGINTHEMEINSTALL'), \defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS ? 'on' : 'off');
// @private: overwrite image after edit.
$this->maybe_define($this->px('RTIMAGEOVERWRITE'), \defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ? 'on' : 'off');
// @private: wp debug.
$this->maybe_define($this->px('RTWPDEBUG'), \defined('WP_DEBUG') && WP_DEBUG ? 'on' : 'off');
// @private: wp debug display.
$this->maybe_define($this->px('RTWPDEBUGDISPLAY'), \defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY ? 'on' : 'off');
// @private: wp debug log.
$this->maybe_define($this->px('RTWPDEBUGLOG'), \defined('WP_DEBUG_LOG') && WP_DEBUG_LOG ? 'on' : 'off');
// @private: deactivate wp auto update core.
$this->maybe_define($this->px('RTWPCOREUPDATE'), \defined('WP_AUTO_UPDATE_CORE') && WP_AUTO_UPDATE_CORE ? 'off' : 'on');
// @private: deactivate concatenate wp-admin scripts.
$this->maybe_define($this->px('RTCONCATENATESCRIPTS'), \defined('CONCATENATE_SCRIPTS') && !(bool) CONCATENATE_SCRIPTS ? 'on' : 'off');
// @private: deactivate wp cron.
$this->maybe_define($this->px('RTDISABLEWPCRON'), \defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ? 'on' : 'off');
// @private
// capture fatal error rarely incase non-throwable
// set true for debugging only
$this->maybe_define($this->px('CAPTURE_FATALERROR'), false);
}
}