@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Wraps base plugin logic/hooks and handles activation/deactivation/uninstall. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param string $version Version. |
34 | 34 | * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks. |
35 | 35 | */ |
36 | - public function __construct( $version, $filepath ) |
|
36 | + public function __construct($version, $filepath) |
|
37 | 37 | { |
38 | 38 | $this->version = $version; |
39 | 39 | $this->filepath = $filepath; |
@@ -50,94 +50,94 @@ discard block |
||
50 | 50 | |
51 | 51 | protected function add_hooks() |
52 | 52 | { |
53 | - add_action( 'plugins_loaded', array( $this, 'setup' ) ); |
|
53 | + add_action('plugins_loaded', array($this, 'setup')); |
|
54 | 54 | |
55 | - add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) ); |
|
56 | - add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) ); |
|
57 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ) ); |
|
58 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ) ); |
|
55 | + add_action('autoptimize_setup_done', array($this, 'version_upgrades_check')); |
|
56 | + add_action('autoptimize_setup_done', array($this, 'check_cache_and_run')); |
|
57 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra')); |
|
58 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab')); |
|
59 | 59 | |
60 | - add_action( 'init', array( $this, 'load_textdomain' ) ); |
|
61 | - add_action( 'plugins_loaded', array( $this, 'hook_page_cache_purge' ) ); |
|
62 | - add_action( 'admin_init', array( 'PAnD', 'init' ) ); |
|
60 | + add_action('init', array($this, 'load_textdomain')); |
|
61 | + add_action('plugins_loaded', array($this, 'hook_page_cache_purge')); |
|
62 | + add_action('admin_init', array('PAnD', 'init')); |
|
63 | 63 | |
64 | - register_activation_hook( $this->filepath, array( $this, 'on_activate' ) ); |
|
64 | + register_activation_hook($this->filepath, array($this, 'on_activate')); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function on_activate() |
68 | 68 | { |
69 | - register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' ); |
|
69 | + register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | public function load_textdomain() |
73 | 73 | { |
74 | - load_plugin_textdomain( 'autoptimize' ); |
|
74 | + load_plugin_textdomain('autoptimize'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | public function setup() |
78 | 78 | { |
79 | 79 | // Do we gzip in php when caching or is the webserver doing it? |
80 | - define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option( 'autoptimize_cache_nogzip' ) ); |
|
80 | + define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option('autoptimize_cache_nogzip')); |
|
81 | 81 | |
82 | 82 | // These can be overridden by specifying them in wp-config.php or such. |
83 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) { |
|
84 | - define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) ); |
|
83 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { |
|
84 | + define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR)); |
|
85 | 85 | } |
86 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) { |
|
87 | - define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' ); |
|
86 | + if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { |
|
87 | + define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/'); |
|
88 | 88 | } |
89 | - if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) { |
|
90 | - define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' ); |
|
89 | + if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) { |
|
90 | + define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_'); |
|
91 | 91 | } |
92 | 92 | // Note: trailing slash is not optional! |
93 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) { |
|
94 | - define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() ); |
|
93 | + if (!defined('AUTOPTIMIZE_CACHE_DIR')) { |
|
94 | + define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname()); |
|
95 | 95 | } |
96 | 96 | |
97 | - define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) ); |
|
97 | + define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME))); |
|
98 | 98 | |
99 | - if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) { |
|
100 | - if ( function_exists( 'domain_mapping_siteurl' ) ) { |
|
101 | - define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) ); |
|
99 | + if (!defined('AUTOPTIMIZE_WP_SITE_URL')) { |
|
100 | + if (function_exists('domain_mapping_siteurl')) { |
|
101 | + define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id())); |
|
102 | 102 | } else { |
103 | - define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() ); |
|
103 | + define('AUTOPTIMIZE_WP_SITE_URL', site_url()); |
|
104 | 104 | } |
105 | 105 | } |
106 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) { |
|
107 | - if ( function_exists( 'domain_mapping_siteurl' ) ) { |
|
108 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) ); |
|
106 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) { |
|
107 | + if (function_exists('domain_mapping_siteurl')) { |
|
108 | + define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url())); |
|
109 | 109 | } else { |
110 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() ); |
|
110 | + define('AUTOPTIMIZE_WP_CONTENT_URL', content_url()); |
|
111 | 111 | } |
112 | 112 | } |
113 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) { |
|
114 | - if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { |
|
113 | + if (!defined('AUTOPTIMIZE_CACHE_URL')) { |
|
114 | + if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
115 | 115 | $blog_id = get_current_blog_id(); |
116 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' ); |
|
116 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/'); |
|
117 | 117 | } else { |
118 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR ); |
|
118 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR); |
|
119 | 119 | } |
120 | 120 | } |
121 | - if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) { |
|
122 | - define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) ); |
|
121 | + if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) { |
|
122 | + define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL)); |
|
123 | 123 | } |
124 | - if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) { |
|
125 | - define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) ); |
|
124 | + if (!defined('AUTOPTIMIZE_HASH')) { |
|
125 | + define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL)); |
|
126 | 126 | } |
127 | - if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) { |
|
128 | - define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ); |
|
127 | + if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) { |
|
128 | + define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | // Multibyte-capable string replacements are available with a filter. |
132 | 132 | // Also requires 'mbstring' extension. |
133 | - $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false ); |
|
134 | - if ( $with_mbstring ) { |
|
135 | - autoptimizeUtils::mbstring_available( \extensions_loaded( 'mbstring' ) ); |
|
133 | + $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false); |
|
134 | + if ($with_mbstring) { |
|
135 | + autoptimizeUtils::mbstring_available(\extensions_loaded('mbstring')); |
|
136 | 136 | } else { |
137 | - autoptimizeUtils::mbstring_available( false ); |
|
137 | + autoptimizeUtils::mbstring_available(false); |
|
138 | 138 | } |
139 | 139 | |
140 | - do_action( 'autoptimize_setup_done' ); |
|
140 | + do_action('autoptimize_setup_done'); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -147,52 +147,52 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function version_upgrades_check() |
149 | 149 | { |
150 | - autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version ); |
|
150 | + autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | public function check_cache_and_run() |
154 | 154 | { |
155 | - if ( autoptimizeCache::cacheavail() ) { |
|
155 | + if (autoptimizeCache::cacheavail()) { |
|
156 | 156 | $conf = autoptimizeConfig::instance(); |
157 | - if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) { |
|
157 | + if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css')) { |
|
158 | 158 | // Hook into WordPress frontend. |
159 | - if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) { |
|
159 | + if (defined('AUTOPTIMIZE_INIT_EARLIER')) { |
|
160 | 160 | add_action( |
161 | 161 | 'init', |
162 | - array( $this, 'start_buffering' ), |
|
162 | + array($this, 'start_buffering'), |
|
163 | 163 | self::INIT_EARLIER_PRIORITY |
164 | 164 | ); |
165 | 165 | } else { |
166 | - if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) { |
|
167 | - define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' ); |
|
166 | + if (!defined('AUTOPTIMIZE_HOOK_INTO')) { |
|
167 | + define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect'); |
|
168 | 168 | } |
169 | 169 | add_action( |
170 | - constant( 'AUTOPTIMIZE_HOOK_INTO' ), |
|
171 | - array( $this, 'start_buffering' ), |
|
170 | + constant('AUTOPTIMIZE_HOOK_INTO'), |
|
171 | + array($this, 'start_buffering'), |
|
172 | 172 | self::DEFAULT_HOOK_PRIORITY |
173 | 173 | ); |
174 | 174 | } |
175 | 175 | } |
176 | 176 | } else { |
177 | - add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' ); |
|
177 | + add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable'); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | 181 | public function maybe_run_ao_extra() |
182 | 182 | { |
183 | - if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) { |
|
183 | + if (apply_filters('autoptimize_filter_extra_activate', true)) { |
|
184 | 184 | $ao_extra = new autoptimizeExtra(); |
185 | 185 | $ao_extra->run(); |
186 | 186 | |
187 | 187 | // And show the imgopt notice. |
188 | - add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' ); |
|
188 | + add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt'); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | 192 | public function maybe_run_partners_tab() |
193 | 193 | { |
194 | 194 | // Loads partners tab code if in admin (and not in admin-ajax.php)! |
195 | - if ( autoptimizeConfig::is_admin_and_not_ajax() ) { |
|
195 | + if (autoptimizeConfig::is_admin_and_not_ajax()) { |
|
196 | 196 | new autoptimizePartners(); |
197 | 197 | } |
198 | 198 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | public function hook_page_cache_purge() |
201 | 201 | { |
202 | 202 | // hook into a collection of page cache purge actions if filter allows. |
203 | - if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) { |
|
203 | + if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) { |
|
204 | 204 | $page_cache_purge_actions = array( |
205 | 205 | 'after_rocket_clean_domain', // exists. |
206 | 206 | 'hyper_cache_purged', // Stefano confirmed this will be added. |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | 'wpfc_delete_cache', // Emre confirmed this will be added this. |
213 | 213 | 'swift_performance_after_clear_all_cache', // swift perf. yeah! |
214 | 214 | ); |
215 | - $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions ); |
|
216 | - foreach ( $page_cache_purge_actions as $purge_action ) { |
|
217 | - add_action( $purge_action, 'autoptimizeCache::clearall_actionless' ); |
|
215 | + $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions); |
|
216 | + foreach ($page_cache_purge_actions as $purge_action) { |
|
217 | + add_action($purge_action, 'autoptimizeCache::clearall_actionless'); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
@@ -226,38 +226,38 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function start_buffering() |
228 | 228 | { |
229 | - if ( $this->should_buffer() ) { |
|
229 | + if ($this->should_buffer()) { |
|
230 | 230 | |
231 | 231 | // Load speedupper conditionally (true by default). |
232 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) { |
|
232 | + if (apply_filters('autoptimize_filter_speedupper', true)) { |
|
233 | 233 | $ao_speedupper = new autoptimizeSpeedupper(); |
234 | 234 | } |
235 | 235 | |
236 | 236 | $conf = autoptimizeConfig::instance(); |
237 | 237 | |
238 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
239 | - if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) { |
|
240 | - define( 'CONCATENATE_SCRIPTS', false ); |
|
238 | + if ($conf->get('autoptimize_js')) { |
|
239 | + if (!defined('CONCATENATE_SCRIPTS')) { |
|
240 | + define('CONCATENATE_SCRIPTS', false); |
|
241 | 241 | } |
242 | - if ( ! defined( 'COMPRESS_SCRIPTS' ) ) { |
|
243 | - define( 'COMPRESS_SCRIPTS', false ); |
|
242 | + if (!defined('COMPRESS_SCRIPTS')) { |
|
243 | + define('COMPRESS_SCRIPTS', false); |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
248 | - if ( ! defined( 'COMPRESS_CSS' ) ) { |
|
249 | - define( 'COMPRESS_CSS', false ); |
|
247 | + if ($conf->get('autoptimize_css')) { |
|
248 | + if (!defined('COMPRESS_CSS')) { |
|
249 | + define('COMPRESS_CSS', false); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
253 | - if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) { |
|
254 | - while ( ob_get_level() > 0 ) { |
|
253 | + if (apply_filters('autoptimize_filter_obkiller', false)) { |
|
254 | + while (ob_get_level() > 0) { |
|
255 | 255 | ob_end_clean(); |
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | 259 | // Now, start the real thing! |
260 | - ob_start( array( $this, 'end_buffering' ) ); |
|
260 | + ob_start(array($this, 'end_buffering')); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
@@ -268,31 +268,31 @@ discard block |
||
268 | 268 | * deciding once per request (for use in tests). |
269 | 269 | * @return bool |
270 | 270 | */ |
271 | - public function should_buffer( $doing_tests = false ) |
|
271 | + public function should_buffer($doing_tests = false) |
|
272 | 272 | { |
273 | 273 | static $do_buffering = null; |
274 | 274 | |
275 | 275 | // Only check once in case we're called multiple times by others but |
276 | 276 | // still allows multiple calls when doing tests. |
277 | - if ( null === $do_buffering || $doing_tests ) { |
|
277 | + if (null === $do_buffering || $doing_tests) { |
|
278 | 278 | |
279 | 279 | $ao_noptimize = false; |
280 | 280 | |
281 | 281 | // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS. |
282 | - if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) { |
|
282 | + if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) { |
|
283 | 283 | $ao_noptimize = true; |
284 | 284 | } |
285 | 285 | |
286 | 286 | // Skip checking query strings if they're disabled. |
287 | - if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) { |
|
287 | + if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) { |
|
288 | 288 | // Check for `ao_noptimize` (and other) keys in the query string |
289 | 289 | // to get non-optimized page for debugging. |
290 | 290 | $keys = array( |
291 | 291 | 'ao_noptimize', |
292 | 292 | 'ao_noptirocket', |
293 | 293 | ); |
294 | - foreach ( $keys as $key ) { |
|
295 | - if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) { |
|
294 | + foreach ($keys as $key) { |
|
295 | + if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) { |
|
296 | 296 | $ao_noptimize = true; |
297 | 297 | break; |
298 | 298 | } |
@@ -300,15 +300,15 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // If setting says not to optimize logged in user and user is logged in... |
303 | - if ( 'on' !== get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) { |
|
303 | + if ('on' !== get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) { |
|
304 | 304 | $ao_noptimize = true; |
305 | 305 | } |
306 | 306 | |
307 | 307 | // If setting says not to optimize cart/checkout. |
308 | - if ( 'on' !== get_option( 'autoptimize_optimize_checkout', 'on' ) ) { |
|
308 | + if ('on' !== get_option('autoptimize_optimize_checkout', 'on')) { |
|
309 | 309 | // Checking for woocommerce, easy digital downloads and wp ecommerce... |
310 | - foreach ( array( 'is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) { |
|
311 | - if ( function_exists( $func ) && $func() ) { |
|
310 | + foreach (array('is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) { |
|
311 | + if (function_exists($func) && $func()) { |
|
312 | 312 | $ao_noptimize = true; |
313 | 313 | break; |
314 | 314 | } |
@@ -316,11 +316,11 @@ discard block |
||
316 | 316 | } |
317 | 317 | |
318 | 318 | // Allows blocking of autoptimization on your own terms regardless of above decisions. |
319 | - $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize ); |
|
319 | + $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize); |
|
320 | 320 | |
321 | 321 | // Check for site being previewed in the Customizer (available since WP 4.0). |
322 | 322 | $is_customize_preview = false; |
323 | - if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) { |
|
323 | + if (function_exists('is_customize_preview') && is_customize_preview()) { |
|
324 | 324 | $is_customize_preview = is_customize_preview(); |
325 | 325 | } |
326 | 326 | |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | * while the main query hasn't been ran yet. Thats why we use |
332 | 332 | * AUTOPTIMIZE_INIT_EARLIER in tests. |
333 | 333 | */ |
334 | - $do_buffering = ( ! is_admin() && ! is_feed() && ! $ao_noptimize && ! $is_customize_preview ); |
|
334 | + $do_buffering = (!is_admin() && !is_feed() && !$ao_noptimize && !$is_customize_preview); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | return $do_buffering; |
@@ -344,24 +344,24 @@ discard block |
||
344 | 344 | * |
345 | 345 | * @return bool |
346 | 346 | */ |
347 | - public function is_valid_buffer( $content ) |
|
347 | + public function is_valid_buffer($content) |
|
348 | 348 | { |
349 | 349 | // Defaults to true. |
350 | 350 | $valid = true; |
351 | 351 | |
352 | - $has_no_html_tag = ( false === stripos( $content, '<html' ) ); |
|
353 | - $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) ); |
|
354 | - $has_html5_doctype = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 ); |
|
352 | + $has_no_html_tag = (false === stripos($content, '<html')); |
|
353 | + $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet')); |
|
354 | + $has_html5_doctype = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0); |
|
355 | 355 | |
356 | - if ( $has_no_html_tag ) { |
|
356 | + if ($has_no_html_tag) { |
|
357 | 357 | // Can't be valid amp markup without an html tag preceding it. |
358 | 358 | $is_amp_markup = false; |
359 | 359 | } else { |
360 | - $is_amp_markup = self::is_amp_markup( $content ); |
|
360 | + $is_amp_markup = self::is_amp_markup($content); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it. |
364 | - if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet ) { |
|
364 | + if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet) { |
|
365 | 365 | $valid = false; |
366 | 366 | } |
367 | 367 | |
@@ -376,14 +376,14 @@ discard block |
||
376 | 376 | * |
377 | 377 | * @return bool |
378 | 378 | */ |
379 | - public static function is_amp_markup( $content ) |
|
379 | + public static function is_amp_markup($content) |
|
380 | 380 | { |
381 | 381 | // Short-circuit when a function is available to determine whether the response is (or will be) an AMP page. |
382 | - if ( function_exists( 'is_amp_endpoint' ) ) { |
|
382 | + if (function_exists('is_amp_endpoint')) { |
|
383 | 383 | return is_amp_endpoint(); |
384 | 384 | } |
385 | 385 | |
386 | - $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content ); |
|
386 | + $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content); |
|
387 | 387 | |
388 | 388 | return (bool) $is_amp_markup; |
389 | 389 | } |
@@ -396,10 +396,10 @@ discard block |
||
396 | 396 | * |
397 | 397 | * @return string |
398 | 398 | */ |
399 | - public function end_buffering( $content ) |
|
399 | + public function end_buffering($content) |
|
400 | 400 | { |
401 | 401 | // Bail early without modifying anything if we can't handle the content. |
402 | - if ( ! $this->is_valid_buffer( $content ) ) { |
|
402 | + if (!$this->is_valid_buffer($content)) { |
|
403 | 403 | return $content; |
404 | 404 | } |
405 | 405 | |
@@ -407,57 +407,57 @@ discard block |
||
407 | 407 | |
408 | 408 | // Determine what needs to be ran. |
409 | 409 | $classes = array(); |
410 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
410 | + if ($conf->get('autoptimize_js')) { |
|
411 | 411 | $classes[] = 'autoptimizeScripts'; |
412 | 412 | } |
413 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
413 | + if ($conf->get('autoptimize_css')) { |
|
414 | 414 | $classes[] = 'autoptimizeStyles'; |
415 | 415 | } |
416 | - if ( $conf->get( 'autoptimize_html' ) ) { |
|
416 | + if ($conf->get('autoptimize_html')) { |
|
417 | 417 | $classes[] = 'autoptimizeHTML'; |
418 | 418 | } |
419 | 419 | |
420 | 420 | $classoptions = array( |
421 | 421 | 'autoptimizeScripts' => array( |
422 | - 'aggregate' => $conf->get( 'autoptimize_js_aggregate' ), |
|
423 | - 'justhead' => $conf->get( 'autoptimize_js_justhead' ), |
|
424 | - 'forcehead' => $conf->get( 'autoptimize_js_forcehead' ), |
|
425 | - 'trycatch' => $conf->get( 'autoptimize_js_trycatch' ), |
|
426 | - 'js_exclude' => $conf->get( 'autoptimize_js_exclude' ), |
|
427 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
428 | - 'include_inline' => $conf->get( 'autoptimize_js_include_inline' ), |
|
422 | + 'aggregate' => $conf->get('autoptimize_js_aggregate'), |
|
423 | + 'justhead' => $conf->get('autoptimize_js_justhead'), |
|
424 | + 'forcehead' => $conf->get('autoptimize_js_forcehead'), |
|
425 | + 'trycatch' => $conf->get('autoptimize_js_trycatch'), |
|
426 | + 'js_exclude' => $conf->get('autoptimize_js_exclude'), |
|
427 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
428 | + 'include_inline' => $conf->get('autoptimize_js_include_inline'), |
|
429 | 429 | ), |
430 | 430 | 'autoptimizeStyles' => array( |
431 | - 'aggregate' => $conf->get( 'autoptimize_css_aggregate' ), |
|
432 | - 'justhead' => $conf->get( 'autoptimize_css_justhead' ), |
|
433 | - 'datauris' => $conf->get( 'autoptimize_css_datauris' ), |
|
434 | - 'defer' => $conf->get( 'autoptimize_css_defer' ), |
|
435 | - 'defer_inline' => $conf->get( 'autoptimize_css_defer_inline' ), |
|
436 | - 'inline' => $conf->get( 'autoptimize_css_inline' ), |
|
437 | - 'css_exclude' => $conf->get( 'autoptimize_css_exclude' ), |
|
438 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
439 | - 'include_inline' => $conf->get( 'autoptimize_css_include_inline' ), |
|
440 | - 'nogooglefont' => $conf->get( 'autoptimize_css_nogooglefont' ), |
|
431 | + 'aggregate' => $conf->get('autoptimize_css_aggregate'), |
|
432 | + 'justhead' => $conf->get('autoptimize_css_justhead'), |
|
433 | + 'datauris' => $conf->get('autoptimize_css_datauris'), |
|
434 | + 'defer' => $conf->get('autoptimize_css_defer'), |
|
435 | + 'defer_inline' => $conf->get('autoptimize_css_defer_inline'), |
|
436 | + 'inline' => $conf->get('autoptimize_css_inline'), |
|
437 | + 'css_exclude' => $conf->get('autoptimize_css_exclude'), |
|
438 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
439 | + 'include_inline' => $conf->get('autoptimize_css_include_inline'), |
|
440 | + 'nogooglefont' => $conf->get('autoptimize_css_nogooglefont'), |
|
441 | 441 | ), |
442 | 442 | 'autoptimizeHTML' => array( |
443 | - 'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ), |
|
443 | + 'keepcomments' => $conf->get('autoptimize_html_keepcomments'), |
|
444 | 444 | ), |
445 | 445 | ); |
446 | 446 | |
447 | - $content = apply_filters( 'autoptimize_filter_html_before_minify', $content ); |
|
447 | + $content = apply_filters('autoptimize_filter_html_before_minify', $content); |
|
448 | 448 | |
449 | 449 | // Run the classes! |
450 | - foreach ( $classes as $name ) { |
|
451 | - $instance = new $name( $content ); |
|
452 | - if ( $instance->read( $classoptions[ $name ] ) ) { |
|
450 | + foreach ($classes as $name) { |
|
451 | + $instance = new $name($content); |
|
452 | + if ($instance->read($classoptions[$name])) { |
|
453 | 453 | $instance->minify(); |
454 | 454 | $instance->cache(); |
455 | 455 | $content = $instance->getcontent(); |
456 | 456 | } |
457 | - unset( $instance ); |
|
457 | + unset($instance); |
|
458 | 458 | } |
459 | 459 | |
460 | - $content = apply_filters( 'autoptimize_html_after_minify', $content ); |
|
460 | + $content = apply_filters('autoptimize_html_after_minify', $content); |
|
461 | 461 | |
462 | 462 | return $content; |
463 | 463 | } |
@@ -499,25 +499,25 @@ discard block |
||
499 | 499 | 'autoptimize_imgopt_launched', |
500 | 500 | ); |
501 | 501 | |
502 | - if ( ! is_multisite() ) { |
|
503 | - foreach ( $delete_options as $del_opt ) { |
|
504 | - delete_option( $del_opt ); |
|
502 | + if (!is_multisite()) { |
|
503 | + foreach ($delete_options as $del_opt) { |
|
504 | + delete_option($del_opt); |
|
505 | 505 | } |
506 | 506 | } else { |
507 | 507 | global $wpdb; |
508 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
508 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
509 | 509 | $original_blog_id = get_current_blog_id(); |
510 | - foreach ( $blog_ids as $blog_id ) { |
|
511 | - switch_to_blog( $blog_id ); |
|
512 | - foreach ( $delete_options as $del_opt ) { |
|
513 | - delete_option( $del_opt ); |
|
510 | + foreach ($blog_ids as $blog_id) { |
|
511 | + switch_to_blog($blog_id); |
|
512 | + foreach ($delete_options as $del_opt) { |
|
513 | + delete_option($del_opt); |
|
514 | 514 | } |
515 | 515 | } |
516 | - switch_to_blog( $original_blog_id ); |
|
516 | + switch_to_blog($original_blog_id); |
|
517 | 517 | } |
518 | 518 | |
519 | - if ( wp_get_schedule( 'ao_cachechecker' ) ) { |
|
520 | - wp_clear_scheduled_hook( 'ao_cachechecker' ); |
|
519 | + if (wp_get_schedule('ao_cachechecker')) { |
|
520 | + wp_clear_scheduled_hook('ao_cachechecker'); |
|
521 | 521 | } |
522 | 522 | } |
523 | 523 | |
@@ -525,41 +525,41 @@ discard block |
||
525 | 525 | { |
526 | 526 | echo '<div class="error"><p>'; |
527 | 527 | // Translators: %s is the cache directory location. |
528 | - printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR ); |
|
528 | + printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR); |
|
529 | 529 | echo '</p></div>'; |
530 | 530 | } |
531 | 531 | |
532 | 532 | public static function notice_installed() |
533 | 533 | { |
534 | 534 | echo '<div class="updated"><p>'; |
535 | - _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' ); |
|
535 | + _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize'); |
|
536 | 536 | echo '</p></div>'; |
537 | 537 | } |
538 | 538 | |
539 | 539 | public static function notice_updated() |
540 | 540 | { |
541 | 541 | echo '<div class="updated"><p>'; |
542 | - _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' ); |
|
542 | + _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize'); |
|
543 | 543 | echo '</p></div>'; |
544 | 544 | } |
545 | 545 | |
546 | 546 | public static function notice_plug_imgopt() |
547 | 547 | { |
548 | 548 | // Translators: the URL added points to the Autopmize Extra settings. |
549 | - $_ao_imgopt_plug_notice = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization and CDN via ShortPixel? Check out the %1$sAutoptimize Extra settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_extra">', '</a>' ); |
|
550 | - $_ao_imgopt_plug_notice = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice ); |
|
549 | + $_ao_imgopt_plug_notice = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization and CDN via ShortPixel? Check out the %1$sAutoptimize Extra settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_extra">', '</a>'); |
|
550 | + $_ao_imgopt_plug_notice = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice); |
|
551 | 551 | $_ao_imgopt_launch_ok = autoptimizeExtra::imgopt_launch_ok_wrapper(); |
552 | 552 | $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123'; |
553 | 553 | |
554 | 554 | // check if AO is optimizing images already. |
555 | 555 | $_ao_imgopt_active = false; |
556 | - $_ao_extra_options = get_option( 'autoptimize_extra_settings', '' ); |
|
557 | - if ( is_array( $_ao_extra_options ) && array_key_exists( 'autoptimize_extra_checkbox_field_5', $_ao_extra_options ) && ! empty( $_ao_extra_options['autoptimize_extra_checkbox_field_5'] ) ) { |
|
556 | + $_ao_extra_options = get_option('autoptimize_extra_settings', ''); |
|
557 | + if (is_array($_ao_extra_options) && array_key_exists('autoptimize_extra_checkbox_field_5', $_ao_extra_options) && !empty($_ao_extra_options['autoptimize_extra_checkbox_field_5'])) { |
|
558 | 558 | $_ao_imgopt_active = true; |
559 | 559 | } |
560 | 560 | |
561 | - if ( current_user_can( 'manage_options' ) && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) { |
|
562 | - echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>'; |
|
561 | + if (current_user_can('manage_options') && '' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) { |
|
562 | + echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>'; |
|
563 | 563 | echo $_ao_imgopt_plug_notice; |
564 | 564 | echo '</p></div>'; |
565 | 565 | } |