-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathdebug2.cls.php
More file actions
716 lines (614 loc) · 18.4 KB
/
debug2.cls.php
File metadata and controls
716 lines (614 loc) · 18.4 KB
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
<?php
/**
* The plugin logging class.
*
* @package LiteSpeed
* @since 1.1.2
*/
namespace LiteSpeed;
defined( 'WPINC' ) || exit();
/**
* Centralized debug logging utilities for LiteSpeed Cache.
*/
class Debug2 extends Root {
/**
* Active log file path.
*
* @var string
*/
private static $log_path;
/**
* Directory prefix for all log files.
*
* @var string
*/
private static $log_path_prefix;
/**
* Request-specific log line prefix.
*
* @var string
*/
private static $_prefix;
const TYPE_CLEAR_LOG = 'clear_log';
const TYPE_BETA_TEST = 'beta_test';
const TYPE_DOWNLOAD_LOG = 'download_log';
const BETA_TEST_URL = 'beta_test_url';
const BETA_TEST_URL_WP = 'https://downloads.wordpress.org/plugin/litespeed-cache.zip';
/**
* Constructor.
*
* NOTE: until LSCWP_LOG is defined, calls to WP filters are not logged to
* avoid a recursion loop inside log_filters().
*
* @since 1.1.2
* @access public
*/
public function __construct() {
self::$log_path_prefix = LITESPEED_STATIC_DIR . '/debug/';
// Maybe move legacy log files
$this->_maybe_init_folder();
self::$log_path = $this->path( 'debug' );
$ua = isset( $_SERVER['HTTP_USER_AGENT'] )
? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) )
: '';
if ( '' !== $ua && 0 === strpos( $ua, 'lscache_' ) ) {
self::$log_path = $this->path( 'crawler' );
}
! defined( 'LSCWP_LOG_TAG' ) && define( 'LSCWP_LOG_TAG', get_current_blog_id() );
if ( $this->conf( Base::O_DEBUG_LEVEL ) ) {
! defined( 'LSCWP_LOG_MORE' ) && define( 'LSCWP_LOG_MORE', true );
}
defined( 'LSCWP_DEBUG_EXC_STRINGS' ) || define( 'LSCWP_DEBUG_EXC_STRINGS', $this->conf( Base::O_DEBUG_EXC_STRINGS ) );
}
/**
* Disable all functionalities temporarily (toggle).
*
* @since 7.4
* @access public
*
* @param int $time How long (in seconds) to disable LSC functions.
*/
public static function tmp_disable( $time = 86400 ) {
$conf = Conf::cls();
$disabled = self::cls()->conf( Base::DEBUG_TMP_DISABLE );
if ( 0 === $disabled ) {
$conf->update_confs( [ Base::DEBUG_TMP_DISABLE => time() + (int) $time ] );
self::debug2( 'LiteSpeed Cache temporary disabled.' );
return;
}
$conf->update_confs( [ Base::DEBUG_TMP_DISABLE => 0 ] );
self::debug2( 'LiteSpeed Cache reactivated.' );
}
/**
* Is the temporary disable active? If expired, re-enable.
*
* @since 7.4
* @access public
*
* @return bool
*/
public static function is_tmp_disable() {
$disabled_time = self::cls()->conf( Base::DEBUG_TMP_DISABLE );
if ( 0 === $disabled_time ) {
return false;
}
if ( time() < (int) $disabled_time ) {
return true;
}
Conf::cls()->update_confs( [ Base::DEBUG_TMP_DISABLE => 0 ] );
return false;
}
/**
* Ensure log directory exists and move legacy logs into it.
*
* @since 6.5
* @access private
*/
private function _maybe_init_folder() {
if ( file_exists( self::$log_path_prefix . 'index.php' ) ) {
return;
}
File::save( self::$log_path_prefix . 'index.php', '<?php // Silence is golden.', true );
$logs = [ 'debug', 'debug.purge', 'crawler' ];
foreach ( $logs as $log ) {
$old_path = LSCWP_CONTENT_DIR . '/' . $log . '.log';
$new_path = $this->path( $log );
if ( file_exists( $old_path ) && ! file_exists( $new_path ) ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.rename_rename -- Moving legacy log files during migration
rename( $old_path, $new_path );
}
}
}
/**
* Get absolute path for a log type.
*
* @since 6.5
* @param string $type Log type (debug|purge|crawler).
* @return string
*/
public function path( $type ) {
return self::$log_path_prefix . self::FilePath( $type );
}
/**
* Get fixed filename for a log type.
*
* @since 6.5
* @param string $type Log type (debug|debug.purge|crawler).
* @return string
*/
public static function FilePath( $type ) {
if ( 'debug.purge' === $type ) {
$type = 'purge';
}
$key = defined( 'AUTH_KEY' ) ? AUTH_KEY : md5( __FILE__ );
$rand = substr( md5( substr( $key, -16 ) ), -16 );
return $type . $rand . '.log';
}
/**
* Write end-of-request markers and response timing.
*
* @since 4.7
* @access public
* @return void
*/
public static function ended() {
$headers = headers_list();
foreach ( $headers as $key => $header ) {
if ( 0 === stripos( $header, 'Set-Cookie' ) ) {
unset( $headers[ $key ] );
}
}
self::debug( 'Response headers', $headers );
$elapsed_time = number_format( ( microtime( true ) - LSCWP_TS_0 ) * 1000, 2 );
self::debug( "End response\n--------------------------------------------------Duration: " . $elapsed_time . " ms------------------------------\n" );
}
/**
* Run beta test upgrade. Accepts a direct ZIP URL or attempts to derive one.
*
* @since 2.9.5
* @access public
*
* @param string|false $zip ZIP URL or false to read from request.
* @return void
*/
public function beta_test( $zip = false ) {
if ( ! $zip ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( empty( $_REQUEST[ self::BETA_TEST_URL ] ) ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$zip = sanitize_text_field( wp_unslash( $_REQUEST[ self::BETA_TEST_URL ] ) );
if ( self::BETA_TEST_URL_WP !== $zip ) {
if ( 'latest' === $zip ) {
$zip = self::BETA_TEST_URL_WP;
} else {
// Generate zip url
$zip = $this->_package_zip( $zip );
}
}
}
if ( ! $zip ) {
self::debug( '[Debug2] ❌ No ZIP file' );
return;
}
self::debug( '[Debug2] ZIP file ' . $zip );
$update_plugins = get_site_transient( 'update_plugins' );
if ( ! is_object( $update_plugins ) ) {
$update_plugins = new \stdClass();
}
$plugin_info = new \stdClass();
$plugin_info->new_version = Core::VER;
$plugin_info->slug = Core::PLUGIN_NAME;
$plugin_info->plugin = Core::PLUGIN_FILE;
$plugin_info->package = $zip;
$plugin_info->url = 'https://wordpress.org/plugins/litespeed-cache/';
$update_plugins->response[ Core::PLUGIN_FILE ] = $plugin_info;
set_site_transient( 'update_plugins', $update_plugins );
Activation::cls()->upgrade();
}
/**
* Resolve a GitHub commit-ish into a downloadable ZIP URL via QC API.
*
* @since 2.9.5
* @access private
*
* @param string $commit Commit hash/branch/tag.
* @return string|false
*/
private function _package_zip( $commit ) {
$data = [
'commit' => $commit,
];
$res = Cloud::get( Cloud::API_BETA_TEST, $data );
if ( empty( $res['zip'] ) ) {
return false;
}
return $res['zip'];
}
/**
* Write purge headers into a dedicated purge log.
*
* @since 2.7
* @access public
*
* @param string $purge_header The Purge header value.
* @return void
*/
public static function log_purge( $purge_header ) {
if ( ! defined( 'LSCWP_LOG' ) && ! defined( 'LSCWP_LOG_BYPASS_NOTADMIN' ) ) {
return;
}
$purge_file = self::cls()->path( 'purge' );
self::cls()->_init_request( $purge_file );
$msg = $purge_header . self::_backtrace_info( 6 );
File::append( $purge_file, self::format_message( $msg ) );
}
/**
* Initialize logging for current request if enabled.
*
* @since 1.1.0
* @access public
* @return void
*/
public function init() {
if ( defined( 'LSCWP_LOG' ) ) {
return;
}
$debug = $this->conf( Base::O_DEBUG );
if ( Base::VAL_ON2 === $debug ) {
if ( ! $this->cls( 'Router' )->is_admin_ip() ) {
defined( 'LSCWP_LOG_BYPASS_NOTADMIN' ) || define( 'LSCWP_LOG_BYPASS_NOTADMIN', true );
return;
}
}
/**
* Check if hit URI includes/excludes
* This is after LSCWP_LOG_BYPASS_NOTADMIN to make `log_purge()` still work
*
* @since 3.0
*/
$list = $this->conf( Base::O_DEBUG_INC );
if ( $list ) {
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$result = Utility::str_hit_array( $request_uri, $list );
if ( ! $result ) {
return;
}
}
$list = $this->conf( Base::O_DEBUG_EXC );
if ( $list ) {
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$result = Utility::str_hit_array( $request_uri, $list );
if ( $result ) {
return;
}
}
if ( ! defined( 'LSCWP_LOG' ) ) {
$this->_init_request();
define( 'LSCWP_LOG', true );
}
}
/**
* Create the initial log record with request context.
*
* @since 1.0.12
* @access private
*
* @param string|null $log_file Optional specific log file path.
* @return void
*/
private function _init_request( $log_file = null ) {
if ( ! $log_file ) {
$log_file = self::$log_path;
}
// Rotate if exceeding configured size (MiB).
$log_file_size = (int) $this->conf( Base::O_DEBUG_FILESIZE );
if ( file_exists( $log_file ) && filesize( $log_file ) > $log_file_size * 1000000 ) {
File::save( $log_file, '' );
}
// Add extra spacing if last write was > 2 seconds ago.
if ( file_exists( $log_file ) && ( time() - filemtime( $log_file ) ) > 2 ) {
File::append( $log_file, "\n\n\n\n" );
}
if ( 'cli' === PHP_SAPI ) {
return;
}
$servervars = array(
'Query String' => '',
'HTTP_ACCEPT' => '',
'HTTP_USER_AGENT' => '',
'HTTP_ACCEPT_ENCODING' => '',
'HTTP_COOKIE' => '',
'REQUEST_METHOD' => '',
'SERVER_PROTOCOL' => '',
'X-LSCACHE' => '',
'LSCACHE_VARY_COOKIE' => '',
'LSCACHE_VARY_VALUE' => '',
'ESI_CONTENT_TYPE' => '',
);
$server = array_merge($servervars, $_SERVER);
$params = array();
if ( isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) {
$server['SERVER_PROTOCOL'] .= ' (HTTPS) ';
}
$param = sprintf('💓 ------%s %s %s', $server['REQUEST_METHOD'], $server['SERVER_PROTOCOL'], strtok($server['REQUEST_URI'], '?'));
$qs = !empty($server['QUERY_STRING']) ? $server['QUERY_STRING'] : '';
if ( $this->conf( Base::O_DEBUG_COLLAPSE_QS ) ) {
$qs = $this->_omit_long_message( $qs );
if ( $qs ) {
$param .= ' ? ' . $qs;
}
$params[] = $param;
} else {
$params[] = $param;
$params[] = 'Query String: ' . $qs;
}
if ( ! empty( $server['HTTP_REFERER'] ) ) {
$params[] = 'HTTP_REFERER: ' . $this->_omit_long_message( $server['HTTP_REFERER'] );
}
if ( defined( 'LSCWP_LOG_MORE' ) ) {
$params[] = 'User Agent: ' . $this->_omit_long_message( $server['HTTP_USER_AGENT'] );
$params[] = 'Accept: ' . $server['HTTP_ACCEPT'];
$params[] = 'Accept Encoding: ' . $server['HTTP_ACCEPT_ENCODING'];
}
if ( isset( $_COOKIE['_lscache_vary'] ) ) {
$params[] = 'Cookie _lscache_vary: ' . sanitize_text_field( wp_unslash( $_COOKIE['_lscache_vary'] ) );
}
if ( defined( 'LSCWP_LOG_MORE' ) ) {
$params[] = 'X-LSCACHE: ' . ( ! empty( $server['X-LSCACHE'] ) ? 'true' : 'false' );
}
if ( $server['LSCACHE_VARY_COOKIE'] ) {
$params[] = 'LSCACHE_VARY_COOKIE: ' . $server['LSCACHE_VARY_COOKIE'];
}
if ( $server['LSCACHE_VARY_VALUE'] ) {
$params[] = 'LSCACHE_VARY_VALUE: ' . $server['LSCACHE_VARY_VALUE'];
}
if ( $server['ESI_CONTENT_TYPE'] ) {
$params[] = 'ESI_CONTENT_TYPE: ' . $server['ESI_CONTENT_TYPE'];
}
$request = array_map( __CLASS__ . '::format_message', $params );
File::append( $log_file, $request );
}
/**
* Trim long message to keep logs compact.
*
* @since 6.3
* @param string $msg Message.
* @return string
*/
private function _omit_long_message( $msg ) {
if ( strlen( $msg ) > 53 ) {
$msg = substr( $msg, 0, 53 ) . '...';
}
return $msg;
}
/**
* Format a single log line with timestamp and prefix.
*
* @since 1.0.12
* @access private
*
* @param string $msg Message to log.
* @return string Formatted line.
*/
private static function format_message( $msg ) {
if ( ! defined( 'LSCWP_LOG_TAG' ) ) {
return $msg . "\n";
}
if ( ! isset( self::$_prefix ) ) {
// address/identity.
if ( 'cli' === PHP_SAPI ) {
$addr = '=CLI=';
if ( isset( $_SERVER['USER'] ) ) {
$addr .= sanitize_text_field( wp_unslash( $_SERVER['USER'] ) );
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$addr .= sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
}
} else {
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
$port = isset( $_SERVER['REMOTE_PORT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_PORT'] ) ) : '';
$addr = "$ip:$port";
}
self::$_prefix = sprintf( ' [%s %s %s] ', $addr, LSCWP_LOG_TAG, Str::rrand( 3 ) );
}
list( $usec, $sec ) = explode( ' ', microtime() );
// Use gmdate to avoid tz-related warnings; apply offset if defined.
$ts = gmdate( 'm/d/y H:i:s', (int) $sec + ( defined( 'LITESPEED_TIME_OFFSET' ) ? (int) LITESPEED_TIME_OFFSET : 0 ) );
return $ts . substr( $usec, 1, 4 ) . self::$_prefix . $msg . "\n";
}
/**
* Log a debug message.
*
* @since 1.1.3
* @access public
*
* @param string $msg Message to write.
* @param int|array $backtrace_limit Depth for backtrace or payload to append.
* @return void
*/
public static function debug( $msg, $backtrace_limit = false ) {
if ( ! defined( 'LSCWP_LOG' ) ) {
return;
}
if ( defined( 'LSCWP_DEBUG_EXC_STRINGS' ) && Utility::str_hit_array( $msg, LSCWP_DEBUG_EXC_STRINGS ) ) {
return;
}
if ( false !== $backtrace_limit ) {
if ( ! is_numeric( $backtrace_limit ) ) {
$backtrace_limit = self::trim_longtext( $backtrace_limit );
if ( is_array( $backtrace_limit ) && 1 === count( $backtrace_limit ) && ! empty( $backtrace_limit[0] ) ) {
$msg .= ' --- ' . $backtrace_limit[0];
} else {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
$msg .= ' --- ' . var_export( $backtrace_limit, true );
}
self::push( $msg );
return;
}
self::push( $msg, (int) $backtrace_limit + 1 );
return;
}
self::push( $msg );
}
/**
* Trim strings inside arrays/object dumps to reasonable length.
*
* @since 3.3
* @param mixed $backtrace_limit Data to trim.
* @return mixed
*/
public static function trim_longtext( $backtrace_limit ) {
if ( is_array( $backtrace_limit ) ) {
$backtrace_limit = array_map( __CLASS__ . '::trim_longtext', $backtrace_limit );
}
if ( is_string( $backtrace_limit ) && strlen( $backtrace_limit ) > 500 ) {
$backtrace_limit = substr( $backtrace_limit, 0, 1000 ) . '...';
}
return $backtrace_limit;
}
/**
* Log a verbose debug message (requires O_DEBUG_LEVEL).
*
* @since 1.2.0
* @access public
*
* @param string $msg Message.
* @param int|array $backtrace_limit Backtrace depth or payload to append.
* @return void
*/
public static function debug2( $msg, $backtrace_limit = false ) {
if ( ! defined( 'LSCWP_LOG_MORE' ) ) {
return;
}
self::debug( $msg, $backtrace_limit );
}
/**
* Append a message to the active log file.
*
* @since 1.1.0
* @access private
*
* @param string $msg Message.
* @param int|bool $backtrace_limit Backtrace depth.
* @return void
*/
private static function push( $msg, $backtrace_limit = false ) {
if ( defined( 'LSCWP_LOG_MORE' ) && false !== $backtrace_limit ) {
$msg .= self::_backtrace_info( (int) $backtrace_limit );
}
File::append( self::$log_path, self::format_message( $msg ) );
}
/**
* Create a compact backtrace string.
*
* @since 2.7
* @access private
*
* @param int $backtrace_limit Depth.
* @return string
*/
private static function _backtrace_info( $backtrace_limit ) {
$msg = '';
$limit = (int) $backtrace_limit;
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
$trace = debug_backtrace( false, $limit + 3 );
for ( $i = 2; $i <= $limit + 2; $i++ ) {
// 0 => _backtrace_info(), 1 => push().
if ( empty( $trace[ $i ]['class'] ) ) {
if ( empty( $trace[ $i ]['file'] ) ) {
break;
}
$log = "\n" . $trace[ $i ]['file'];
} else {
if ( __CLASS__ === $trace[ $i ]['class'] ) {
continue;
}
$args = '';
if ( ! empty( $trace[ $i ]['args'] ) ) {
foreach ( $trace[ $i ]['args'] as $v ) {
if ( is_array( $v ) ) {
$v = 'ARRAY';
}
if ( is_string( $v ) || is_numeric( $v ) ) {
$args .= $v . ',';
}
}
$args = substr( $args, 0, strlen( $args ) > 100 ? 100 : -1 );
}
$log = str_replace( 'Core', 'LSC', $trace[ $i ]['class'] ) . $trace[ $i ]['type'] . $trace[ $i ]['function'] . '(' . $args . ')';
}
if ( ! empty( $trace[ $i - 1 ]['line'] ) ) {
$log .= '@' . $trace[ $i - 1 ]['line'];
}
$msg .= " => $log";
}
return $msg;
}
/**
* Clear all log files (debug|purge|crawler).
*
* @since 1.6.6
* @access private
* @return void
*/
private function _clear_log() {
$logs = [ 'debug', 'purge', 'crawler' ];
foreach ( $logs as $log ) {
File::save( $this->path( $log ), '' );
}
}
/**
* Download a log file.
*
* @since 7.0
* @access private
* @return void
*/
private function _download_log() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verified in Router::verify_type()
$log_type = isset( $_GET['log'] ) ? sanitize_text_field( wp_unslash( $_GET['log'] ) ) : '';
$valid_logs = [ 'debug', 'purge', 'crawler' ];
if ( ! in_array( $log_type, $valid_logs, true ) ) {
wp_die( esc_html__( 'Invalid log type.', 'litespeed-cache' ) );
}
$file = $this->path( $log_type );
if ( ! file_exists( $file ) ) {
wp_die( esc_html__( 'Log file not found.', 'litespeed-cache' ) );
}
$filename = 'litespeed-' . $log_type . '-' . gmdate( 'Y-m-d_His' ) . '.log';
header( 'Content-Type: text/plain; charset=utf-8' );
header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
header( 'Content-Length: ' . filesize( $file ) );
header( 'Cache-Control: no-cache, no-store, must-revalidate' );
header( 'Pragma: no-cache' );
header( 'Expires: 0' );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Direct file output for download
readfile( $file );
exit;
}
/**
* Handle requests routed to this class.
*
* @since 1.6.6
* @access public
* @return void
*/
public function handler() {
$type = Router::verify_type();
switch ( $type ) {
case self::TYPE_CLEAR_LOG:
$this->_clear_log();
break;
case self::TYPE_BETA_TEST:
$this->beta_test();
break;
case self::TYPE_DOWNLOAD_LOG:
$this->_download_log();
return; // _download_log() calls exit, but return here for clarity
default:
break;
}
Admin::redirect();
}
}