litespeed-cache
Last commit date
assets
1 year ago
cli
1 year ago
data
1 year ago
lang
1 year ago
lib
1 year ago
src
1 year ago
thirdparty
1 year ago
tpl
1 year ago
LICENSE
1 year ago
autoload.php
1 year ago
changelog.txt
1 year ago
composer.json
1 year ago
composer.lock
1 year ago
guest.vary.php
1 year ago
litespeed-cache.php
1 year ago
package-lock.json
1 year ago
package.json
1 year ago
phpcs.xml.dist
1 year ago
qc-ping.txt
1 year ago
readme.txt
1 year ago
security.md
1 year ago
litespeed-cache.php
192 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Plugin Name: LiteSpeed Cache |
| 5 | * Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration |
| 6 | * Description: High-performance page caching and site optimization from LiteSpeed |
| 7 | * Version: 7.0.1 |
| 8 | * Author: LiteSpeed Technologies |
| 9 | * Author URI: https://www.litespeedtech.com |
| 10 | * License: GPLv3 |
| 11 | * License URI: http://www.gnu.org/licenses/gpl.html |
| 12 | * Text Domain: litespeed-cache |
| 13 | * Domain Path: /lang |
| 14 | * |
| 15 | * Copyright (C) 2015-2025 LiteSpeed Technologies, Inc. |
| 16 | * |
| 17 | * This program is free software: you can redistribute it and/or modify |
| 18 | * it under the terms of the GNU General Public License as published by |
| 19 | * the Free Software Foundation, either version 3 of the License, or |
| 20 | * (at your option) any later version. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 29 | |
| 30 | */ |
| 31 | defined('WPINC') || exit(); |
| 32 | |
| 33 | if (defined('LSCWP_V')) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | !defined('LSCWP_V') && define('LSCWP_V', '7.0.1'); |
| 38 | |
| 39 | !defined('LSCWP_CONTENT_DIR') && define('LSCWP_CONTENT_DIR', WP_CONTENT_DIR); |
| 40 | !defined('LSCWP_DIR') && define('LSCWP_DIR', __DIR__ . '/'); // Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU |
| 41 | !defined('LSCWP_BASENAME') && define('LSCWP_BASENAME', 'litespeed-cache/litespeed-cache.php'); //LSCWP_BASENAME='litespeed-cache/litespeed-cache.php' |
| 42 | |
| 43 | /** |
| 44 | * This needs to be before activation because admin-rules.class.php need const `LSCWP_CONTENT_FOLDER` |
| 45 | * This also needs to be before cfg.cls init because default cdn_included_dir needs `LSCWP_CONTENT_FOLDER` |
| 46 | * @since 5.2 Auto correct protocol for CONTENT URL |
| 47 | */ |
| 48 | $WP_CONTENT_URL = WP_CONTENT_URL; |
| 49 | $site_url = site_url('/'); |
| 50 | if (substr($WP_CONTENT_URL, 0, 5) == 'http:' && substr($site_url, 0, 5) == 'https') { |
| 51 | $WP_CONTENT_URL = str_replace('http://', 'https://', $WP_CONTENT_URL); |
| 52 | } |
| 53 | !defined('LSCWP_CONTENT_FOLDER') && define('LSCWP_CONTENT_FOLDER', str_replace($site_url, '', $WP_CONTENT_URL)); // `wp-content` |
| 54 | !defined('LSWCP_PLUGIN_URL') && define('LSWCP_PLUGIN_URL', plugin_dir_url(__FILE__)); // Full URL path '//example.com/wp-content/plugins/litespeed-cache/' |
| 55 | |
| 56 | /** |
| 57 | * Static cache files consts |
| 58 | * @since 3.0 |
| 59 | */ |
| 60 | !defined('LITESPEED_DATA_FOLDER') && define('LITESPEED_DATA_FOLDER', 'litespeed'); |
| 61 | !defined('LITESPEED_STATIC_URL') && define('LITESPEED_STATIC_URL', $WP_CONTENT_URL . '/' . LITESPEED_DATA_FOLDER); // Full static cache folder URL '//example.com/wp-content/litespeed' |
| 62 | !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' |
| 63 | |
| 64 | !defined('LITESPEED_TIME_OFFSET') && define('LITESPEED_TIME_OFFSET', get_option('gmt_offset') * 60 * 60); |
| 65 | |
| 66 | // Placeholder for lazyload img |
| 67 | !defined('LITESPEED_PLACEHOLDER') && define('LITESPEED_PLACEHOLDER', 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs='); |
| 68 | |
| 69 | // Auto register LiteSpeed classes |
| 70 | require_once LSCWP_DIR . 'autoload.php'; |
| 71 | |
| 72 | // Define CLI |
| 73 | if ((defined('WP_CLI') && WP_CLI) || PHP_SAPI == 'cli') { |
| 74 | !defined('LITESPEED_CLI') && define('LITESPEED_CLI', true); |
| 75 | |
| 76 | // Register CLI cmd |
| 77 | if (method_exists('WP_CLI', 'add_command')) { |
| 78 | WP_CLI::add_command('litespeed-option', 'LiteSpeed\CLI\Option'); |
| 79 | WP_CLI::add_command('litespeed-purge', 'LiteSpeed\CLI\Purge'); |
| 80 | WP_CLI::add_command('litespeed-online', 'LiteSpeed\CLI\Online'); |
| 81 | WP_CLI::add_command('litespeed-image', 'LiteSpeed\CLI\Image'); |
| 82 | WP_CLI::add_command('litespeed-debug', 'LiteSpeed\CLI\Debug'); |
| 83 | WP_CLI::add_command('litespeed-presets', 'LiteSpeed\CLI\Presets'); |
| 84 | WP_CLI::add_command('litespeed-crawler', 'LiteSpeed\CLI\Crawler'); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // Server type |
| 89 | if (!defined('LITESPEED_SERVER_TYPE')) { |
| 90 | if (isset($_SERVER['HTTP_X_LSCACHE']) && $_SERVER['HTTP_X_LSCACHE']) { |
| 91 | define('LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_ADC'); |
| 92 | } elseif (isset($_SERVER['LSWS_EDITION']) && strpos($_SERVER['LSWS_EDITION'], 'Openlitespeed') === 0) { |
| 93 | define('LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_OLS'); |
| 94 | } elseif (isset($_SERVER['SERVER_SOFTWARE']) && $_SERVER['SERVER_SOFTWARE'] == 'LiteSpeed') { |
| 95 | define('LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_ENT'); |
| 96 | } else { |
| 97 | define('LITESPEED_SERVER_TYPE', 'NONE'); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // Checks if caching is allowed via server variable |
| 102 | if (!empty($_SERVER['X-LSCACHE']) || LITESPEED_SERVER_TYPE === 'LITESPEED_SERVER_ADC' || defined('LITESPEED_CLI')) { |
| 103 | !defined('LITESPEED_ALLOWED') && define('LITESPEED_ALLOWED', true); |
| 104 | } |
| 105 | |
| 106 | // ESI const definition |
| 107 | if (!defined('LSWCP_ESI_SUPPORT')) { |
| 108 | define('LSWCP_ESI_SUPPORT', LITESPEED_SERVER_TYPE !== 'LITESPEED_SERVER_OLS' ? true : false); |
| 109 | } |
| 110 | |
| 111 | if (!defined('LSWCP_TAG_PREFIX')) { |
| 112 | define('LSWCP_TAG_PREFIX', substr(md5(LSCWP_DIR), -3)); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Handle exception |
| 117 | */ |
| 118 | if (!function_exists('litespeed_exception_handler')) { |
| 119 | function litespeed_exception_handler($errno, $errstr, $errfile, $errline) |
| 120 | { |
| 121 | throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Overwrite the WP nonce funcs outside of LiteSpeed namespace |
| 127 | * @since 3.0 |
| 128 | */ |
| 129 | if (!function_exists('litespeed_define_nonce_func')) { |
| 130 | function litespeed_define_nonce_func() |
| 131 | { |
| 132 | /** |
| 133 | * If the nonce is in none_actions filter, convert it to ESI |
| 134 | */ |
| 135 | function wp_create_nonce($action = -1) |
| 136 | { |
| 137 | if (!defined('LITESPEED_DISABLE_ALL') || !LITESPEED_DISABLE_ALL) { |
| 138 | $control = \LiteSpeed\ESI::cls()->is_nonce_action($action); |
| 139 | if ($control !== null) { |
| 140 | $params = array( |
| 141 | 'action' => $action, |
| 142 | ); |
| 143 | return \LiteSpeed\ESI::cls()->sub_esi_block('nonce', 'wp_create_nonce ' . $action, $params, $control, true, true, true); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return wp_create_nonce_litespeed_esi($action); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Ori WP wp_create_nonce |
| 152 | */ |
| 153 | function wp_create_nonce_litespeed_esi($action = -1) |
| 154 | { |
| 155 | $uid = get_current_user_id(); |
| 156 | if (!$uid) { |
| 157 | /** This filter is documented in wp-includes/pluggable.php */ |
| 158 | $uid = apply_filters('nonce_user_logged_out', $uid, $action); |
| 159 | } |
| 160 | |
| 161 | $token = wp_get_session_token(); |
| 162 | $i = wp_nonce_tick(); |
| 163 | |
| 164 | return substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Begins execution of the plugin. |
| 171 | * |
| 172 | * @since 1.0.0 |
| 173 | */ |
| 174 | if (!function_exists('run_litespeed_cache')) { |
| 175 | function run_litespeed_cache() |
| 176 | { |
| 177 | //Check minimum PHP requirements, which is 7.2 at the moment. |
| 178 | if (version_compare(PHP_VERSION, '7.2.0', '<')) { |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | //Check minimum WP requirements, which is 5.3 at the moment. |
| 183 | if (version_compare($GLOBALS['wp_version'], '5.3', '<')) { |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | \LiteSpeed\Core::cls(); |
| 188 | } |
| 189 | |
| 190 | run_litespeed_cache(); |
| 191 | } |
| 192 |