PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / trunk
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score vtrunk
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
← All changes | powered-cache.php +103 -258 1.1trunk View file →
@@ -1,293 +1,138 @@
1 1 <?php
2 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.1
9 - * Text Domain: powered-cache
10 - * Domain Path: /languages/
11 - * License: GPLv2 (or later)
3 + * Plugin Name: Powered Cache
4 + * Plugin URI: https://poweredcache.com
5 + * Description: Powered Cache is the most powerful caching and performance suite for WordPress, designed to easily improve your PageSpeed and Web Vitals Score.
6 + * Version: 3.7.3
7 + * Requires at least: 5.7
8 + * Requires PHP: 7.4
9 + * Author: Powered Cache
10 + * Author URI: https://poweredcache.com
11 + * License: GPL v2 or later
12 + * License URI: https://www.gnu.org/licenses/gpl-2.0.html
13 + * Text Domain: powered-cache
14 + * Domain Path: /languages
15 + *
16 + * @package PoweredCache
12 17 */
13 18
19 +namespace PoweredCache;
20 +
21 +use PoweredCache\Extensions\Extensions;
22 +
14 23 if ( ! defined( 'ABSPATH' ) ) {
15 24 exit; // Exit if accessed directly.
16 25 }
17 26
18 -define( 'POWERED_CACHE_REQUIRED_WP_VERSION', '4.1' );
27 +// Useful global constants.
28 +define( 'POWERED_CACHE_VERSION', '3.7.3' );
29 +define( 'POWERED_CACHE_DB_VERSION', '3.4' );
30 +define( 'POWERED_CACHE_PLUGIN_FILE', __FILE__ );
31 +define( 'POWERED_CACHE_URL', plugin_dir_url( __FILE__ ) );
32 +define( 'POWERED_CACHE_PATH', plugin_dir_path( __FILE__ ) );
33 +define( 'POWERED_CACHE_INC', POWERED_CACHE_PATH . 'includes/' );
34 +define( 'POWERED_CACHE_DROPIN_DIR', POWERED_CACHE_INC . 'dropins/' );
35 +define( 'POWERED_CACHE_COMPAT_DIR', POWERED_CACHE_INC . 'compat/' );
36 +define( 'POWERED_CACHE_PACKAGE_DIR', POWERED_CACHE_INC . 'package/' );
19 37
38 +if ( ! defined( 'POWERED_CACHE_CACHE_DIR' ) ) {
39 + define( 'POWERED_CACHE_CACHE_DIR', WP_CONTENT_DIR . '/cache/' );
40 +}
20 41
21 -if ( ! class_exists( 'Powered_Cache' ) ) :
42 +if ( ! defined( 'POWERED_CACHE_FO_CACHE_DIR' ) ) {
43 + define( 'POWERED_CACHE_FO_CACHE_DIR', POWERED_CACHE_CACHE_DIR . 'min/' );
44 +}
22 45
23 - final class Powered_Cache {
46 +// Require Composer autoloader if it exists.
47 +if ( file_exists( POWERED_CACHE_PATH . 'vendor/autoload.php' ) ) {
48 + require_once POWERED_CACHE_PATH . 'vendor/autoload.php';
49 +}
24 50
25 - /**
26 - * Stores the single instance of this plugin.
27 - * @since 1.0
28 - */
29 - private static $instance;
51 +// load packages
52 +require_once POWERED_CACHE_PACKAGE_DIR . 'deliciousbrains/wp-background-processing/classes/wp-async-request.php';
53 +require_once POWERED_CACHE_PACKAGE_DIR . 'deliciousbrains/wp-background-processing/classes/wp-background-process.php';
30 54
55 +/**
56 + * PSR-4-ish autoloading
57 + *
58 + * @since 2.0
59 + */
60 +spl_autoload_register(
61 + function ( $class ) {
62 + // project-specific namespace prefix.
63 + $prefix = 'PoweredCache\\';
31 64
32 - /**
33 - * A dummy constructor
34 - *
35 - * @since 1.0
36 - */
37 - protected function __construct() { }
65 + // base directory for the namespace prefix.
66 + $base_dir = __DIR__ . '/includes/classes/';
38 67
68 + // does the class use the namespace prefix?
69 + $len = strlen( $prefix );
39 70
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;
71 + if ( strncmp( $prefix, $class, $len ) !== 0 ) {
72 + return;
56 73 }
57 74
75 + $relative_class = substr( $class, $len );
58 76
59 - /**
60 - * Setup plugin constants.
61 - *
62 - * @since 1.0
63 - * @return void
64 - */
65 - private function setup_constants() {
77 + $file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
66 78
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.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 - }
79 + // if the file exists, require it.
80 + if ( file_exists( $file ) ) {
81 + require $file;
102 82 }
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&#8217; 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&#8217; huh?', 'powered-cache' ), '1.0' ); }
215 -
216 -
217 83 }
84 +);
218 85
86 +// Include files.
87 +require_once POWERED_CACHE_INC . 'constants.php';
88 +require_once POWERED_CACHE_INC . 'utils.php';
89 +require_once POWERED_CACHE_INC . 'core.php';
90 +require_once POWERED_CACHE_INC . 'admin/dashboard.php';
91 +require_once POWERED_CACHE_INC . 'admin/notices.php';
92 +require_once POWERED_CACHE_COMPAT_DIR . 'loader.php';
219 93
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' );
94 +$network_activated = Utils\is_network_wide( POWERED_CACHE_PLUGIN_FILE );
95 +if ( ! defined( 'POWERED_CACHE_IS_NETWORK' ) ) {
96 + define( 'POWERED_CACHE_IS_NETWORK', $network_activated );
252 97 }
253 98
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 -}
99 +if ( Utils\is_dev_mode_active() ) {
100 + DevMode::setup();
263 101
102 + $frontend_request = ! (
103 + ( function_exists( 'is_admin' ) && is_admin() )
104 + || ( defined( 'DOING_AJAX' ) && DOING_AJAX )
105 + || ( defined( 'DOING_CRON' ) && DOING_CRON )
106 + || ( defined( 'WP_CLI' ) && WP_CLI )
107 + );
264 108
265 -/**
266 - * Check requirement
267 - */
268 -function powered_cache_requirements_notice() {
269 - if ( ! current_user_can( 'update_core' ) ) {
109 + // don't run the plugin for frontend requests in dev mode
110 + if ( $frontend_request ) {
270 111 return;
271 112 }
272 - ?>
113 +}
273 114
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
115 +if ( Utils\bypass_request() ) {
116 + return;
283 117 }
284 118
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 119
289 - return;
290 -}
120 +// Bootstrap.
121 +Core\setup();
122 +Admin\Dashboard\setup();
123 +Admin\Notices\setup();
124 +Install::factory();
125 +AdvancedCache::factory();
126 +ObjectCache::factory();
127 +CDN::factory();
128 +Cron::factory();
129 +Preloader::factory();
130 +FileOptimizer::factory();
131 +LazyLoad::factory();
132 +Preloader::factory();
133 +MetaBox::factory();
134 +Extensions::factory();
291 135
292 -// run
293 -powered_cache();
136 +// Activation/Deactivation.
137 +register_activation_hook( __FILE__, '\PoweredCache\Core\activate' );
138 +register_deactivation_hook( __FILE__, '\PoweredCache\Core\deactivate' );