| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Powered Cache |
| 4 |
* Plugin URI: https://poweredcache.com |
| 5 |
* Description: Comprehensive caching and performance plugin for WordPress. |
| 6 |
* Author: SKOP, Mustafa Uysal |
| 7 |
* Author URI: http://skop.co/ |
| 8 |
* Version: 1.2.1 |
| 9 |
* Text Domain: powered-cache |
| 10 |
* Domain Path: /languages/ |
| 11 |
* License: GPLv2 (or later) |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly. |
| 16 |
} |
| 17 |
|
| 18 |
define( 'POWERED_CACHE_REQUIRED_WP_VERSION', '4.1' ); |
| 19 |
|
| 20 |
|
| 21 |
if ( ! class_exists( 'Powered_Cache' ) ) : |
| 22 |
|
| 23 |
final class Powered_Cache { |
| 24 |
|
| 25 |
/** |
| 26 |
* Stores the single instance of this plugin. |
| 27 |
* @since 1.0 |
| 28 |
*/ |
| 29 |
private static $instance; |
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* A dummy constructor |
| 34 |
* |
| 35 |
* @since 1.0 |
| 36 |
*/ |
| 37 |
protected function __construct() { } |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* Singleton instance of the current class |
| 42 |
* |
| 43 |
* @since 1.0 |
| 44 |
* @return Powered_Cache |
| 45 |
*/ |
| 46 |
public static function instance() { |
| 47 |
if ( ! isset( self::$instance ) ) { |
| 48 |
self::$instance = new Powered_Cache; |
| 49 |
self::$instance->setup_constants(); |
| 50 |
self::$instance->includes(); |
| 51 |
self::$instance->setup_globals(); |
| 52 |
self::$instance->setup(); |
| 53 |
} |
| 54 |
|
| 55 |
return self::$instance; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
/** |
| 60 |
* Setup plugin constants. |
| 61 |
* |
| 62 |
* @since 1.0 |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
private function setup_constants() { |
| 66 |
|
| 67 |
if ( ! defined( 'POWERED_CACHE_PLUGIN_FILE' ) ) { |
| 68 |
define( 'POWERED_CACHE_PLUGIN_FILE', __FILE__ ); |
| 69 |
} |
| 70 |
|
| 71 |
if ( ! defined( 'POWERED_CACHE_PLUGIN_VERSION' ) ) { |
| 72 |
define( 'POWERED_CACHE_PLUGIN_VERSION', '1.2.1' ); |
| 73 |
} |
| 74 |
|
| 75 |
if ( ! defined( 'POWERED_CACHE_PLUGIN_DIR' ) ) { |
| 76 |
define( 'POWERED_CACHE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 77 |
} |
| 78 |
|
| 79 |
if ( ! defined( 'POWERED_CACHE_PREMIUM_DIR' ) ) { |
| 80 |
define( 'POWERED_CACHE_PREMIUM_DIR', POWERED_CACHE_PLUGIN_DIR . 'premium/' ); |
| 81 |
} |
| 82 |
|
| 83 |
if ( ! defined( 'POWERED_CACHE_CACHE_DIR' ) ) { |
| 84 |
define( 'POWERED_CACHE_CACHE_DIR', WP_CONTENT_DIR . '/cache/' ); |
| 85 |
} |
| 86 |
|
| 87 |
if ( ! defined( 'POWERED_CACHE_INC_DIR' ) ) { |
| 88 |
define( 'POWERED_CACHE_INC_DIR', POWERED_CACHE_PLUGIN_DIR . 'includes/' ); |
| 89 |
} |
| 90 |
|
| 91 |
if ( ! defined( 'POWERED_CACHE_DROPIN_DIR' ) ) { |
| 92 |
define( 'POWERED_CACHE_DROPIN_DIR', POWERED_CACHE_INC_DIR . 'dropins/' ); |
| 93 |
} |
| 94 |
|
| 95 |
if ( ! defined( 'POWERED_CACHE_ADMIN_DIR' ) ) { |
| 96 |
define( 'POWERED_CACHE_ADMIN_DIR', POWERED_CACHE_INC_DIR . 'admin/' ); |
| 97 |
} |
| 98 |
|
| 99 |
if ( ! defined( 'POWERED_CACHE_PLUGIN_URL' ) ) { |
| 100 |
define( 'POWERED_CACHE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
/** |
| 106 |
* Include required files |
| 107 |
* |
| 108 |
* @since 1.0 |
| 109 |
*/ |
| 110 |
private function includes() { |
| 111 |
require_once POWERED_CACHE_INC_DIR . 'functions.php'; |
| 112 |
require_once POWERED_CACHE_INC_DIR . 'class-powered-cache-config.php'; |
| 113 |
require_once POWERED_CACHE_INC_DIR . 'class-powered-cache-cdn.php'; |
| 114 |
require_once POWERED_CACHE_INC_DIR . 'class-powered-cache-extensions.php'; |
| 115 |
require_once POWERED_CACHE_INC_DIR . 'class-powered-cache-cron.php'; |
| 116 |
require_once POWERED_CACHE_INC_DIR . 'class-powered-cache-hooks.php'; |
| 117 |
require_once POWERED_CACHE_INC_DIR . 'class-powered-cache-advanced-cache.php'; |
| 118 |
require_once POWERED_CACHE_INC_DIR . 'class-powered-cache-object-cache.php'; |
| 119 |
|
| 120 |
if ( file_exists( POWERED_CACHE_PREMIUM_DIR . 'loader.php' ) ) { |
| 121 |
require_once POWERED_CACHE_PREMIUM_DIR . 'loader.php'; |
| 122 |
} |
| 123 |
|
| 124 |
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
| 125 |
require_once POWERED_CACHE_ADMIN_DIR . 'notices.php'; |
| 126 |
require_once POWERED_CACHE_ADMIN_DIR . 'class-powered-cache-extension-admin-base.php'; |
| 127 |
require_once POWERED_CACHE_ADMIN_DIR . 'class-powered-cache-admin-actions.php'; |
| 128 |
require_once POWERED_CACHE_ADMIN_DIR . 'class-powered-cache-admin-helper.php'; |
| 129 |
require_once POWERED_CACHE_ADMIN_DIR . 'class-powered-cache-admin.php'; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Set up global variables |
| 137 |
* |
| 138 |
* @since 1.0 |
| 139 |
*/ |
| 140 |
private function setup_globals() { |
| 141 |
global $powered_cache_options; |
| 142 |
$powered_cache_options = powered_cache_get_settings(); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
/** |
| 147 |
* Setup plugin functionality |
| 148 |
* @since 1.0 |
| 149 |
*/ |
| 150 |
private function setup() { |
| 151 |
add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) ); |
| 152 |
|
| 153 |
Powered_Cache_Config::factory(); |
| 154 |
|
| 155 |
// load activated extensions |
| 156 |
Powered_Cache_Extensions::factory()->load_extentions(); |
| 157 |
|
| 158 |
// setup cron |
| 159 |
Powered_Cache_Cron::factory(); |
| 160 |
|
| 161 |
// Attached hooks |
| 162 |
Powered_Cache_Hooks::factory(); |
| 163 |
|
| 164 |
// init admin |
| 165 |
if ( is_admin() && class_exists( 'Powered_Cache_Admin' ) ) { |
| 166 |
Powered_Cache_Admin::factory(); |
| 167 |
} |
| 168 |
|
| 169 |
if ( true === powered_cache_get_option( 'enable_page_caching' ) ) { |
| 170 |
Powered_Cache_Advanced_Cache::factory(); |
| 171 |
} |
| 172 |
|
| 173 |
if ( 'off' !== powered_cache_get_option( 'object_cache' ) ) { |
| 174 |
Powered_Cache_Object_Cache::factory(); |
| 175 |
} |
| 176 |
|
| 177 |
// setup CDN |
| 178 |
if ( true === powered_cache_get_option( 'cdn_status' ) ) { |
| 179 |
if ( ! is_ssl() || ( is_ssl() && false === powered_cache_get_option( 'cdn_ssl_disable' ) ) ) { |
| 180 |
Powered_Cache_CDN::factory(); |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
/** |
| 188 |
* Loads the language packs |
| 189 |
* |
| 190 |
* @access public |
| 191 |
* @since 1.0 |
| 192 |
* @return void |
| 193 |
*/ |
| 194 |
public function load_textdomain() { |
| 195 |
$powered_lang_dir = dirname( plugin_basename( POWERED_CACHE_PLUGIN_FILE ) ) . '/languages/'; |
| 196 |
$powered_lang_dir = apply_filters( 'powered_cache_lang_dir', $powered_lang_dir ); |
| 197 |
load_plugin_textdomain( 'powered-cache', false, $powered_lang_dir ); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
/** |
| 202 |
* We don't want the object to be cloned. |
| 203 |
* |
| 204 |
* @since 1.0 |
| 205 |
*/ |
| 206 |
public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'powered-cache' ), '1.0' ); } |
| 207 |
|
| 208 |
|
| 209 |
/** |
| 210 |
* Disable unserializing |
| 211 |
* |
| 212 |
* @since 1.0 |
| 213 |
*/ |
| 214 |
public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'powered-cache' ), '1.0' ); } |
| 215 |
|
| 216 |
|
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
endif; |
| 221 |
|
| 222 |
|
| 223 |
register_deactivation_hook( __FILE__, 'powered_cache_deactivation' ); |
| 224 |
|
| 225 |
function powered_cache_deactivation() { |
| 226 |
global $powered_cache_fs; |
| 227 |
|
| 228 |
powered_cache_flush(); |
| 229 |
if ( ! is_multisite() ) { |
| 230 |
Powered_Cache_Config::factory()->define_wp_cache( false ); |
| 231 |
Powered_Cache_Config::factory()->configure_htaccess( false ); |
| 232 |
|
| 233 |
|
| 234 |
// delete object cache file |
| 235 |
if ( file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php' ) ) { |
| 236 |
$powered_cache_fs->delete( untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php' ); |
| 237 |
} |
| 238 |
|
| 239 |
// delete advanced cache file |
| 240 |
if ( file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' ) ) { |
| 241 |
$powered_cache_fs->delete( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' ); |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
delete_option( 'powered_cache_preload_runtime_option' ); |
| 246 |
|
| 247 |
|
| 248 |
// remove cron tasks |
| 249 |
wp_clear_scheduled_hook( 'powered_cache_preload_hook' ); |
| 250 |
wp_clear_scheduled_hook( 'powered_cache_preload_child_process' ); |
| 251 |
wp_clear_scheduled_hook( 'powered_cache_purge_cache' ); |
| 252 |
} |
| 253 |
|
| 254 |
/** |
| 255 |
* The main function for that returns Powered_Cache |
| 256 |
* |
| 257 |
* @since 1.0 |
| 258 |
* @return Powered_Cache |
| 259 |
*/ |
| 260 |
function powered_cache() { |
| 261 |
return Powered_Cache::instance(); |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
/** |
| 266 |
* Check requirement |
| 267 |
*/ |
| 268 |
function powered_cache_requirements_notice() { |
| 269 |
if ( ! current_user_can( 'update_core' ) ) { |
| 270 |
return; |
| 271 |
} |
| 272 |
?> |
| 273 |
|
| 274 |
<div id="message" class="error notice"> |
| 275 |
<p><strong><?php esc_html_e( 'Your site does not support Powered Cache.', 'powered-cache' ); ?></strong></p> |
| 276 |
|
| 277 |
<p><?php printf( esc_html__( 'Your site is currently running WordPress version %1$s, while Powered Cache requires version %2$s or greater.', 'powered-cache' ), esc_html( get_bloginfo( 'version' ) ), POWERED_CACHE_REQUIRED_WP_VERSION ); ?></p> |
| 278 |
|
| 279 |
<p><?php esc_html_e( 'Please update your WordPress or deactivate Powered Cache.', 'powered-cache' ); ?></p> |
| 280 |
</div> |
| 281 |
|
| 282 |
<?php |
| 283 |
} |
| 284 |
|
| 285 |
if ( version_compare( get_bloginfo( 'version' ), POWERED_CACHE_REQUIRED_WP_VERSION, '<' ) ) { |
| 286 |
add_action( 'admin_notices', 'powered_cache_requirements_notice' ); |
| 287 |
add_action( 'network_admin_notices', 'powered_cache_requirements_notice' ); |
| 288 |
|
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
// run |
| 293 |
powered_cache(); |