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 -254 1.0trunk View file →
@@ -1,289 +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.0
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.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 - }
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-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 83 }
84 +);
214 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';
215 93
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' );
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 );
248 97 }
249 98
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 -}
99 +if ( Utils\is_dev_mode_active() ) {
100 + DevMode::setup();
259 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 + );
260 108
261 -/**
262 - * Check requirement
263 - */
264 -function powered_cache_requirements_notice() {
265 - if ( ! current_user_can( 'update_core' ) ) {
109 + // don't run the plugin for frontend requests in dev mode
110 + if ( $frontend_request ) {
266 111 return;
267 112 }
268 - ?>
113 +}
269 114
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
115 +if ( Utils\bypass_request() ) {
116 + return;
279 117 }
280 118
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 119
285 - return;
286 -}
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();
287 135
288 -// run
289 -powered_cache();
136 +// Activation/Deactivation.
137 +register_activation_hook( __FILE__, '\PoweredCache\Core\activate' );
138 +register_deactivation_hook( __FILE__, '\PoweredCache\Core\deactivate' );