Skip to content

Commit dbad247

Browse files
v7.4-b6: Disable all for 24h (#886)
Added functionality for disable all for 24H Added warning in Beta Test that LSC is disabled
1 parent e58389b commit dbad247

6 files changed

Lines changed: 88 additions & 1 deletion

File tree

src/base.cls.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ class Base extends Root {
279279
const O_QC_CNAME = 'qc-cname';
280280

281281
const NETWORK_O_USE_PRIMARY = 'use_primary_settings';
282+
283+
const DEBUG_TMP_DISABLE = 'debug-disable_tmp';
282284

283285
/*** Other consts ***/
284286
const O_GUIDE = 'litespeed-guide'; // Array of each guidance tag as key, step as val //xx todo: may need to remove
@@ -545,6 +547,8 @@ class Base extends Root {
545547

546548
self::O_QC_NAMESERVERS => '',
547549
self::O_QC_CNAME => '',
550+
551+
self::DEBUG_TMP_DISABLE => 0,
548552
);
549553

550554
protected static $_default_site_options = array(

src/core.cls.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public function __construct() {
8080
include_once LSCWP_DIR . 'thirdparty/entry.inc.php';
8181
}
8282

83-
if ( $this->conf( Base::O_DEBUG_DISABLE_ALL ) ) {
83+
84+
if ( $this->conf( Base::O_DEBUG_DISABLE_ALL ) || Debug2::is_temporary_disable() ) {
8485
! defined( 'LITESPEED_DISABLE_ALL' ) && define( 'LITESPEED_DISABLE_ALL', true );
8586
}
8687

src/debug2.cls.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,51 @@ public function __construct() {
4848
defined('LSCWP_DEBUG_EXC_STRINGS') || define('LSCWP_DEBUG_EXC_STRINGS', $this->conf(Base::O_DEBUG_EXC_STRINGS));
4949
}
5050

51+
/**
52+
* Disable all functionalities for a time period.
53+
*
54+
* @since 7.4
55+
* @access public
56+
* @param integer $time How long should we disable LSC functionalities.
57+
*/
58+
public static function temporary_disable( $time = 86400 ) {
59+
$conf = Conf::cls();
60+
$disabled = self::cls()->conf( Base::DEBUG_TMP_DISABLE );
61+
62+
if ( 0 === $disabled ) {
63+
$conf->update_confs( [ Base::DEBUG_TMP_DISABLE => time() + $time ] );
64+
self::debug2( '[Debug] LiteSpeed Cache temporary disabled.' );
65+
66+
return;
67+
}
68+
69+
$conf->update_confs( [ Base::DEBUG_TMP_DISABLE => 0 ] );
70+
self::debug2( '[Debug] LiteSpeed Cache reactivated.' );
71+
}
72+
73+
/**
74+
* Test if Disable All is active. Disable if time is reached.
75+
*
76+
* @since 7.4
77+
* @access public
78+
*/
79+
public static function is_temporary_disable() {
80+
$conf = Conf::cls();
81+
$disabled_time = self::cls()->conf( Base::DEBUG_TMP_DISABLE );
82+
83+
if ( 0 === $disabled_time ) {
84+
return false;
85+
} else {
86+
$time = time();
87+
if( 0 > $time - $disabled_time ){
88+
return true;
89+
} else {
90+
$conf->update_confs( [ Base::DEBUG_TMP_DISABLE => 0 ] );
91+
return false;
92+
}
93+
}
94+
}
95+
5196
/**
5297
* Try moving legacy logs into /litespeed/debug/ folder
5398
*

src/router.cls.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Router extends Base {
4141
const ACTION_DEBUG2 = 'debug2';
4242
const ACTION_CDN_CLOUDFLARE = 'CDN\Cloudflare';
4343
const ACTION_ADMIN_DISPLAY = 'admin_display';
44+
const ACTION_DISABLE_TEMP = 'disable_temp';
4445

4546
// List all handlers here
4647
private static $_HANDLERS = array(
@@ -587,6 +588,11 @@ private function verify_action() {
587588
$_can_option = current_user_can('manage_options');
588589

589590
switch ($action) {
591+
case self::ACTION_DISABLE_TEMP: // disable LSC for 24H
592+
Debug2::temporary_disable();
593+
Admin::redirect("?page=litespeed-toolbox#settings-debug");
594+
return;
595+
590596
case self::ACTION_SAVE_SETTINGS_NETWORK: // Save network settings
591597
if ($_can_network_option) {
592598
self::$_action = $action;

tpl/toolbox/beta_test.tpl.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
<?php Doc::learn_more( 'https://docs.litespeedtech.com/lscache/lscwp/toolbox/#beta-test-tab' ); ?>
3434
</h3>
3535

36+
<?php if ( defined( 'LITESPEED_DISABLE_ALL' ) && LITESPEED_DISABLE_ALL ) : ?>
37+
<div class="litespeed-callout notice notice-warning inline">
38+
<h4><?php esc_html_e( 'NOTICE:', 'litespeed-cache' ); ?></h4>
39+
<p><?php esc_html_e( 'LiteSpeed Cache is disabled. This functionality will not work.', 'litespeed-cache' ); ?></p>
40+
</div>
41+
<?php endif; ?>
42+
3643
<div class="litespeed-desc">
3744
<?php esc_html_e( 'Use this section to switch plugin versions. To beta test a GitHub commit, enter the commit URL in the field below.', 'litespeed-cache' ); ?>
3845
</div>

tpl/toolbox/settings-debug.tpl.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@
2727
<?php esc_html_e( 'View Site Before Cache', 'litespeed-cache' ); ?>
2828
</a>
2929

30+
31+
<?php
32+
$temp_disabled_time = $this->conf( Base::DEBUG_TMP_DISABLE );
33+
$temp_disabled = Debug2::is_temporary_disable();
34+
?>
35+
<a href="<?php echo wp_kses_post( Utility::build_url(Router::ACTION_DISABLE_TEMP, false, false, '_ori') ); ?>" class="button button-success">
36+
<?php
37+
if ( !$temp_disabled ) {
38+
esc_html_e( 'Disable all optimizations for 24H', 'litespeed-cache' );
39+
} else {
40+
esc_html_e( 'Enable LSC now', 'litespeed-cache' );
41+
}
42+
?>
43+
</a>
44+
<?php
45+
if ( $temp_disabled ) :
46+
$date = wp_date( get_option('date_format') . ' ' . get_option( 'time_format' ), $temp_disabled_time );
47+
?>
48+
<div class="litespeed-callout notice notice-warning inline">
49+
<h4><?php esc_html_e( 'NOTICE:', 'litespeed-cache' ); ?></h4>
50+
<p><?php echo wp_kses_post( sprintf ( __( 'LiteSpeed Cache is temporary disabled until: %s.', 'litespeed-cache' ), '<strong>' . $date . '</strong>' ) ); ?></p>
51+
</div>
52+
<?php endif; ?>
53+
3054
<h3 class="litespeed-title-short">
3155
<?php esc_html_e( 'Debug Settings', 'litespeed-cache' ); ?>
3256
<?php Doc::learn_more( 'https://docs.litespeedtech.com/lscache/lscwp/toolbox/#debug-settings-tab' ); ?>

0 commit comments

Comments
 (0)