|
1 | 1 | <?php |
2 | | - |
3 | 2 | /** |
4 | 3 | * Plugin Name: LiteSpeed Cache |
5 | 4 | * Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration |
6 | 5 | * Description: High-performance page caching and site optimization from LiteSpeed |
7 | | - * Version: 7.4-b9 |
| 6 | + * Version: 7.4-b10 |
8 | 7 | * Author: LiteSpeed Technologies |
9 | 8 | * Author URI: https://www.litespeedtech.com |
10 | 9 | * License: GPLv3 |
11 | 10 | * License URI: https://www.gnu.org/licenses/gpl-3.0.html |
12 | 11 | * Text Domain: litespeed-cache |
13 | 12 | * Domain Path: /lang |
14 | 13 | * |
| 14 | + * @package LiteSpeed |
| 15 | + * |
15 | 16 | * Copyright (C) 2015-2025 LiteSpeed Technologies, Inc. |
16 | 17 | * |
17 | 18 | * This program is free software: you can redistribute it and/or modify |
|
28 | 29 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
29 | 30 | */ |
30 | 31 |
|
31 | | -defined('WPINC') || exit(); |
| 32 | +defined( 'WPINC' ) || exit(); |
32 | 33 |
|
33 | | -if (defined('LSCWP_V')) return; |
| 34 | +if ( defined( 'LSCWP_V' ) ) { |
| 35 | + return; |
| 36 | +} |
34 | 37 |
|
35 | | -!defined('LSCWP_V') && define('LSCWP_V', '7.4-b9'); |
| 38 | +! defined( 'LSCWP_V' ) && define( 'LSCWP_V', '7.4-b10' ); |
36 | 39 |
|
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' |
40 | 43 |
|
41 | 44 | /** |
42 | 45 | * This needs to be before activation because admin-rules.class.php need const `LSCWP_CONTENT_FOLDER` |
43 | 46 | * This also needs to be before cfg.cls init because default cdn_included_dir needs `LSCWP_CONTENT_FOLDER` |
44 | 47 | * |
45 | 48 | * @since 5.2 Auto correct protocol for CONTENT URL |
46 | 49 | */ |
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 ); |
51 | 54 | } |
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/' |
55 | 58 |
|
56 | 59 | /** |
57 | 60 | * Static cache files consts |
58 | 61 | * |
59 | 62 | * @since 3.0 |
60 | 63 | */ |
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' |
65 | 68 |
|
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 ); |
67 | 70 |
|
68 | 71 | // 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=' ); |
70 | 73 |
|
71 | 74 | // Auto register LiteSpeed classes |
72 | 75 | require_once LSCWP_DIR . 'autoload.php'; |
73 | 76 |
|
74 | 77 | // 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 ); |
77 | 80 |
|
78 | 81 | // 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' ); |
88 | 91 | } |
89 | 92 | } |
90 | 93 |
|
91 | 94 | // 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' ); |
99 | 106 | } else { |
100 | | - define('LITESPEED_SERVER_TYPE', 'NONE'); |
| 107 | + define( 'LITESPEED_SERVER_TYPE', 'NONE' ); |
101 | 108 | } |
102 | 109 | } |
103 | 110 |
|
104 | 111 | // 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 ); |
107 | 114 | } |
108 | 115 |
|
109 | 116 | // 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' ); |
112 | 119 | } |
113 | 120 |
|
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 ) ); |
116 | 123 | } |
117 | 124 |
|
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 | + */ |
122 | 135 | 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 | + ); |
124 | 143 | } |
125 | 144 | } |
126 | 145 |
|
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 | + */ |
133 | 152 | function litespeed_define_nonce_func() { |
134 | 153 | /** |
135 | 154 | * If the nonce is in none_actions filter, convert it to ESI |
| 155 | + * |
| 156 | + * @param mixed $action Action name or -1. |
| 157 | + * @return string |
136 | 158 | */ |
137 | 159 | 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 ) { |
141 | 163 | $params = array( |
142 | 164 | 'action' => $action, |
143 | 165 | ); |
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 ); |
145 | 167 | } |
146 | 168 | } |
147 | 169 |
|
148 | | - return wp_create_nonce_litespeed_esi($action); |
| 170 | + return wp_create_nonce_litespeed_esi( $action ); |
149 | 171 | } |
150 | 172 |
|
151 | 173 | /** |
152 | 174 | * Ori WP wp_create_nonce |
| 175 | + * |
| 176 | + * @param mixed $action Action name or -1. |
| 177 | + * @return string |
153 | 178 | */ |
154 | 179 | function wp_create_nonce_litespeed_esi( $action = -1 ) { |
155 | 180 | $uid = get_current_user_id(); |
156 | | - if (!$uid) { |
| 181 | + if ( ! $uid ) { |
157 | 182 | /** 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 ); |
159 | 184 | } |
160 | 185 |
|
161 | 186 | $token = wp_get_session_token(); |
162 | 187 | $i = wp_nonce_tick(); |
163 | 188 |
|
164 | | - return substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10); |
| 189 | + return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); |
165 | 190 | } |
166 | 191 | } |
167 | 192 | } |
168 | 193 |
|
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 | + */ |
175 | 200 | function run_litespeed_cache() { |
176 | 201 | // 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', '<' ) ) { |
178 | 203 | return; |
179 | 204 | } |
180 | 205 |
|
181 | 206 | // 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', '<' ) ) { |
183 | 208 | return; |
184 | 209 | } |
185 | 210 |
|
|
0 commit comments