Skip to content

Commit 1438579

Browse files
author
Hai Zheng
committed
v7.4-b10: * **Misc** Supported LITESPEED_DEV const to switch to dev environment.
1 parent e254713 commit 1438579

4 files changed

Lines changed: 122 additions & 104 deletions

File tree

litespeed-cache.php

Lines changed: 98 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
2-
32
/**
43
* Plugin Name: LiteSpeed Cache
54
* Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
65
* Description: High-performance page caching and site optimization from LiteSpeed
7-
* Version: 7.4-b9
6+
* Version: 7.4-b10
87
* Author: LiteSpeed Technologies
98
* Author URI: https://www.litespeedtech.com
109
* License: GPLv3
1110
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
1211
* Text Domain: litespeed-cache
1312
* Domain Path: /lang
1413
*
14+
* @package LiteSpeed
15+
*
1516
* Copyright (C) 2015-2025 LiteSpeed Technologies, Inc.
1617
*
1718
* This program is free software: you can redistribute it and/or modify
@@ -28,158 +29,182 @@
2829
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2930
*/
3031

31-
defined('WPINC') || exit();
32+
defined( 'WPINC' ) || exit();
3233

33-
if (defined('LSCWP_V')) return;
34+
if ( defined( 'LSCWP_V' ) ) {
35+
return;
36+
}
3437

35-
!defined('LSCWP_V') && define('LSCWP_V', '7.4-b9');
38+
! defined( 'LSCWP_V' ) && define( 'LSCWP_V', '7.4-b10' );
3639

37-
!defined('LSCWP_CONTENT_DIR') && define('LSCWP_CONTENT_DIR', WP_CONTENT_DIR);
38-
!defined('LSCWP_DIR') && define('LSCWP_DIR', __DIR__ . '/'); // Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU
39-
!defined('LSCWP_BASENAME') && define('LSCWP_BASENAME', 'litespeed-cache/litespeed-cache.php'); // LSCWP_BASENAME='litespeed-cache/litespeed-cache.php'
40+
! defined( 'LSCWP_CONTENT_DIR' ) && define( 'LSCWP_CONTENT_DIR', WP_CONTENT_DIR );
41+
! defined( 'LSCWP_DIR' ) && define( 'LSCWP_DIR', __DIR__ . '/' ); // Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU
42+
! defined( 'LSCWP_BASENAME' ) && define( 'LSCWP_BASENAME', 'litespeed-cache/litespeed-cache.php' ); // LSCWP_BASENAME='litespeed-cache/litespeed-cache.php'
4043

