litespeed-cache
Last commit date
admin
8 years ago
cli
8 years ago
css
8 years ago
img
8 years ago
inc
8 years ago
includes
8 years ago
js
8 years ago
languages
8 years ago
lib
8 years ago
thirdparty
8 years ago
tpl
8 years ago
litespeed-cache.php
8 years ago
readme.txt
8 years ago
litespeed-cache.php
165 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The plugin bootstrap file |
| 4 | * |
| 5 | * This file is read by WordPress to generate the plugin information in the plugin |
| 6 | * admin area. This file also includes all of the dependencies used by the plugin, |
| 7 | * registers the activation and deactivation functions, and defines a function |
| 8 | * that starts the plugin. |
| 9 | * |
| 10 | * @link https://www.litespeedtech.com |
| 11 | * @since 1.0.0 |
| 12 | * @package LiteSpeed_Cache |
| 13 | * |
| 14 | * @wordpress-plugin |
| 15 | * Plugin Name: LiteSpeed Cache |
| 16 | * Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration |
| 17 | * Description: WordPress plugin to connect to LSCache on LiteSpeed Web Server. |
| 18 | * Version: 1.9.1.1 |
| 19 | * Author: LiteSpeed Technologies |
| 20 | * Author URI: https://www.litespeedtech.com |
| 21 | * License: GPLv3 |
| 22 | * License URI: http://www.gnu.org/licenses/gpl.html |
| 23 | * Text Domain: litespeed-cache |
| 24 | * Domain Path: /languages |
| 25 | * |
| 26 | * Copyright (C) 2015-2017 LiteSpeed Technologies, Inc. |
| 27 | * |
| 28 | * This program is free software: you can redistribute it and/or modify |
| 29 | * it under the terms of the GNU General Public License as published by |
| 30 | * the Free Software Foundation, either version 3 of the License, or |
| 31 | * (at your option) any later version. |
| 32 | * |
| 33 | * This program is distributed in the hope that it will be useful, |
| 34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 36 | * GNU General Public License for more details. |
| 37 | * |
| 38 | * You should have received a copy of the GNU General Public License |
| 39 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 40 | |
| 41 | */ |
| 42 | // If this file is called directly, abort. |
| 43 | if ( ! defined( 'WPINC' ) ) { |
| 44 | die ; |
| 45 | } |
| 46 | |
| 47 | if ( class_exists( 'LiteSpeed_Cache' ) || defined( 'LSCWP_DIR' ) ) { |
| 48 | return ; |
| 49 | } |
| 50 | |
| 51 | ! defined( 'LSCWP_CONTENT_DIR' ) && define( 'LSCWP_CONTENT_DIR', WP_CONTENT_DIR ) ; |
| 52 | ! defined( 'LSCWP_DIR' ) && define( 'LSCWP_DIR', dirname( __FILE__ ) . '/' ) ;// Full absolute path '/usr/local/lsws/***/wp-content/plugins/litespeed-cache/' or MU |
| 53 | ! defined( 'LSCWP_BASENAME' ) && define( 'LSCWP_BASENAME', 'litespeed-cache/litespeed-cache.php' ) ;//LSCWP_BASENAME='litespeed-cache/litespeed-cache.php' |
| 54 | |
| 55 | ! defined( 'LITESPEED_TIME_OFFSET' ) && define( 'LITESPEED_TIME_OFFSET', get_option( 'gmt_offset' ) * 60 * 60 ) ; |
| 56 | |
| 57 | // Placeholder for lazyload img |
| 58 | ! defined( 'LITESPEED_PLACEHOLDER' ) && define( 'LITESPEED_PLACEHOLDER', 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=' ) ; |
| 59 | |
| 60 | // Auto register LiteSpeed classes |
| 61 | require_once LSCWP_DIR . 'inc/litespeed.autoload.php' ; |
| 62 | |
| 63 | // Define CLI |
| 64 | if ( ( defined( 'WP_CLI' ) && WP_CLI ) || PHP_SAPI == 'cli' ) { |
| 65 | ! defined( 'LITESPEED_CLI' ) && define( 'LITESPEED_CLI', true ) ; |
| 66 | |
| 67 | // Register CLI cmd |
| 68 | if ( method_exists( 'WP_CLI', 'add_command' ) ) { |
| 69 | WP_CLI::add_command( 'lscache-admin', 'LiteSpeed_Cache_Cli_Admin' ) ; |
| 70 | WP_CLI::add_command( 'lscache-purge', 'LiteSpeed_Cache_Cli_Purge' ) ; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // Server type |
| 75 | if ( ! defined( 'LITESPEED_SERVER_TYPE' ) ) { |
| 76 | if ( isset( $_SERVER['HTTP_X_LSCACHE'] ) && $_SERVER['HTTP_X_LSCACHE'] ) { |
| 77 | define( 'LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_ADC' ) ; |
| 78 | } |
| 79 | elseif ( isset( $_SERVER['LSWS_EDITION'] ) && strpos( $_SERVER['LSWS_EDITION'], 'Openlitespeed' ) === 0 ) { |
| 80 | define( 'LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_OLS' ) ; |
| 81 | } |
| 82 | elseif ( isset( $_SERVER['SERVER_SOFTWARE'] ) && $_SERVER['SERVER_SOFTWARE'] == 'LiteSpeed' ) { |
| 83 | define( 'LITESPEED_SERVER_TYPE', 'LITESPEED_SERVER_ENT' ) ; |
| 84 | } |
| 85 | else { |
| 86 | define( 'LITESPEED_SERVER_TYPE', 'NONE' ) ; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // Checks if caching is allowed via server variable |
| 91 | if ( ! empty ( $_SERVER['X-LSCACHE'] ) || LITESPEED_SERVER_TYPE === 'LITESPEED_SERVER_ADC' || defined( 'LITESPEED_CLI' ) ) { |
| 92 | ! defined( 'LITESPEED_ALLOWED' ) && define( 'LITESPEED_ALLOWED', true ) ; |
| 93 | } |
| 94 | |
| 95 | // ESI const defination |
| 96 | if ( ! defined( 'LSWCP_ESI_SUPPORT' ) ) { |
| 97 | define( 'LSWCP_ESI_SUPPORT', LITESPEED_SERVER_TYPE !== 'LITESPEED_SERVER_OLS' ? true : false ) ; |
| 98 | } |
| 99 | |
| 100 | if ( ! defined( 'LSWCP_TAG_PREFIX' ) ) { |
| 101 | define( 'LSWCP_TAG_PREFIX', substr( md5( LSCWP_DIR ), -3 ) ) ; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Begins execution of the plugin. |
| 106 | * |
| 107 | * Since everything within the plugin is registered via hooks, |
| 108 | * then kicking off the plugin from this point in the file does |
| 109 | * not affect the page life cycle. |
| 110 | * |
| 111 | * @since 1.0.0 |
| 112 | */ |
| 113 | if ( ! function_exists( 'run_litespeed_cache' ) ) { |
| 114 | function run_litespeed_cache() |
| 115 | { |
| 116 | $version_supported = true ; |
| 117 | |
| 118 | //Check minimum PHP requirements, which is 5.3 at the moment. |
| 119 | if ( version_compare( PHP_VERSION, '5.3.0', '<' ) ) { |
| 120 | error_log( LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_PHP_VER ) ) ; |
| 121 | $version_supported = false ; |
| 122 | } |
| 123 | |
| 124 | //Check minimum WP requirements, which is 4.0 at the moment. |
| 125 | if ( version_compare( $GLOBALS['wp_version'], '4.0', '<' ) ) { |
| 126 | error_log( LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_WP_VER ) ) ; |
| 127 | $version_supported = false ; |
| 128 | } |
| 129 | |
| 130 | if ( $version_supported ) { |
| 131 | LiteSpeed_Cache::get_instance() ; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | run_litespeed_cache() ; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Easier API for Purging a single post. |
| 140 | * |
| 141 | * If a third party plugin needs to purge a single post, it can send |
| 142 | * a purge tag using this function. |
| 143 | * |
| 144 | * @since 1.0.1 |
| 145 | * @access public |
| 146 | * @param integer $id The post id to purge. |
| 147 | */ |
| 148 | if ( ! function_exists( 'litespeed_purge_single_post' ) ) { |
| 149 | function litespeed_purge_single_post( $id ) |
| 150 | { |
| 151 | LiteSpeed_Cache_Purge::purge_post( $id ) ; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Handle exception |
| 157 | */ |
| 158 | if ( ! function_exists( 'litespeed_exception_handler' ) ) { |
| 159 | function litespeed_exception_handler( $errno, $errstr, $errfile, $errline ) |
| 160 | { |
| 161 | throw new ErrorException($errstr, 0, $errno, $errfile, $errline) ; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 |