PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / 1.0.1
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score v1.0.1
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
powered-cache / powered-cache.php

powered-cache.php in Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score 1.0.1, at powered-cache.php

289 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.0.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.0' );
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-advanced-cache.php';
117 require_once POWERED_CACHE_INC_DIR . 'class-powered-cache-object-cache.php';
118
119 if ( file_exists( POWERED_CACHE_PREMIUM_DIR . 'loader.php' ) ) {
120 require_once POWERED_CACHE_PREMIUM_DIR . 'loader.php';
121 }
122
123 if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
124 require_once POWERED_CACHE_ADMIN_DIR . 'notices.php';
125 require_once POWERED_CACHE_ADMIN_DIR . 'class-powered-cache-extension-admin-base.php';
126 require_once POWERED_CACHE_ADMIN_DIR . 'class-powered-cache-admin-actions.php';
127 require_once POWERED_CACHE_ADMIN_DIR . 'class-powered-cache-admin-helper.php';
128 require_once POWERED_CACHE_ADMIN_DIR . 'class-powered-cache-admin.php';
129 }
130
131
132 }
133
134 /**
135 * Set up global variables
136 *
137 * @since 1.0
138 */
139 private function setup_globals() {
140 global $powered_cache_options;
141 $powered_cache_options = powered_cache_get_settings();
142 }
143
144
145 /**
146 * Setup plugin functionality
147 * @since 1.0
148 */
149 private function setup() {
150 add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
151
152 Powered_Cache_Config::factory();
153
154 // load activated extensions
155 Powered_Cache_Extensions::factory()->load_extentions();
156
157 // setup cron
158 Powered_Cache_Cron::factory();
159
160 // init admin
161 if ( is_admin() && class_exists( 'Powered_Cache_Admin' ) ) {
162 Powered_Cache_Admin::factory();
163 }
164
165 if ( true === powered_cache_get_option( 'enable_page_caching' ) ) {
166 Powered_Cache_Advanced_Cache::factory();
167 }
168
169 if ( 'off' !== powered_cache_get_option( 'object_cache' ) ) {
170 Powered_Cache_Object_Cache::factory();
171 }
172
173 // setup CDN
174 if ( true === powered_cache_get_option( 'cdn_status' ) ) {
175 if ( ! is_ssl() || ( is_ssl() && false === powered_cache_get_option( 'cdn_ssl_disable' ) ) ) {
176 Powered_Cache_CDN::factory();
177 }
178 }
179
180 }
181
182
183 /**
184 * Loads the language packs
185 *
186 * @access public
187 * @since 1.0
188 * @return void
189 */
190 public function load_textdomain() {
191 $powered_lang_dir = dirname( plugin_basename( POWERED_CACHE_PLUGIN_FILE ) ) . '/languages/';
192 $powered_lang_dir = apply_filters( 'powered_cache_lang_dir', $powered_lang_dir );
193 load_plugin_textdomain( 'powered-cache', false, $powered_lang_dir );
194 }
195
196
197 /**
198 * We don't want the object to be cloned.
199 *
200 * @since 1.0
201 */
202 public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'powered-cache' ), '1.0' ); }
203
204
205 /**
206 * Disable unserializing
207 *
208 * @since 1.0
209 */
210 public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'powered-cache' ), '1.0' ); }
211
212
213 }
214
215
216 endif;
217
218
219 register_deactivation_hook( __FILE__, 'powered_cache_deactivation' );
220
221 function powered_cache_deactivation() {
222 global $wp_filesystem;
223
224 powered_cache_flush();
225 if ( ! is_multisite() ) {
226 Powered_Cache_Config::factory()->define_wp_cache( false );
227 Powered_Cache_Config::factory()->configure_htaccess( false );
228
229
230 // delete object cache file
231 if ( file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php' ) ) {
232 $wp_filesystem->delete( untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php' );
233 }
234
235 // delete advanced cache file
236 if ( file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' ) ) {
237 $wp_filesystem->delete( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' );
238 }
239 }
240
241 delete_option( 'powered_cache_preload_runtime_option' );
242
243
244 // remove cron tasks
245 wp_clear_scheduled_hook( 'powered_cache_preload_hook' );
246 wp_clear_scheduled_hook( 'powered_cache_preload_child_process' );
247 wp_clear_scheduled_hook( 'powered_cache_purge_cache' );
248 }
249
250 /**
251 * The main function for that returns Powered_Cache
252 *
253 * @since 1.0
254 * @return Powered_Cache
255 */
256 function powered_cache() {
257 return Powered_Cache::instance();
258 }
259
260
261 /**
262 * Check requirement
263 */
264 function powered_cache_requirements_notice() {
265 if ( ! current_user_can( 'update_core' ) ) {
266 return;
267 }
268 ?>
269
270 <div id="message" class="error notice">
271 <p><strong><?php esc_html_e( 'Your site does not support Powered Cache.', 'powered-cache' ); ?></strong></p>
272
273 <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>
274
275 <p><?php esc_html_e( 'Please update your WordPress or deactivate Powered Cache.', 'powered-cache' ); ?></p>
276 </div>
277
278 <?php
279 }
280
281 if ( version_compare( get_bloginfo( 'version' ), POWERED_CACHE_REQUIRED_WP_VERSION, '<' ) ) {
282 add_action( 'admin_notices', 'powered_cache_requirements_notice' );
283 add_action( 'network_admin_notices', 'powered_cache_requirements_notice' );
284
285 return;
286 }
287
288 // run
289 powered_cache();