4144
/**
4245
* This needs to be before activation because admin-rules.class.php need const `LSCWP_CONTENT_FOLDER`
4346
* This also needs to be before cfg.cls init because default cdn_included_dir needs `LSCWP_CONTENT_FOLDER`
4447
*
4548
* @since 5.2 Auto correct protocol for CONTENT URL
4649
*/
47-
$WP_CONTENT_URL = WP_CONTENT_URL;
48-
$site_url = site_url('/');
49-
if (substr($WP_CONTENT_URL, 0, 5) == 'http:' && substr($site_url, 0, 5) == 'https') {
50-
$WP_CONTENT_URL = str_replace('http://', 'https://', $WP_CONTENT_URL);
50+
$wp_content_url = WP_CONTENT_URL;
51+
$site_url = site_url( '/' );
52+
if ( 'http:' === substr( $wp_content_url, 0, 5 ) && 'https' === substr( $site_url, 0, 5 ) ) {
53+
$wp_content_url = str_replace( 'http://', 'https://', $wp_content_url );
5154
}
52-
!defined('LSCWP_CONTENT_FOLDER') && define('LSCWP_CONTENT_FOLDER', str_replace($site_url, '', $WP_CONTENT_URL)); // `wp-content`
53-
unset($site_url);
54-
!defined('LSWCP_PLUGIN_URL') && define('LSWCP_PLUGIN_URL', plugin_dir_url(__FILE__)); // Full URL path '//example.com/wp-content/plugins/litespeed-cache/'
55+
! defined( 'LSCWP_CONTENT_FOLDER' ) && define( 'LSCWP_CONTENT_FOLDER', str_replace( $site_url, '', $wp_content_url ) ); // `wp-content`
56+
unset( $site_url );
57+
! defined( 'LSWCP_PLUGIN_URL' ) && define( 'LSWCP_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); // Full URL path '//example.com/wp-content/plugins/litespeed-cache/'
5558

5659
/**
5760
* Static cache files consts
5861
*
5962
* @since 3.0
6063
*/
61-
!defined('LITESPEED_DATA_FOLDER') && define('LITESPEED_DATA_FOLDER', 'litespeed');
62-
!defined('LITESPEED_STATIC_URL') && define('LITESPEED_STATIC_URL', $WP_CONTENT_URL . '/' . LITESPEED_DATA_FOLDER); // Full static cache folder URL '//example.com/wp-content/litespeed'
63-
unset($WP_CONTENT_URL);
64-
!defined('LITESPEED_STATIC_DIR') && define('LITESPEED_STATIC_DIR', LSCWP_CONTENT_DIR . '/' . LITESPEED_DATA_FOLDER); // Full static cache folder path '/var/www/html/***/wp-content/litespeed'
64+
! defined( 'LITESPEED_DATA_FOLDER' ) && define( 'LITESPEED_DATA_FOLDER', 'litespeed' );
65+
! defined( 'LITESPEED_STATIC_URL' ) && define( 'LITESPEED_STATIC_URL', $wp_content_url . '/' . LITESPEED_DATA_FOLDER ); // Full static cache folder URL '//example.com/wp-content/litespeed'
66+
unset( $wp_content_url );
67+
! defined( 'LITESPEED_STATIC_DIR' ) && define( 'LITESPEED_STATIC_DIR', LSCWP_CONTENT_DIR . '/' . LITESPEED_DATA_FOLDER ); // Full static cache folder path '/var/www/html/***/wp-content/litespeed'
6568

66-
!defined('LITESPEED_TIME_OFFSET') && define('LITESPEED_TIME_OFFSET', get_option('gmt_offset') * 60 * 60);
69+
! defined( 'LITESPEED_TIME_OFFSET' ) && define( 'LITESPEED_TIME_OFFSET', get_option( 'gmt_offset' ) * 60 * 60 );
6770

6871
// Placeholder for lazyload img
69-
!defined('LITESPEED_PLACEHOLDER') && define('LITESPEED_PLACEHOLDER', 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=');
72+
! defined( 'LITESPEED_PLACEHOLDER' ) && define( 'LITESPEED_PLACEHOLDER', 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=' );
7073

7174
// Auto register LiteSpeed classes
7275
require_once LSCWP_DIR . 'autoload.php';
7376

7477
// Define CLI
75-
if ((defined('WP_CLI') && WP_CLI) || PHP_SAPI == 'cli') {
76-
!defined('LITESPEED_CLI') && define('LITESPEED_CLI', true);
78+
if ( ( defined( 'WP_CLI' ) && WP_CLI ) || 'cli' === PHP_SAPI ) {
79+
! defined( 'LITESPEED_CLI' ) && define( 'LITESPEED_CLI', true );
7780

7881
// Register CLI cmd
79-
if (method_exists('WP_CLI', 'add_command')) {
80-
WP_CLI::add_command('litespeed-option', 'LiteSpeed\CLI\Option');
81-
WP_CLI::add_command('litespeed-purge', 'LiteSpeed\CLI\Purge');
82-
WP_CLI::add_command('litespeed-online', 'LiteSpeed\CLI\Online');
83-
WP_CLI::add_command('litespeed-image', 'LiteSpeed\CLI\Image');
84-
WP_CLI::add_command('litespeed-debug', 'LiteSpeed\CLI\Debug');
85-
WP_CLI::add_command('litespeed-presets', 'LiteSpeed\CLI\Presets');
86-
WP_CLI::add_command('litespeed-crawler', 'LiteSpeed\CLI\Crawler');
87-
WP_CLI::add_command('litespeed-database', 'LiteSpeed\CLI\Database');
82+
if ( method_exists( 'WP_CLI', 'add_command' ) ) {
83+
WP_CLI::add_command( 'litespeed-option', 'LiteSpeed\CLI\Option' );
84+
WP_CLI::add_command( 'litespeed-purge', 'LiteSpeed\CLI\Purge' );
85+
WP_CLI::add_command( 'litespeed-online', 'LiteSpeed\CLI\Online' );
86+
WP_CLI::add_command( 'litespeed-image', 'LiteSpeed\CLI\Image' );
87+
WP_CLI::add_command( 'litespeed-debug', 'LiteSpeed\CLI\Debug' );
88+
WP_CLI::add_command( 'litespeed-presets', 'LiteSpeed\CLI\Presets' );
89+
WP_CLI::add_command( 'litespeed-crawler', 'LiteSpeed\CLI\Crawler' );
90+
WP_CLI::add_command( 'litespeed-database', 'LiteSpeed\CLI\Database' );
8891
}
8992
}
9093

9194
// Server type
92-
if (!defined('LITESPEED_SERVER_TYPE')) {
93-
if (isset($_SERVER['HTTP_X_LSCACHE']) && $_SERVER['HTTP_X_LSCACHE']) {
94-
define('LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_ADC');
95-
} elseif (isset($_SERVER['LSWS_EDITION']) && strpos($_SERVER['LSWS_EDITION'], 'Openlitespeed') === 0) {
96-
define('LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_OLS');
97-
} elseif (isset($_SERVER['SERVER_SOFTWARE']) && $_SERVER['SERVER_SOFTWARE'] == 'LiteSpeed') {
98-
define('LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_ENT');
95+
if ( ! defined( 'LITESPEED_SERVER_TYPE' ) ) {
96+
$http_x_lscache = isset( $_SERVER['HTTP_X_LSCACHE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_LSCACHE'] ) ) : '';
97+
$lsws_edition = isset( $_SERVER['LSWS_EDITION'] ) ? sanitize_text_field( wp_unslash( $_SERVER['LSWS_EDITION'] ) ) : '';
98+
$server_software = isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '';
99+
100+
if ( $http_x_lscache ) {
101+
define( 'LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_ADC' );
102+
} elseif ( 0 === strpos( $lsws_edition, 'Openlitespeed' ) ) {
103+
define( 'LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_OLS' );
104+
} elseif ( 'LiteSpeed' === $server_software ) {
105+
define( 'LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_ENT' );
99106
} else {
100-
define('LITESPEED_SERVER_TYPE', 'NONE');
107+
define( 'LITESPEED_SERVER_TYPE', 'NONE' );
101108
}
102109
}
103110

104111
// Checks if caching is allowed via server variable
105-
if (!empty($_SERVER['X-LSCACHE']) || LITESPEED_SERVER_TYPE === 'LITESPEED_SERVER_ADC' || defined('LITESPEED_CLI')) {
106-
!defined('LITESPEED_ALLOWED') && define('LITESPEED_ALLOWED', true);
112+
if ( ! empty( $_SERVER['X-LSCACHE'] ) || 'LITESPEED_SERVER_ADC' === LITESPEED_SERVER_TYPE || defined( 'LITESPEED_CLI' ) ) {
113+
! defined( 'LITESPEED_ALLOWED' ) && define( 'LITESPEED_ALLOWED', true );
107114
}
108115

109116
// ESI const definition
110-
if (!defined('LSWCP_ESI_SUPPORT')) {
111-
define('LSWCP_ESI_SUPPORT', LITESPEED_SERVER_TYPE !== 'LITESPEED_SERVER_OLS' ? true : false);
117+
if ( ! defined( 'LSWCP_ESI_SUPPORT' ) ) {
118+
define( 'LSWCP_ESI_SUPPORT', LITESPEED_SERVER_TYPE !== 'LITESPEED_SERVER_OLS' );
112119
}
113120

114-
if (!defined('LSWCP_TAG_PREFIX')) {
115-
define('LSWCP_TAG_PREFIX', substr(md5(LSCWP_DIR), -3));
121+
if ( ! defined( 'LSWCP_TAG_PREFIX' ) ) {
122+
define( 'LSWCP_TAG_PREFIX', substr( md5( LSCWP_DIR ), -3 ) );
116123
}
117124

118-
/**
119-
* Handle exception
120-
*/
121-
if (!function_exists('litespeed_exception_handler')) {
125+
if ( ! function_exists( 'litespeed_exception_handler' ) ) {
126+
/**
127+
* Handle exception
128+
*
129+
* @param int $errno Error number.
130+
* @param string $errstr Error string.
131+
* @param string $errfile Error file.
132+
* @param int $errline Error line.
133+
* @throws \ErrorException When an error is encountered.
134+
*/
122135
function litespeed_exception_handler( $errno, $errstr, $errfile, $errline ) {
123-
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
136+
throw new \ErrorException(
137+
esc_html( $errstr ),
138+
0,
139+
absint( $errno ),
140+
esc_html( $errfile ),
141+
absint( $errline )
142+
);
124143
}
125144
}
126145

127-
/**
128-
* Overwrite the WP nonce funcs outside of LiteSpeed namespace
129-
*
130-
* @since 3.0
131-
*/
132-
if (!function_exists('litespeed_define_nonce_func')) {
146+
if ( ! function_exists( 'litespeed_define_nonce_func' ) ) {
147+
/**
148+
* Overwrite the WP nonce funcs outside of LiteSpeed namespace
149+
*
150+
* @since 3.0
151+
*/
133152
function litespeed_define_nonce_func() {
134153
/**
135154
* If the nonce is in none_actions filter, convert it to ESI
155+
*
156+
* @param mixed $action Action name or -1.
157+
* @return string
136158
*/
137159
function wp_create_nonce( $action = -1 ) {
138-
if (!defined('LITESPEED_DISABLE_ALL') || !LITESPEED_DISABLE_ALL) {
139-
$control = \LiteSpeed\ESI::cls()->is_nonce_action($action);
140-
if ($control !== null) {
160+
if ( ! defined( 'LITESPEED_DISABLE_ALL' ) || ! LITESPEED_DISABLE_ALL ) {
161+
$control = \LiteSpeed\ESI::cls()->is_nonce_action( $action );
162+
if ( null !== $control ) {
141163
$params = array(
142164
'action' => $action,
143165
);
144-
return \LiteSpeed\ESI::cls()->sub_esi_block('nonce', 'wp_create_nonce ' . $action, $params, $control, true, true, true);
166+
return \LiteSpeed\ESI::cls()->sub_esi_block( 'nonce', 'wp_create_nonce ' . $action, $params, $control, true, true, true );
145167
}
146168
}
147169

148-
return wp_create_nonce_litespeed_esi($action);
170+
return wp_create_nonce_litespeed_esi( $action );
149171
}
150172

151173
/**
152174
* Ori WP wp_create_nonce
175+
*
176+
* @param mixed $action Action name or -1.
177+
* @return string
153178
*/
154179
function wp_create_nonce_litespeed_esi( $action = -1 ) {
155180
$uid = get_current_user_id();
156-
if (!$uid) {
181+
if ( ! $uid ) {
157182
/** This filter is documented in wp-includes/pluggable.php */
158-
$uid = apply_filters('nonce_user_logged_out', $uid, $action);
183+
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
159184
}
160185

161186
$token = wp_get_session_token();
162187
$i = wp_nonce_tick();
163188

164-
return substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
189+
return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
165190
}
166191
}
167192
}
168193

169-
/**
170-
* Begins execution of the plugin.
171-
*
172-
* @since 1.0.0
173-
*/
174-
if (!function_exists('run_litespeed_cache')) {
194+
if ( ! function_exists( 'run_litespeed_cache' ) ) {
195+
/**
196+
* Begins execution of the plugin.
197+
*
198+
* @since 1.0.0
199+
*/
175200
function run_litespeed_cache() {
176201
// Check minimum PHP requirements, which is 7.2 at the moment.
177-
if (version_compare(PHP_VERSION, '7.2.0', '<')) {
202+
if ( version_compare( PHP_VERSION, '7.2.0', '<' ) ) {
178203
return;
179204
}
180205

181206
// Check minimum WP requirements, which is 5.3 at the moment.
182-
if (version_compare($GLOBALS['wp_version'], '5.3', '<')) {
207+
if ( version_compare( $GLOBALS['wp_version'], '5.3', '<' ) ) {
183208
return;
184209
}
185210

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ You can report security bugs through the Patchstack Vulnerability Disclosure Pro
265265
* **Page Optimize** Dropped v4.2 legacy `LITESPEED_BYPASS_OPTM`.
266266
* **Crawler** Used .html file to test port in case some security plugins blocked .txt which caused port test failure. (#661828)
267267
* **GUI** Showed current live values for options if they are overridden by filters or the server environment. (PR#885)
268+
* **Misc** Supported `LITESPEED_DEV` const to switch to dev environment.
268269
* **Misc** Allows leading `_` for private func/vars in format checker.
269270
* **Misc** Suppressed frequent version check when certain database option is cached.
270271

0 commit comments

Comments
 (0)