@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Class for CSS optimization. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -161,54 +161,54 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @param array $options all options. |
163 | 163 | */ |
164 | - public function read( $options ) |
|
164 | + public function read($options) |
|
165 | 165 | { |
166 | - $noptimize_css = apply_filters( 'autoptimize_filter_css_noptimize', false, $this->content ); |
|
167 | - if ( $noptimize_css ) { |
|
166 | + $noptimize_css = apply_filters('autoptimize_filter_css_noptimize', false, $this->content); |
|
167 | + if ($noptimize_css) { |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
171 | - $allowlist_css = apply_filters( 'autoptimize_filter_css_allowlist', '', $this->content ); |
|
172 | - $allowlist_css = apply_filters( 'autoptimize_filter_css_whitelist', $allowlist_css, $this->content ); // fixme: to be removed in next version. |
|
173 | - if ( ! empty( $allowlist_css ) ) { |
|
174 | - $this->allowlist = array_filter( array_map( 'trim', explode( ',', $allowlist_css ) ) ); |
|
171 | + $allowlist_css = apply_filters('autoptimize_filter_css_allowlist', '', $this->content); |
|
172 | + $allowlist_css = apply_filters('autoptimize_filter_css_whitelist', $allowlist_css, $this->content); // fixme: to be removed in next version. |
|
173 | + if (!empty($allowlist_css)) { |
|
174 | + $this->allowlist = array_filter(array_map('trim', explode(',', $allowlist_css))); |
|
175 | 175 | } |
176 | 176 | |
177 | - $removable_css = apply_filters( 'autoptimize_filter_css_removables', '' ); |
|
178 | - if ( ! empty( $removable_css ) ) { |
|
179 | - $this->cssremovables = array_filter( array_map( 'trim', explode( ',', $removable_css ) ) ); |
|
177 | + $removable_css = apply_filters('autoptimize_filter_css_removables', ''); |
|
178 | + if (!empty($removable_css)) { |
|
179 | + $this->cssremovables = array_filter(array_map('trim', explode(',', $removable_css))); |
|
180 | 180 | } |
181 | 181 | |
182 | - $this->cssinlinesize = apply_filters( 'autoptimize_filter_css_inlinesize', 256 ); |
|
182 | + $this->cssinlinesize = apply_filters('autoptimize_filter_css_inlinesize', 256); |
|
183 | 183 | |
184 | 184 | // filter to "late inject minified CSS", default to true for now (it is faster). |
185 | - $this->inject_min_late = apply_filters( 'autoptimize_filter_css_inject_min_late', true ); |
|
185 | + $this->inject_min_late = apply_filters('autoptimize_filter_css_inject_min_late', true); |
|
186 | 186 | |
187 | 187 | // Remove everything that's not the header. |
188 | - if ( apply_filters( 'autoptimize_filter_css_justhead', $options['justhead'] ) ) { |
|
189 | - $content = explode( '</head>', $this->content, 2 ); |
|
190 | - $this->content = $content[0] . '</head>'; |
|
188 | + if (apply_filters('autoptimize_filter_css_justhead', $options['justhead'])) { |
|
189 | + $content = explode('</head>', $this->content, 2); |
|
190 | + $this->content = $content[0].'</head>'; |
|
191 | 191 | $this->restofcontent = $content[1]; |
192 | 192 | } |
193 | 193 | |
194 | 194 | // Determine whether we're doing CSS-files aggregation or not. |
195 | - if ( isset( $options['aggregate'] ) && ! $options['aggregate'] ) { |
|
195 | + if (isset($options['aggregate']) && !$options['aggregate']) { |
|
196 | 196 | $this->aggregate = false; |
197 | 197 | } |
198 | 198 | // Returning true for "dontaggregate" turns off aggregation. |
199 | - if ( $this->aggregate && apply_filters( 'autoptimize_filter_css_dontaggregate', false ) ) { |
|
199 | + if ($this->aggregate && apply_filters('autoptimize_filter_css_dontaggregate', false)) { |
|
200 | 200 | $this->aggregate = false; |
201 | 201 | } |
202 | 202 | |
203 | 203 | // include inline? |
204 | - if ( apply_filters( 'autoptimize_css_include_inline', $options['include_inline'] ) ) { |
|
204 | + if (apply_filters('autoptimize_css_include_inline', $options['include_inline'])) { |
|
205 | 205 | $this->include_inline = true; |
206 | 206 | } |
207 | 207 | |
208 | 208 | // List of CSS strings which are excluded from autoptimization. |
209 | - $exclude_css = apply_filters( 'autoptimize_filter_css_exclude', $options['css_exclude'], $this->content ); |
|
210 | - if ( '' !== $exclude_css ) { |
|
211 | - $this->dontmove = array_filter( array_map( 'trim', explode( ',', $exclude_css ) ) ); |
|
209 | + $exclude_css = apply_filters('autoptimize_filter_css_exclude', $options['css_exclude'], $this->content); |
|
210 | + if ('' !== $exclude_css) { |
|
211 | + $this->dontmove = array_filter(array_map('trim', explode(',', $exclude_css))); |
|
212 | 212 | } else { |
213 | 213 | $this->dontmove = array(); |
214 | 214 | } |
@@ -219,16 +219,16 @@ discard block |
||
219 | 219 | // Should we defer css? |
220 | 220 | // value: true / false. |
221 | 221 | $this->defer = $options['defer']; |
222 | - $this->defer = apply_filters( 'autoptimize_filter_css_defer', $this->defer, $this->content ); |
|
222 | + $this->defer = apply_filters('autoptimize_filter_css_defer', $this->defer, $this->content); |
|
223 | 223 | |
224 | 224 | // Should we inline while deferring? |
225 | 225 | // value: inlined CSS. |
226 | - $this->defer_inline = apply_filters( 'autoptimize_filter_css_defer_inline', $this->sanitize_css( $options['defer_inline'] ), $this->content ); |
|
226 | + $this->defer_inline = apply_filters('autoptimize_filter_css_defer_inline', $this->sanitize_css($options['defer_inline']), $this->content); |
|
227 | 227 | |
228 | 228 | // Should we inline? |
229 | 229 | // value: true / false. |
230 | 230 | $this->inline = $options['inline']; |
231 | - $this->inline = apply_filters( 'autoptimize_filter_css_inline', $this->inline, $this->content ); |
|
231 | + $this->inline = apply_filters('autoptimize_filter_css_inline', $this->inline, $this->content); |
|
232 | 232 | |
233 | 233 | // Store cdn url. |
234 | 234 | $this->cdn_url = $options['cdn_url']; |
@@ -237,16 +237,16 @@ discard block |
||
237 | 237 | $this->datauris = $options['datauris']; |
238 | 238 | |
239 | 239 | // Determine whether excluded files should be minified if not yet so. |
240 | - if ( ! $options['minify_excluded'] && $options['aggregate'] ) { |
|
240 | + if (!$options['minify_excluded'] && $options['aggregate']) { |
|
241 | 241 | $this->minify_excluded = false; |
242 | 242 | } |
243 | - $this->minify_excluded = apply_filters( 'autoptimize_filter_css_minify_excluded', $this->minify_excluded, '' ); |
|
243 | + $this->minify_excluded = apply_filters('autoptimize_filter_css_minify_excluded', $this->minify_excluded, ''); |
|
244 | 244 | |
245 | 245 | // should we force all media-attributes to all? |
246 | - $this->media_force_all = apply_filters( 'autoptimize_filter_css_tagmedia_forceall', false ); |
|
246 | + $this->media_force_all = apply_filters('autoptimize_filter_css_tagmedia_forceall', false); |
|
247 | 247 | |
248 | 248 | // noptimize me. |
249 | - $this->content = $this->hide_noptimize( $this->content ); |
|
249 | + $this->content = $this->hide_noptimize($this->content); |
|
250 | 250 | |
251 | 251 | // Exclude (no)script, as those may contain CSS which should be left as is. |
252 | 252 | $this->content = $this->replace_contents_with_marker_if_exists( |
@@ -257,25 +257,25 @@ discard block |
||
257 | 257 | ); |
258 | 258 | |
259 | 259 | // Save IE hacks. |
260 | - $this->content = $this->hide_iehacks( $this->content ); |
|
260 | + $this->content = $this->hide_iehacks($this->content); |
|
261 | 261 | |
262 | 262 | // Hide HTML comments. |
263 | - $this->content = $this->hide_comments( $this->content ); |
|
263 | + $this->content = $this->hide_comments($this->content); |
|
264 | 264 | |
265 | 265 | // Get <style> and <link>. |
266 | - if ( preg_match_all( '#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches ) ) { |
|
266 | + if (preg_match_all('#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches)) { |
|
267 | 267 | |
268 | - foreach ( $matches[0] as $tag ) { |
|
269 | - if ( $this->isremovable( $tag, $this->cssremovables ) ) { |
|
270 | - $this->content = str_replace( $tag, '', $this->content ); |
|
271 | - } elseif ( $this->ismovable( $tag ) ) { |
|
268 | + foreach ($matches[0] as $tag) { |
|
269 | + if ($this->isremovable($tag, $this->cssremovables)) { |
|
270 | + $this->content = str_replace($tag, '', $this->content); |
|
271 | + } elseif ($this->ismovable($tag)) { |
|
272 | 272 | // Get the media. |
273 | - if ( false !== strpos( $tag, 'media=' ) ) { |
|
274 | - preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias ); |
|
275 | - $medias = explode( ',', $medias[1] ); |
|
273 | + if (false !== strpos($tag, 'media=')) { |
|
274 | + preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias); |
|
275 | + $medias = explode(',', $medias[1]); |
|
276 | 276 | $media = array(); |
277 | - foreach ( $medias as $elem ) { |
|
278 | - if ( empty( $elem ) ) { |
|
277 | + foreach ($medias as $elem) { |
|
278 | + if (empty($elem)) { |
|
279 | 279 | $elem = 'all'; |
280 | 280 | } |
281 | 281 | |
@@ -283,68 +283,68 @@ discard block |
||
283 | 283 | } |
284 | 284 | } else { |
285 | 285 | // No media specified - applies to all. |
286 | - $media = array( 'all' ); |
|
286 | + $media = array('all'); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // forcing media attribute to all to merge all in one file. |
290 | - if ( $this->media_force_all ) { |
|
291 | - $media = array( 'all' ); |
|
290 | + if ($this->media_force_all) { |
|
291 | + $media = array('all'); |
|
292 | 292 | } |
293 | 293 | |
294 | - $media = apply_filters( 'autoptimize_filter_css_tagmedia', $media, $tag ); |
|
294 | + $media = apply_filters('autoptimize_filter_css_tagmedia', $media, $tag); |
|
295 | 295 | |
296 | - if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) { |
|
296 | + if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) { |
|
297 | 297 | // <link>. |
298 | - $url = current( explode( '?', $source[2], 2 ) ); |
|
299 | - $path = $this->getpath( $url ); |
|
298 | + $url = current(explode('?', $source[2], 2)); |
|
299 | + $path = $this->getpath($url); |
|
300 | 300 | |
301 | - if ( false !== $path && preg_match( '#\.css$#', $path ) ) { |
|
301 | + if (false !== $path && preg_match('#\.css$#', $path)) { |
|
302 | 302 | // Good link. |
303 | - $this->css[] = array( $media, $path ); |
|
303 | + $this->css[] = array($media, $path); |
|
304 | 304 | } else { |
305 | 305 | // Link is dynamic (.php etc). |
306 | - $new_tag = $this->optionally_defer_excluded( $tag, 'none' ); |
|
307 | - if ( '' !== $new_tag && $new_tag !== $tag ) { |
|
308 | - $this->content = str_replace( $tag, $new_tag, $this->content ); |
|
306 | + $new_tag = $this->optionally_defer_excluded($tag, 'none'); |
|
307 | + if ('' !== $new_tag && $new_tag !== $tag) { |
|
308 | + $this->content = str_replace($tag, $new_tag, $this->content); |
|
309 | 309 | } |
310 | 310 | $tag = ''; |
311 | 311 | } |
312 | 312 | } else { |
313 | 313 | // Inline css in style tags can be wrapped in comment tags, so restore comments. |
314 | - $tag = $this->restore_comments( $tag ); |
|
315 | - preg_match( '#<style.*>(.*)</style>#Usmi', $tag, $code ); |
|
314 | + $tag = $this->restore_comments($tag); |
|
315 | + preg_match('#<style.*>(.*)</style>#Usmi', $tag, $code); |
|
316 | 316 | |
317 | 317 | // And re-hide them to be able to to the removal based on tag. |
318 | - $tag = $this->hide_comments( $tag ); |
|
318 | + $tag = $this->hide_comments($tag); |
|
319 | 319 | |
320 | - if ( $this->include_inline ) { |
|
321 | - $code = preg_replace( '#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1] ); |
|
322 | - $this->css[] = array( $media, 'INLINE;' . $code ); |
|
320 | + if ($this->include_inline) { |
|
321 | + $code = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1]); |
|
322 | + $this->css[] = array($media, 'INLINE;'.$code); |
|
323 | 323 | } else { |
324 | 324 | $tag = ''; |
325 | 325 | } |
326 | 326 | } |
327 | 327 | |
328 | 328 | // Remove the original style tag. |
329 | - $this->content = str_replace( $tag, '', $this->content ); |
|
329 | + $this->content = str_replace($tag, '', $this->content); |
|
330 | 330 | } else { |
331 | - if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) { |
|
332 | - $exploded_url = explode( '?', $source[2], 2 ); |
|
331 | + if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) { |
|
332 | + $exploded_url = explode('?', $source[2], 2); |
|
333 | 333 | $url = $exploded_url[0]; |
334 | - $path = $this->getpath( $url ); |
|
334 | + $path = $this->getpath($url); |
|
335 | 335 | $new_tag = $tag; |
336 | 336 | |
337 | 337 | // Excluded CSS, minify that file: |
338 | 338 | // -> if aggregate is on and exclude minify is on |
339 | 339 | // -> if aggregate is off and the file is not in dontmove. |
340 | - if ( $path && $this->minify_excluded ) { |
|
341 | - $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false ); |
|
342 | - if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) { |
|
343 | - $minified_url = $this->minify_single( $path ); |
|
344 | - if ( ! empty( $minified_url ) ) { |
|
340 | + if ($path && $this->minify_excluded) { |
|
341 | + $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false); |
|
342 | + if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) { |
|
343 | + $minified_url = $this->minify_single($path); |
|
344 | + if (!empty($minified_url)) { |
|
345 | 345 | // Replace orig URL with cached minified URL. |
346 | - $new_tag = str_replace( $url, $minified_url, $tag ); |
|
347 | - } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) { |
|
346 | + $new_tag = str_replace($url, $minified_url, $tag); |
|
347 | + } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) { |
|
348 | 348 | // Remove the original style tag, because cache content is empty but only if |
349 | 349 | // filter is true-ed because $minified_url is also false if file is minified already. |
350 | 350 | $new_tag = ''; |
@@ -352,14 +352,14 @@ discard block |
||
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | - if ( '' !== $new_tag ) { |
|
355 | + if ('' !== $new_tag) { |
|
356 | 356 | // Optionally defer (preload) non-aggregated CSS. |
357 | - $new_tag = $this->optionally_defer_excluded( $new_tag, $url ); |
|
357 | + $new_tag = $this->optionally_defer_excluded($new_tag, $url); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | // And replace! |
361 | - if ( ( '' !== $new_tag && $new_tag !== $tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_css_remove_empty_files', false ) ) ) { |
|
362 | - $this->content = str_replace( $tag, $new_tag, $this->content ); |
|
361 | + if (('' !== $new_tag && $new_tag !== $tag) || ('' === $new_tag && apply_filters('autoptimize_filter_css_remove_empty_files', false))) { |
|
362 | + $this->content = str_replace($tag, $new_tag, $this->content); |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | } |
@@ -380,30 +380,30 @@ discard block |
||
380 | 380 | * |
381 | 381 | * @return string $new_tag |
382 | 382 | */ |
383 | - private function optionally_defer_excluded( $tag, $url = '' ) |
|
383 | + private function optionally_defer_excluded($tag, $url = '') |
|
384 | 384 | { |
385 | 385 | // Defer single CSS if "inline & defer" is ON and there is inline CSS. |
386 | - if ( ! empty( $tag ) && false === strpos( $tag, ' onload=' ) && $this->defer && ! empty( $this->defer_inline ) && apply_filters( 'autoptimize_filter_css_defer_excluded', true, $tag ) ) { |
|
386 | + if (!empty($tag) && false === strpos($tag, ' onload=') && $this->defer && !empty($this->defer_inline) && apply_filters('autoptimize_filter_css_defer_excluded', true, $tag)) { |
|
387 | 387 | // get media attribute and based on that create onload JS attribute value. |
388 | - if ( false === strpos( $tag, 'media=' ) ) { |
|
389 | - $tag = str_replace( '<link', "<link media='all'", $tag ); |
|
388 | + if (false === strpos($tag, 'media=')) { |
|
389 | + $tag = str_replace('<link', "<link media='all'", $tag); |
|
390 | 390 | } |
391 | 391 | |
392 | - preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $_medias ); |
|
392 | + preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $_medias); |
|
393 | 393 | $_media = $_medias[1]; |
394 | - $_preload_onload = autoptimizeConfig::get_ao_css_preload_onload( $_media ); |
|
394 | + $_preload_onload = autoptimizeConfig::get_ao_css_preload_onload($_media); |
|
395 | 395 | |
396 | - if ( 'print' !== $_media ) { |
|
396 | + if ('print' !== $_media) { |
|
397 | 397 | // If not media=print, adapt original <link> element for CSS to be preloaded and add <noscript>-version for fallback. |
398 | - $new_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>' . str_replace( |
|
398 | + $new_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>'.str_replace( |
|
399 | 399 | $_medias[0], |
400 | - "media='print' onload=\"" . $_preload_onload . '"', |
|
400 | + "media='print' onload=\"".$_preload_onload.'"', |
|
401 | 401 | $tag |
402 | 402 | ); |
403 | 403 | |
404 | 404 | // Optionally (but default false) preload the (excluded) CSS-file. |
405 | - if ( apply_filters( 'autoptimize_fitler_css_preload_and_print', false ) && 'none' !== $url ) { |
|
406 | - $new_tag = '<link rel="preload" as="stylesheet" href="' . $url . '"/>' . $new_tag; |
|
405 | + if (apply_filters('autoptimize_fitler_css_preload_and_print', false) && 'none' !== $url) { |
|
406 | + $new_tag = '<link rel="preload" as="stylesheet" href="'.$url.'"/>'.$new_tag; |
|
407 | 407 | } |
408 | 408 | } else { |
409 | 409 | $new_tag = $tag; |
@@ -423,22 +423,22 @@ discard block |
||
423 | 423 | * @param string $path image path. |
424 | 424 | * @return boolean |
425 | 425 | */ |
426 | - private function is_datauri_candidate( $path ) |
|
426 | + private function is_datauri_candidate($path) |
|
427 | 427 | { |
428 | 428 | // Call only once since it's called from a loop. |
429 | 429 | static $max_size = null; |
430 | - if ( null === $max_size ) { |
|
430 | + if (null === $max_size) { |
|
431 | 431 | $max_size = $this->get_datauri_maxsize(); |
432 | 432 | } |
433 | 433 | |
434 | - if ( $path && preg_match( '#\.(jpe?g|png|gif|webp|bmp)$#i', $path ) && |
|
435 | - file_exists( $path ) && is_readable( $path ) && filesize( $path ) <= $max_size ) { |
|
434 | + if ($path && preg_match('#\.(jpe?g|png|gif|webp|bmp)$#i', $path) && |
|
435 | + file_exists($path) && is_readable($path) && filesize($path) <= $max_size) { |
|
436 | 436 | |
437 | 437 | // Seems we have a candidate. |
438 | 438 | $is_candidate = true; |
439 | 439 | } else { |
440 | 440 | // Filter allows overriding default decision (which checks for local file existence). |
441 | - $is_candidate = apply_filters( 'autoptimize_filter_css_is_datauri_candidate', false, $path ); |
|
441 | + $is_candidate = apply_filters('autoptimize_filter_css_is_datauri_candidate', false, $path); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | return $is_candidate; |
@@ -463,29 +463,29 @@ discard block |
||
463 | 463 | * of thing you're probably better of building assets completely |
464 | 464 | * outside of WordPress anyway. |
465 | 465 | */ |
466 | - if ( null === $max_size ) { |
|
467 | - $max_size = (int) apply_filters( 'autoptimize_filter_css_datauri_maxsize', 4096 ); |
|
466 | + if (null === $max_size) { |
|
467 | + $max_size = (int) apply_filters('autoptimize_filter_css_datauri_maxsize', 4096); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | return $max_size; |
471 | 471 | } |
472 | 472 | |
473 | - private function check_datauri_exclude_list( $url ) |
|
473 | + private function check_datauri_exclude_list($url) |
|
474 | 474 | { |
475 | 475 | static $exclude_list = null; |
476 | 476 | $no_datauris = array(); |
477 | 477 | |
478 | 478 | // Again, skip doing certain stuff repeatedly when loop-called. |
479 | - if ( null === $exclude_list ) { |
|
480 | - $exclude_list = apply_filters( 'autoptimize_filter_css_datauri_exclude', '' ); |
|
481 | - $no_datauris = array_filter( array_map( 'trim', explode( ',', $exclude_list ) ) ); |
|
479 | + if (null === $exclude_list) { |
|
480 | + $exclude_list = apply_filters('autoptimize_filter_css_datauri_exclude', ''); |
|
481 | + $no_datauris = array_filter(array_map('trim', explode(',', $exclude_list))); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | $matched = false; |
485 | 485 | |
486 | - if ( ! empty( $exclude_list ) ) { |
|
487 | - foreach ( $no_datauris as $no_datauri ) { |
|
488 | - if ( false !== strpos( $url, $no_datauri ) ) { |
|
486 | + if (!empty($exclude_list)) { |
|
487 | + foreach ($no_datauris as $no_datauri) { |
|
488 | + if (false !== strpos($url, $no_datauri)) { |
|
489 | 489 | $matched = true; |
490 | 490 | break; |
491 | 491 | } |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | return $matched; |
496 | 496 | } |
497 | 497 | |
498 | - private function build_or_get_datauri_image( $path ) |
|
498 | + private function build_or_get_datauri_image($path) |
|
499 | 499 | { |
500 | 500 | /** |
501 | 501 | * TODO/FIXME: document the required return array format, or better yet, |
@@ -504,27 +504,27 @@ discard block |
||
504 | 504 | */ |
505 | 505 | |
506 | 506 | // Allows short-circuiting datauri generation for an image. |
507 | - $result = apply_filters( 'autoptimize_filter_css_datauri_image', array(), $path ); |
|
508 | - if ( ! empty( $result ) ) { |
|
509 | - if ( is_array( $result ) && isset( $result['full'] ) && isset( $result['base64data'] ) ) { |
|
507 | + $result = apply_filters('autoptimize_filter_css_datauri_image', array(), $path); |
|
508 | + if (!empty($result)) { |
|
509 | + if (is_array($result) && isset($result['full']) && isset($result['base64data'])) { |
|
510 | 510 | return $result; |
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | - $hash = md5( $path ); |
|
515 | - $check = new autoptimizeCache( $hash, 'img' ); |
|
516 | - if ( $check->check() ) { |
|
514 | + $hash = md5($path); |
|
515 | + $check = new autoptimizeCache($hash, 'img'); |
|
516 | + if ($check->check()) { |
|
517 | 517 | // we have the base64 image in cache. |
518 | 518 | $head_and_data = $check->retrieve(); |
519 | - $_base64data = explode( ';base64,', $head_and_data ); |
|
519 | + $_base64data = explode(';base64,', $head_and_data); |
|
520 | 520 | $base64data = $_base64data[1]; |
521 | - unset( $_base64data ); |
|
521 | + unset($_base64data); |
|
522 | 522 | } else { |
523 | 523 | // It's an image and we don't have it in cache, get the type by extension. |
524 | - $exploded_path = explode( '.', $path ); |
|
525 | - $type = end( $exploded_path ); |
|
524 | + $exploded_path = explode('.', $path); |
|
525 | + $type = end($exploded_path); |
|
526 | 526 | |
527 | - switch ( $type ) { |
|
527 | + switch ($type) { |
|
528 | 528 | case 'jpg': |
529 | 529 | case 'jpeg': |
530 | 530 | $dataurihead = 'data:image/jpeg;base64,'; |
@@ -546,13 +546,13 @@ discard block |
||
546 | 546 | } |
547 | 547 | |
548 | 548 | // Encode the data. |
549 | - $base64data = base64_encode( file_get_contents( $path ) ); |
|
550 | - $head_and_data = $dataurihead . $base64data; |
|
549 | + $base64data = base64_encode(file_get_contents($path)); |
|
550 | + $head_and_data = $dataurihead.$base64data; |
|
551 | 551 | |
552 | 552 | // Save in cache. |
553 | - $check->cache( $head_and_data, 'text/plain' ); |
|
553 | + $check->cache($head_and_data, 'text/plain'); |
|
554 | 554 | } |
555 | - unset( $check ); |
|
555 | + unset($check); |
|
556 | 556 | |
557 | 557 | return array( |
558 | 558 | 'full' => $head_and_data, |
@@ -569,13 +569,13 @@ discard block |
||
569 | 569 | * |
570 | 570 | * @return string |
571 | 571 | */ |
572 | - protected static function replace_longest_matches_first( $string, $replacements = array() ) |
|
572 | + protected static function replace_longest_matches_first($string, $replacements = array()) |
|
573 | 573 | { |
574 | - if ( ! empty( $replacements ) ) { |
|
574 | + if (!empty($replacements)) { |
|
575 | 575 | // Sort the replacements array by key length in desc order (so that the longest strings are replaced first). |
576 | - $keys = array_map( 'strlen', array_keys( $replacements ) ); |
|
577 | - array_multisort( $keys, SORT_DESC, $replacements ); |
|
578 | - $string = str_replace( array_keys( $replacements ), array_values( $replacements ), $string ); |
|
576 | + $keys = array_map('strlen', array_keys($replacements)); |
|
577 | + array_multisort($keys, SORT_DESC, $replacements); |
|
578 | + $string = str_replace(array_keys($replacements), array_values($replacements), $string); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | return $string; |
@@ -591,15 +591,15 @@ discard block |
||
591 | 591 | * |
592 | 592 | * @return string |
593 | 593 | */ |
594 | - public function replace_urls( $code = '' ) |
|
594 | + public function replace_urls($code = '') |
|
595 | 595 | { |
596 | 596 | $replacements = array(); |
597 | 597 | |
598 | - preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches ); |
|
599 | - if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) { |
|
600 | - foreach ( $url_src_matches[1] as $count => $original_url ) { |
|
598 | + preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches); |
|
599 | + if (is_array($url_src_matches) && !empty($url_src_matches)) { |
|
600 | + foreach ($url_src_matches[1] as $count => $original_url) { |
|
601 | 601 | // Removes quotes and other cruft. |
602 | - $url = trim( $original_url, " \t\n\r\0\x0B\"'" ); |
|
602 | + $url = trim($original_url, " \t\n\r\0\x0B\"'"); |
|
603 | 603 | |
604 | 604 | /** |
605 | 605 | * TODO/FIXME: Add a way for other code / callable to be called here |
@@ -617,17 +617,17 @@ discard block |
||
617 | 617 | */ |
618 | 618 | |
619 | 619 | // Do CDN replacement if needed. |
620 | - if ( ! empty( $this->cdn_url ) ) { |
|
621 | - $replacement_url = $this->url_replace_cdn( $url ); |
|
620 | + if (!empty($this->cdn_url)) { |
|
621 | + $replacement_url = $this->url_replace_cdn($url); |
|
622 | 622 | // Prepare replacements array. |
623 | - $replacements[ $url_src_matches[1][ $count ] ] = str_replace( |
|
624 | - $original_url, $replacement_url, $url_src_matches[1][ $count ] |
|
623 | + $replacements[$url_src_matches[1][$count]] = str_replace( |
|
624 | + $original_url, $replacement_url, $url_src_matches[1][$count] |
|
625 | 625 | ); |
626 | 626 | } |
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
630 | - $code = self::replace_longest_matches_first( $code, $replacements ); |
|
630 | + $code = self::replace_longest_matches_first($code, $replacements); |
|
631 | 631 | |
632 | 632 | return $code; |
633 | 633 | } |
@@ -640,26 +640,26 @@ discard block |
||
640 | 640 | * @param string $code HTML being processed to hide fonts. |
641 | 641 | * @return string |
642 | 642 | */ |
643 | - public function hide_fontface_and_maybe_cdn( $code ) |
|
643 | + public function hide_fontface_and_maybe_cdn($code) |
|
644 | 644 | { |
645 | 645 | // Proceed only if @font-face declarations exist within $code. |
646 | - preg_match_all( self::FONT_FACE_REGEX, $code, $fontfaces ); |
|
647 | - if ( isset( $fontfaces[0] ) ) { |
|
646 | + preg_match_all(self::FONT_FACE_REGEX, $code, $fontfaces); |
|
647 | + if (isset($fontfaces[0])) { |
|
648 | 648 | // Check if we need to cdn fonts or not. |
649 | - $do_font_cdn = apply_filters( 'autoptimize_filter_css_fonts_cdn', false ); |
|
649 | + $do_font_cdn = apply_filters('autoptimize_filter_css_fonts_cdn', false); |
|
650 | 650 | |
651 | - foreach ( $fontfaces[0] as $full_match ) { |
|
651 | + foreach ($fontfaces[0] as $full_match) { |
|
652 | 652 | // Keep original match so we can search/replace it. |
653 | 653 | $match_search = $full_match; |
654 | 654 | |
655 | 655 | // Do font cdn if needed. |
656 | - if ( $do_font_cdn ) { |
|
657 | - $full_match = $this->replace_urls( $full_match ); |
|
656 | + if ($do_font_cdn) { |
|
657 | + $full_match = $this->replace_urls($full_match); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Replace declaration with its base64 encoded string. |
661 | - $replacement = self::build_marker( 'FONTFACE', $full_match ); |
|
662 | - $code = str_replace( $match_search, $replacement, $code ); |
|
661 | + $replacement = self::build_marker('FONTFACE', $full_match); |
|
662 | + $code = str_replace($match_search, $replacement, $code); |
|
663 | 663 | } |
664 | 664 | } |
665 | 665 | |
@@ -673,9 +673,9 @@ discard block |
||
673 | 673 | * @param string $code HTML being processed to unhide fonts. |
674 | 674 | * @return string |
675 | 675 | */ |
676 | - public function restore_fontface( $code ) |
|
676 | + public function restore_fontface($code) |
|
677 | 677 | { |
678 | - return $this->restore_marked_content( 'FONTFACE', $code ); |
|
678 | + return $this->restore_marked_content('FONTFACE', $code); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | /** |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | * @param string $code HTML being processed rewrite assets. |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - public function rewrite_assets( $code ) |
|
687 | + public function rewrite_assets($code) |
|
688 | 688 | { |
689 | 689 | // Handle @font-face rules by hiding and processing them separately. |
690 | - $code = $this->hide_fontface_and_maybe_cdn( $code ); |
|
690 | + $code = $this->hide_fontface_and_maybe_cdn($code); |
|
691 | 691 | |
692 | 692 | /** |
693 | 693 | * TODO/FIXME: |
@@ -704,35 +704,35 @@ discard block |
||
704 | 704 | $imgreplace = array(); |
705 | 705 | |
706 | 706 | // Matches and captures anything specified within the literal `url()` and excludes those containing data: URIs. |
707 | - preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches ); |
|
708 | - if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) { |
|
709 | - foreach ( $url_src_matches[1] as $count => $original_url ) { |
|
707 | + preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches); |
|
708 | + if (is_array($url_src_matches) && !empty($url_src_matches)) { |
|
709 | + foreach ($url_src_matches[1] as $count => $original_url) { |
|
710 | 710 | // Removes quotes and other cruft. |
711 | - $url = trim( $original_url, " \t\n\r\0\x0B\"'" ); |
|
711 | + $url = trim($original_url, " \t\n\r\0\x0B\"'"); |
|
712 | 712 | |
713 | 713 | // If datauri inlining is turned on, do it. |
714 | 714 | $inlined = false; |
715 | - if ( $this->datauris ) { |
|
715 | + if ($this->datauris) { |
|
716 | 716 | $iurl = $url; |
717 | - if ( false !== strpos( $iurl, '?' ) ) { |
|
718 | - $iurl = strtok( $iurl, '?' ); |
|
717 | + if (false !== strpos($iurl, '?')) { |
|
718 | + $iurl = strtok($iurl, '?'); |
|
719 | 719 | } |
720 | 720 | |
721 | - $ipath = $this->getpath( $iurl ); |
|
721 | + $ipath = $this->getpath($iurl); |
|
722 | 722 | |
723 | - $excluded = $this->check_datauri_exclude_list( $ipath ); |
|
724 | - if ( ! $excluded ) { |
|
725 | - $is_datauri_candidate = $this->is_datauri_candidate( $ipath ); |
|
726 | - if ( $is_datauri_candidate ) { |
|
727 | - $datauri = $this->build_or_get_datauri_image( $ipath ); |
|
723 | + $excluded = $this->check_datauri_exclude_list($ipath); |
|
724 | + if (!$excluded) { |
|
725 | + $is_datauri_candidate = $this->is_datauri_candidate($ipath); |
|
726 | + if ($is_datauri_candidate) { |
|
727 | + $datauri = $this->build_or_get_datauri_image($ipath); |
|
728 | 728 | $base64data = $datauri['base64data']; |
729 | 729 | // Add it to the list for replacement. |
730 | - $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace( |
|
730 | + $imgreplace[$url_src_matches[1][$count]] = str_replace( |
|
731 | 731 | $original_url, |
732 | 732 | $datauri['full'], |
733 | - $url_src_matches[1][ $count ] |
|
733 | + $url_src_matches[1][$count] |
|
734 | 734 | ); |
735 | - $inlined = true; |
|
735 | + $inlined = true; |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | } |
@@ -743,20 +743,20 @@ discard block |
||
743 | 743 | * inlining isn't turned on, or if a resource is skipped from |
744 | 744 | * being inlined for whatever reason above. |
745 | 745 | */ |
746 | - if ( ! $inlined && ( ! empty( $this->cdn_url ) || has_filter( 'autoptimize_filter_base_replace_cdn' ) ) ) { |
|
746 | + if (!$inlined && (!empty($this->cdn_url) || has_filter('autoptimize_filter_base_replace_cdn'))) { |
|
747 | 747 | // Just do the "simple" CDN replacement. |
748 | - $replacement_url = $this->url_replace_cdn( $url ); |
|
749 | - $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace( |
|
750 | - $original_url, $replacement_url, $url_src_matches[1][ $count ] |
|
748 | + $replacement_url = $this->url_replace_cdn($url); |
|
749 | + $imgreplace[$url_src_matches[1][$count]] = str_replace( |
|
750 | + $original_url, $replacement_url, $url_src_matches[1][$count] |
|
751 | 751 | ); |
752 | 752 | } |
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
756 | - $code = self::replace_longest_matches_first( $code, $imgreplace ); |
|
756 | + $code = self::replace_longest_matches_first($code, $imgreplace); |
|
757 | 757 | |
758 | 758 | // Replace back font-face markers with actual font-face declarations. |
759 | - $code = $this->restore_fontface( $code ); |
|
759 | + $code = $this->restore_fontface($code); |
|
760 | 760 | |
761 | 761 | return $code; |
762 | 762 | } |
@@ -766,29 +766,29 @@ discard block |
||
766 | 766 | */ |
767 | 767 | public function minify() |
768 | 768 | { |
769 | - foreach ( $this->css as $group ) { |
|
770 | - list( $media, $css ) = $group; |
|
771 | - if ( preg_match( '#^INLINE;#', $css ) ) { |
|
769 | + foreach ($this->css as $group) { |
|
770 | + list($media, $css) = $group; |
|
771 | + if (preg_match('#^INLINE;#', $css)) { |
|
772 | 772 | // <style>. |
773 | - $css = preg_replace( '#^INLINE;#', '', $css ); |
|
774 | - $css = self::fixurls( ABSPATH . 'index.php', $css ); // ABSPATH already contains a trailing slash. |
|
775 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, '' ); |
|
776 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
773 | + $css = preg_replace('#^INLINE;#', '', $css); |
|
774 | + $css = self::fixurls(ABSPATH.'index.php', $css); // ABSPATH already contains a trailing slash. |
|
775 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, ''); |
|
776 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
777 | 777 | $css = $tmpstyle; |
778 | 778 | $this->alreadyminified = true; |
779 | 779 | } |
780 | 780 | } else { |
781 | 781 | // <link> |
782 | - if ( false !== $css && file_exists( $css ) && is_readable( $css ) ) { |
|
782 | + if (false !== $css && file_exists($css) && is_readable($css)) { |
|
783 | 783 | $css_path = $css; |
784 | - $css = self::fixurls( $css_path, file_get_contents( $css_path ) ); |
|
785 | - $css = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $css ); |
|
786 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, $css_path ); |
|
787 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
784 | + $css = self::fixurls($css_path, file_get_contents($css_path)); |
|
785 | + $css = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $css); |
|
786 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, $css_path); |
|
787 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
788 | 788 | $css = $tmpstyle; |
789 | 789 | $this->alreadyminified = true; |
790 | - } elseif ( $this->can_inject_late( $css_path, $css ) ) { |
|
791 | - $css = self::build_injectlater_marker( $css_path, md5( $css ) ); |
|
790 | + } elseif ($this->can_inject_late($css_path, $css)) { |
|
791 | + $css = self::build_injectlater_marker($css_path, md5($css)); |
|
792 | 792 | } |
793 | 793 | } else { |
794 | 794 | // Couldn't read CSS. Maybe getpath isn't working? |
@@ -796,12 +796,12 @@ discard block |
||
796 | 796 | } |
797 | 797 | } |
798 | 798 | |
799 | - foreach ( $media as $elem ) { |
|
800 | - if ( ! empty( $css ) ) { |
|
801 | - if ( ! isset( $this->csscode[ $elem ] ) ) { |
|
802 | - $this->csscode[ $elem ] = ''; |
|
799 | + foreach ($media as $elem) { |
|
800 | + if (!empty($css)) { |
|
801 | + if (!isset($this->csscode[$elem])) { |
|
802 | + $this->csscode[$elem] = ''; |
|
803 | 803 | } |
804 | - $this->csscode[ $elem ] .= "\n/*FILESTART*/" . $css; |
|
804 | + $this->csscode[$elem] .= "\n/*FILESTART*/".$css; |
|
805 | 805 | } |
806 | 806 | } |
807 | 807 | } |
@@ -809,133 +809,133 @@ discard block |
||
809 | 809 | // Check for duplicate code. |
810 | 810 | $md5list = array(); |
811 | 811 | $tmpcss = $this->csscode; |
812 | - foreach ( $tmpcss as $media => $code ) { |
|
813 | - $md5sum = md5( $code ); |
|
812 | + foreach ($tmpcss as $media => $code) { |
|
813 | + $md5sum = md5($code); |
|
814 | 814 | $medianame = $media; |
815 | - foreach ( $md5list as $med => $sum ) { |
|
815 | + foreach ($md5list as $med => $sum) { |
|
816 | 816 | // If same code. |
817 | - if ( $sum === $md5sum ) { |
|
817 | + if ($sum === $md5sum) { |
|
818 | 818 | // Add the merged code. |
819 | - $medianame = $med . ', ' . $media; |
|
820 | - $this->csscode[ $medianame ] = $code; |
|
821 | - $md5list[ $medianame ] = $md5list[ $med ]; |
|
822 | - unset( $this->csscode[ $med ], $this->csscode[ $media ], $md5list[ $med ] ); |
|
819 | + $medianame = $med.', '.$media; |
|
820 | + $this->csscode[$medianame] = $code; |
|
821 | + $md5list[$medianame] = $md5list[$med]; |
|
822 | + unset($this->csscode[$med], $this->csscode[$media], $md5list[$med]); |
|
823 | 823 | } |
824 | 824 | } |
825 | - $md5list[ $medianame ] = $md5sum; |
|
825 | + $md5list[$medianame] = $md5sum; |
|
826 | 826 | } |
827 | - unset( $tmpcss ); |
|
827 | + unset($tmpcss); |
|
828 | 828 | |
829 | 829 | // Manage @imports, while is for recursive import management. |
830 | - foreach ( $this->csscode as &$thiscss ) { |
|
830 | + foreach ($this->csscode as &$thiscss) { |
|
831 | 831 | // Flag to trigger import reconstitution and var to hold external imports. |
832 | 832 | $fiximports = false; |
833 | 833 | $external_imports = ''; |
834 | 834 | |
835 | 835 | // remove comments to avoid importing commented-out imports. |
836 | - $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss ); |
|
837 | - while ( preg_match_all( '#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches ) ) { |
|
838 | - foreach ( $matches[0] as $import ) { |
|
839 | - if ( $this->isremovable( $import, $this->cssremovables ) ) { |
|
840 | - $thiscss = str_replace( $import, '', $thiscss ); |
|
836 | + $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss); |
|
837 | + while (preg_match_all('#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches)) { |
|
838 | + foreach ($matches[0] as $import) { |
|
839 | + if ($this->isremovable($import, $this->cssremovables)) { |
|
840 | + $thiscss = str_replace($import, '', $thiscss); |
|
841 | 841 | $import_ok = true; |
842 | 842 | } else { |
843 | - $url = trim( preg_replace( '#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim( $import ) ), " \t\n\r\0\x0B\"'" ); |
|
844 | - $path = $this->getpath( $url ); |
|
843 | + $url = trim(preg_replace('#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim($import)), " \t\n\r\0\x0B\"'"); |
|
844 | + $path = $this->getpath($url); |
|
845 | 845 | $import_ok = false; |
846 | - if ( file_exists( $path ) && is_readable( $path ) ) { |
|
847 | - $code = addcslashes( self::fixurls( $path, file_get_contents( $path ) ), '\\' ); |
|
848 | - $code = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $code ); |
|
849 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $code, '' ); |
|
850 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
846 | + if (file_exists($path) && is_readable($path)) { |
|
847 | + $code = addcslashes(self::fixurls($path, file_get_contents($path)), '\\'); |
|
848 | + $code = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $code); |
|
849 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $code, ''); |
|
850 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
851 | 851 | $code = $tmpstyle; |
852 | 852 | $this->alreadyminified = true; |
853 | - } elseif ( $this->can_inject_late( $path, $code ) ) { |
|
854 | - $code = self::build_injectlater_marker( $path, md5( $code ) ); |
|
853 | + } elseif ($this->can_inject_late($path, $code)) { |
|
854 | + $code = self::build_injectlater_marker($path, md5($code)); |
|
855 | 855 | } |
856 | 856 | |
857 | - if ( ! empty( $code ) ) { |
|
858 | - $tmp_thiscss = preg_replace( '#(/\*FILESTART\*/.*)' . preg_quote( $import, '#' ) . '#Us', '/*FILESTART2*/' . $code . '$1', $thiscss ); |
|
859 | - if ( ! empty( $tmp_thiscss ) ) { |
|
857 | + if (!empty($code)) { |
|
858 | + $tmp_thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import, '#').'#Us', '/*FILESTART2*/'.$code.'$1', $thiscss); |
|
859 | + if (!empty($tmp_thiscss)) { |
|
860 | 860 | $thiscss = $tmp_thiscss; |
861 | 861 | $import_ok = true; |
862 | - unset( $tmp_thiscss ); |
|
862 | + unset($tmp_thiscss); |
|
863 | 863 | } |
864 | 864 | } |
865 | - unset( $code ); |
|
865 | + unset($code); |
|
866 | 866 | } |
867 | 867 | } |
868 | - if ( ! $import_ok ) { |
|
868 | + if (!$import_ok) { |
|
869 | 869 | // External imports and general fall-back. |
870 | 870 | $external_imports .= $import; |
871 | 871 | |
872 | - $thiscss = str_replace( $import, '', $thiscss ); |
|
872 | + $thiscss = str_replace($import, '', $thiscss); |
|
873 | 873 | $fiximports = true; |
874 | 874 | } |
875 | 875 | } |
876 | - $thiscss = preg_replace( '#/\*FILESTART\*/#', '', $thiscss ); |
|
877 | - $thiscss = preg_replace( '#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss ); |
|
876 | + $thiscss = preg_replace('#/\*FILESTART\*/#', '', $thiscss); |
|
877 | + $thiscss = preg_replace('#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss); |
|
878 | 878 | |
879 | 879 | // and update $thiscss_nocomments before going into next iteration in while loop. |
880 | - $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss ); |
|
880 | + $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss); |
|
881 | 881 | } |
882 | - unset( $thiscss_nocomments ); |
|
882 | + unset($thiscss_nocomments); |
|
883 | 883 | |
884 | 884 | // Add external imports to top of aggregated CSS. |
885 | - if ( $fiximports ) { |
|
886 | - $thiscss = $external_imports . $thiscss; |
|
885 | + if ($fiximports) { |
|
886 | + $thiscss = $external_imports.$thiscss; |
|
887 | 887 | } |
888 | 888 | } |
889 | - unset( $thiscss ); |
|
889 | + unset($thiscss); |
|
890 | 890 | |
891 | 891 | // $this->csscode has all the uncompressed code now. |
892 | - foreach ( $this->csscode as &$code ) { |
|
892 | + foreach ($this->csscode as &$code) { |
|
893 | 893 | // Check for already-minified code. |
894 | - $hash = md5( $code ); |
|
895 | - do_action( 'autoptimize_action_css_hash', $hash ); |
|
896 | - $ccheck = new autoptimizeCache( $hash, 'css' ); |
|
897 | - if ( $ccheck->check() ) { |
|
894 | + $hash = md5($code); |
|
895 | + do_action('autoptimize_action_css_hash', $hash); |
|
896 | + $ccheck = new autoptimizeCache($hash, 'css'); |
|
897 | + if ($ccheck->check()) { |
|
898 | 898 | $code = $ccheck->retrieve(); |
899 | - $this->hashmap[ md5( $code ) ] = $hash; |
|
899 | + $this->hashmap[md5($code)] = $hash; |
|
900 | 900 | continue; |
901 | 901 | } |
902 | - unset( $ccheck ); |
|
902 | + unset($ccheck); |
|
903 | 903 | |
904 | 904 | // Rewrite and/or inline referenced assets. |
905 | - $code = $this->rewrite_assets( $code ); |
|
905 | + $code = $this->rewrite_assets($code); |
|
906 | 906 | |
907 | 907 | // Minify. |
908 | - $code = $this->run_minifier_on( $code ); |
|
908 | + $code = $this->run_minifier_on($code); |
|
909 | 909 | |
910 | 910 | // Bring back INJECTLATER stuff. |
911 | - $code = $this->inject_minified( $code ); |
|
911 | + $code = $this->inject_minified($code); |
|
912 | 912 | |
913 | 913 | // Filter results. |
914 | - $tmp_code = apply_filters( 'autoptimize_css_after_minify', $code ); |
|
915 | - if ( ! empty( $tmp_code ) ) { |
|
914 | + $tmp_code = apply_filters('autoptimize_css_after_minify', $code); |
|
915 | + if (!empty($tmp_code)) { |
|
916 | 916 | $code = $tmp_code; |
917 | - unset( $tmp_code ); |
|
917 | + unset($tmp_code); |
|
918 | 918 | } |
919 | 919 | |
920 | - $this->hashmap[ md5( $code ) ] = $hash; |
|
920 | + $this->hashmap[md5($code)] = $hash; |
|
921 | 921 | } |
922 | 922 | |
923 | - unset( $code ); |
|
923 | + unset($code); |
|
924 | 924 | return true; |
925 | 925 | } |
926 | 926 | |
927 | - public function run_minifier_on( $code ) |
|
927 | + public function run_minifier_on($code) |
|
928 | 928 | { |
929 | - if ( ! $this->alreadyminified ) { |
|
930 | - $do_minify = apply_filters( 'autoptimize_css_do_minify', true ); |
|
929 | + if (!$this->alreadyminified) { |
|
930 | + $do_minify = apply_filters('autoptimize_css_do_minify', true); |
|
931 | 931 | |
932 | - if ( $do_minify ) { |
|
932 | + if ($do_minify) { |
|
933 | 933 | $cssmin = new autoptimizeCSSmin(); |
934 | - $tmp_code = trim( $cssmin->run( $code ) ); |
|
934 | + $tmp_code = trim($cssmin->run($code)); |
|
935 | 935 | |
936 | - if ( ! empty( $tmp_code ) ) { |
|
936 | + if (!empty($tmp_code)) { |
|
937 | 937 | $code = $tmp_code; |
938 | - unset( $tmp_code ); |
|
938 | + unset($tmp_code); |
|
939 | 939 | } |
940 | 940 | } |
941 | 941 | } |
@@ -949,18 +949,18 @@ discard block |
||
949 | 949 | public function cache() |
950 | 950 | { |
951 | 951 | // CSS cache. |
952 | - foreach ( $this->csscode as $media => $code ) { |
|
953 | - if ( empty( $code ) ) { |
|
952 | + foreach ($this->csscode as $media => $code) { |
|
953 | + if (empty($code)) { |
|
954 | 954 | continue; |
955 | 955 | } |
956 | 956 | |
957 | - $md5 = $this->hashmap[ md5( $code ) ]; |
|
958 | - $cache = new autoptimizeCache( $md5, 'css' ); |
|
959 | - if ( ! $cache->check() ) { |
|
957 | + $md5 = $this->hashmap[md5($code)]; |
|
958 | + $cache = new autoptimizeCache($md5, 'css'); |
|
959 | + if (!$cache->check()) { |
|
960 | 960 | // Cache our code. |
961 | - $cache->cache( $code, 'text/css' ); |
|
961 | + $cache->cache($code, 'text/css'); |
|
962 | 962 | } |
963 | - $this->url[ $media ] = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
963 | + $this->url[$media] = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
964 | 964 | } |
965 | 965 | } |
966 | 966 | |
@@ -970,95 +970,95 @@ discard block |
||
970 | 970 | public function getcontent() |
971 | 971 | { |
972 | 972 | // Restore the full content (only applies when "autoptimize_filter_css_justhead" filter is true). |
973 | - if ( ! empty( $this->restofcontent ) ) { |
|
973 | + if (!empty($this->restofcontent)) { |
|
974 | 974 | $this->content .= $this->restofcontent; |
975 | 975 | $this->restofcontent = ''; |
976 | 976 | } |
977 | 977 | |
978 | 978 | // type is not added by default. |
979 | 979 | $type_css = ''; |
980 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
980 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
981 | 981 | $type_css = 'type="text/css" '; |
982 | 982 | } |
983 | 983 | |
984 | 984 | // Inject the new stylesheets. |
985 | - $replace_tag = array( '<title', 'before' ); |
|
986 | - $replace_tag = apply_filters( 'autoptimize_filter_css_replacetag', $replace_tag, $this->content ); |
|
985 | + $replace_tag = array('<title', 'before'); |
|
986 | + $replace_tag = apply_filters('autoptimize_filter_css_replacetag', $replace_tag, $this->content); |
|
987 | 987 | |
988 | - if ( $this->inline ) { |
|
989 | - foreach ( $this->csscode as $media => $code ) { |
|
990 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<style ' . $type_css . 'media="' . $media . '">' . $code . '</style>' ), $replace_tag ); |
|
988 | + if ($this->inline) { |
|
989 | + foreach ($this->csscode as $media => $code) { |
|
990 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<style '.$type_css.'media="'.$media.'">'.$code.'</style>'), $replace_tag); |
|
991 | 991 | } |
992 | 992 | } else { |
993 | - if ( $this->defer ) { |
|
993 | + if ($this->defer) { |
|
994 | 994 | $preload_css_block = ''; |
995 | 995 | $inlined_ccss_block = ''; |
996 | 996 | $noscript_css_block = '<noscript id="aonoscrcss">'; |
997 | 997 | |
998 | 998 | $defer_inline_code = $this->defer_inline; |
999 | - if ( ! empty( $defer_inline_code ) ) { |
|
1000 | - if ( apply_filters( 'autoptimize_filter_css_critcss_minify', true ) ) { |
|
1001 | - $icss_hash = md5( $defer_inline_code ); |
|
1002 | - $icss_cache = new autoptimizeCache( $icss_hash, 'css' ); |
|
1003 | - if ( $icss_cache->check() ) { |
|
999 | + if (!empty($defer_inline_code)) { |
|
1000 | + if (apply_filters('autoptimize_filter_css_critcss_minify', true)) { |
|
1001 | + $icss_hash = md5($defer_inline_code); |
|
1002 | + $icss_cache = new autoptimizeCache($icss_hash, 'css'); |
|
1003 | + if ($icss_cache->check()) { |
|
1004 | 1004 | // we have the optimized inline CSS in cache. |
1005 | 1005 | $defer_inline_code = $icss_cache->retrieve(); |
1006 | 1006 | } else { |
1007 | 1007 | $cssmin = new autoptimizeCSSmin(); |
1008 | - $tmp_code = trim( $cssmin->run( $defer_inline_code ) ); |
|
1008 | + $tmp_code = trim($cssmin->run($defer_inline_code)); |
|
1009 | 1009 | |
1010 | - if ( ! empty( $tmp_code ) ) { |
|
1010 | + if (!empty($tmp_code)) { |
|
1011 | 1011 | $defer_inline_code = $tmp_code; |
1012 | - $icss_cache->cache( $defer_inline_code, 'text/css' ); |
|
1013 | - unset( $tmp_code ); |
|
1012 | + $icss_cache->cache($defer_inline_code, 'text/css'); |
|
1013 | + unset($tmp_code); |
|
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | } |
1017 | 1017 | // inlined critical css set here, but injected when full CSS is injected |
1018 | 1018 | // to avoid CSS containing SVG with <title tag receiving the full CSS link. |
1019 | - $inlined_ccss_block = '<style ' . $type_css . 'id="aoatfcss" media="all">' . $defer_inline_code . '</style>'; |
|
1019 | + $inlined_ccss_block = '<style '.$type_css.'id="aoatfcss" media="all">'.$defer_inline_code.'</style>'; |
|
1020 | 1020 | } |
1021 | 1021 | } |
1022 | 1022 | |
1023 | - foreach ( $this->url as $media => $url ) { |
|
1024 | - $url = $this->url_replace_cdn( $url ); |
|
1023 | + foreach ($this->url as $media => $url) { |
|
1024 | + $url = $this->url_replace_cdn($url); |
|
1025 | 1025 | |
1026 | 1026 | // Add the stylesheet either deferred (import at bottom) or normal links in head. |
1027 | - if ( $this->defer && 'print' !== $media ) { |
|
1028 | - $preload_onload = autoptimizeConfig::get_ao_css_preload_onload( $media ); |
|
1027 | + if ($this->defer && 'print' !== $media) { |
|
1028 | + $preload_onload = autoptimizeConfig::get_ao_css_preload_onload($media); |
|
1029 | 1029 | |
1030 | - $preload_css_block .= '<link rel="stylesheet" media="print" href="' . $url . '" onload="' . $preload_onload . '" />'; |
|
1031 | - if ( apply_filters( 'autoptimize_fitler_css_preload_and_print', false ) ) { |
|
1032 | - $preload_css_block = '<link rel="preload" as="stylesheet" href="' . $url . '"/>' . $preload_css_block; |
|
1030 | + $preload_css_block .= '<link rel="stylesheet" media="print" href="'.$url.'" onload="'.$preload_onload.'" />'; |
|
1031 | + if (apply_filters('autoptimize_fitler_css_preload_and_print', false)) { |
|
1032 | + $preload_css_block = '<link rel="preload" as="stylesheet" href="'.$url.'"/>'.$preload_css_block; |
|
1033 | 1033 | } |
1034 | - $noscript_css_block .= '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />'; |
|
1034 | + $noscript_css_block .= '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />'; |
|
1035 | 1035 | } else { |
1036 | - if ( strlen( $this->csscode[ $media ] ) > $this->cssinlinesize ) { |
|
1037 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />' ), $replace_tag ); |
|
1038 | - } elseif ( strlen( $this->csscode[ $media ] ) > 0 ) { |
|
1039 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<style ' . $type_css . 'media="' . $media . '">' . $this->csscode[ $media ] . '</style>' ), $replace_tag ); |
|
1036 | + if (strlen($this->csscode[$media]) > $this->cssinlinesize) { |
|
1037 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />'), $replace_tag); |
|
1038 | + } elseif (strlen($this->csscode[$media]) > 0) { |
|
1039 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<style '.$type_css.'media="'.$media.'">'.$this->csscode[$media].'</style>'), $replace_tag); |
|
1040 | 1040 | } |
1041 | 1041 | } |
1042 | 1042 | } |
1043 | 1043 | |
1044 | - if ( $this->defer ) { |
|
1044 | + if ($this->defer) { |
|
1045 | 1045 | $noscript_css_block .= '</noscript>'; |
1046 | 1046 | // Inject inline critical CSS, the preloaded full CSS and the noscript-CSS. |
1047 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', $inlined_ccss_block . $preload_css_block . $noscript_css_block ), $replace_tag ); |
|
1047 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', $inlined_ccss_block.$preload_css_block.$noscript_css_block), $replace_tag); |
|
1048 | 1048 | } |
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | // restore comments. |
1052 | - $this->content = $this->restore_comments( $this->content ); |
|
1052 | + $this->content = $this->restore_comments($this->content); |
|
1053 | 1053 | |
1054 | 1054 | // restore IE hacks. |
1055 | - $this->content = $this->restore_iehacks( $this->content ); |
|
1055 | + $this->content = $this->restore_iehacks($this->content); |
|
1056 | 1056 | |
1057 | 1057 | // restore (no)script. |
1058 | - $this->content = $this->restore_marked_content( 'SCRIPT', $this->content ); |
|
1058 | + $this->content = $this->restore_marked_content('SCRIPT', $this->content); |
|
1059 | 1059 | |
1060 | 1060 | // Restore noptimize. |
1061 | - $this->content = $this->restore_noptimize( $this->content ); |
|
1061 | + $this->content = $this->restore_noptimize($this->content); |
|
1062 | 1062 | |
1063 | 1063 | // Return the modified stylesheet. |
1064 | 1064 | return $this->content; |
@@ -1070,44 +1070,44 @@ discard block |
||
1070 | 1070 | * @param string $file filename of optimized CSS-file. |
1071 | 1071 | * @param string $code CSS-code in which to fix URL's. |
1072 | 1072 | */ |
1073 | - static function fixurls( $file, $code ) |
|
1073 | + static function fixurls($file, $code) |
|
1074 | 1074 | { |
1075 | 1075 | // Switch all imports to the url() syntax. |
1076 | - $code = preg_replace( '#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code ); |
|
1076 | + $code = preg_replace('#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code); |
|
1077 | 1077 | |
1078 | - if ( preg_match_all( self::ASSETS_REGEX, $code, $matches ) ) { |
|
1079 | - $file = str_replace( WP_ROOT_DIR, '/', $file ); |
|
1078 | + if (preg_match_all(self::ASSETS_REGEX, $code, $matches)) { |
|
1079 | + $file = str_replace(WP_ROOT_DIR, '/', $file); |
|
1080 | 1080 | /** |
1081 | 1081 | * Rollback as per https://github.com/futtta/autoptimize/issues/94 |
1082 | 1082 | * $file = str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', $file ); |
1083 | 1083 | */ |
1084 | - $dir = dirname( $file ); // Like /themes/expound/css. |
|
1084 | + $dir = dirname($file); // Like /themes/expound/css. |
|
1085 | 1085 | |
1086 | 1086 | /** |
1087 | 1087 | * $dir should not contain backslashes, since it's used to replace |
1088 | 1088 | * urls, but it can contain them when running on Windows because |
1089 | 1089 | * fixurls() is sometimes called with `ABSPATH . 'index.php'` |
1090 | 1090 | */ |
1091 | - $dir = str_replace( '\\', '/', $dir ); |
|
1092 | - unset( $file ); // not used below at all. |
|
1091 | + $dir = str_replace('\\', '/', $dir); |
|
1092 | + unset($file); // not used below at all. |
|
1093 | 1093 | |
1094 | 1094 | $replace = array(); |
1095 | - foreach ( $matches[1] as $k => $url ) { |
|
1095 | + foreach ($matches[1] as $k => $url) { |
|
1096 | 1096 | // Remove quotes. |
1097 | - $url = trim( $url, " \t\n\r\0\x0B\"'" ); |
|
1098 | - $no_q_url = trim( $url, "\"'" ); |
|
1099 | - if ( $url !== $no_q_url ) { |
|
1097 | + $url = trim($url, " \t\n\r\0\x0B\"'"); |
|
1098 | + $no_q_url = trim($url, "\"'"); |
|
1099 | + if ($url !== $no_q_url) { |
|
1100 | 1100 | $removed_quotes = true; |
1101 | 1101 | } else { |
1102 | 1102 | $removed_quotes = false; |
1103 | 1103 | } |
1104 | 1104 | |
1105 | - if ( '' === $no_q_url ) { |
|
1105 | + if ('' === $no_q_url) { |
|
1106 | 1106 | continue; |
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | $url = $no_q_url; |
1110 | - if ( '/' === $url[0] || preg_match( '#^(https?://|ftp://|data:)#i', $url ) ) { |
|
1110 | + if ('/' === $url[0] || preg_match('#^(https?://|ftp://|data:)#i', $url)) { |
|
1111 | 1111 | // URL is protocol-relative, host-relative or something we don't touch. |
1112 | 1112 | continue; |
1113 | 1113 | } else { // Relative URL. |
@@ -1116,49 +1116,49 @@ discard block |
||
1116 | 1116 | * rollback as per https://github.com/futtta/autoptimize/issues/94 |
1117 | 1117 | * $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_CONTENT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) ); |
1118 | 1118 | */ |
1119 | - $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_ROOT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) ); |
|
1120 | - $newurl = apply_filters( 'autoptimize_filter_css_fixurl_newurl', $newurl ); |
|
1119 | + $newurl = preg_replace('/https?:/', '', str_replace(' ', '%20', AUTOPTIMIZE_WP_ROOT_URL.str_replace('//', '/', $dir.'/'.$url))); |
|
1120 | + $newurl = apply_filters('autoptimize_filter_css_fixurl_newurl', $newurl); |
|
1121 | 1121 | |
1122 | 1122 | /** |
1123 | 1123 | * Hash the url + whatever was behind potentially for replacement |
1124 | 1124 | * We must do this, or different css classes referencing the same bg image (but |
1125 | 1125 | * different parts of it, say, in sprites and such) loose their stuff... |
1126 | 1126 | */ |
1127 | - $hash = md5( $url . $matches[2][ $k ] ); |
|
1128 | - $code = str_replace( $matches[0][ $k ], $hash, $code ); |
|
1127 | + $hash = md5($url.$matches[2][$k]); |
|
1128 | + $code = str_replace($matches[0][$k], $hash, $code); |
|
1129 | 1129 | |
1130 | - if ( $removed_quotes ) { |
|
1131 | - $replace[ $hash ] = "url('" . $newurl . "')" . $matches[2][ $k ]; |
|
1130 | + if ($removed_quotes) { |
|
1131 | + $replace[$hash] = "url('".$newurl."')".$matches[2][$k]; |
|
1132 | 1132 | } else { |
1133 | - $replace[ $hash ] = 'url(' . $newurl . ')' . $matches[2][ $k ]; |
|
1133 | + $replace[$hash] = 'url('.$newurl.')'.$matches[2][$k]; |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - $code = self::replace_longest_matches_first( $code, $replace ); |
|
1138 | + $code = self::replace_longest_matches_first($code, $replace); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | return $code; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | - private function ismovable( $tag ) |
|
1144 | + private function ismovable($tag) |
|
1145 | 1145 | { |
1146 | - if ( ! $this->aggregate ) { |
|
1146 | + if (!$this->aggregate) { |
|
1147 | 1147 | return false; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - if ( ! empty( $this->allowlist ) ) { |
|
1151 | - foreach ( $this->allowlist as $match ) { |
|
1152 | - if ( false !== strpos( $tag, $match ) ) { |
|
1150 | + if (!empty($this->allowlist)) { |
|
1151 | + foreach ($this->allowlist as $match) { |
|
1152 | + if (false !== strpos($tag, $match)) { |
|
1153 | 1153 | return true; |
1154 | 1154 | } |
1155 | 1155 | } |
1156 | 1156 | // no match with allowlist. |
1157 | 1157 | return false; |
1158 | 1158 | } else { |
1159 | - if ( is_array( $this->dontmove ) && ! empty( $this->dontmove ) ) { |
|
1160 | - foreach ( $this->dontmove as $match ) { |
|
1161 | - if ( false !== strpos( $tag, $match ) ) { |
|
1159 | + if (is_array($this->dontmove) && !empty($this->dontmove)) { |
|
1160 | + foreach ($this->dontmove as $match) { |
|
1161 | + if (false !== strpos($tag, $match)) { |
|
1162 | 1162 | // Matched something. |
1163 | 1163 | return false; |
1164 | 1164 | } |
@@ -1170,22 +1170,22 @@ discard block |
||
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - private function can_inject_late( $css_path, $css ) |
|
1173 | + private function can_inject_late($css_path, $css) |
|
1174 | 1174 | { |
1175 | - $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false, $css_path ); |
|
1176 | - if ( true !== $this->inject_min_late ) { |
|
1175 | + $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $css_path); |
|
1176 | + if (true !== $this->inject_min_late) { |
|
1177 | 1177 | // late-inject turned off. |
1178 | 1178 | return false; |
1179 | - } elseif ( ( false === strpos( $css_path, 'min.css' ) ) && ( str_replace( $consider_minified_array, '', $css_path ) === $css_path ) ) { |
|
1179 | + } elseif ((false === strpos($css_path, 'min.css')) && (str_replace($consider_minified_array, '', $css_path) === $css_path)) { |
|
1180 | 1180 | // file not minified based on filename & filter. |
1181 | 1181 | return false; |
1182 | - } elseif ( false !== strpos( $css, '@import' ) ) { |
|
1182 | + } elseif (false !== strpos($css, '@import')) { |
|
1183 | 1183 | // can't late-inject files with imports as those need to be aggregated. |
1184 | 1184 | return false; |
1185 | - } elseif ( ( false !== strpos( $css, '@font-face' ) ) && ( apply_filters( 'autoptimize_filter_css_fonts_cdn', false ) === true ) && ( ! empty( $this->cdn_url ) ) ) { |
|
1185 | + } elseif ((false !== strpos($css, '@font-face')) && (apply_filters('autoptimize_filter_css_fonts_cdn', false) === true) && (!empty($this->cdn_url))) { |
|
1186 | 1186 | // don't late-inject CSS with font-src's if fonts are set to be CDN'ed. |
1187 | 1187 | return false; |
1188 | - } elseif ( ( ( true == $this->datauris ) || ( ! empty( $this->cdn_url ) ) ) && preg_match( '#background[^;}]*url\(#Ui', $css ) ) { |
|
1188 | + } elseif (((true == $this->datauris) || (!empty($this->cdn_url))) && preg_match('#background[^;}]*url\(#Ui', $css)) { |
|
1189 | 1189 | // don't late-inject CSS with images if CDN is set OR if image inlining is on. |
1190 | 1190 | return false; |
1191 | 1191 | } else { |
@@ -1203,44 +1203,44 @@ discard block |
||
1203 | 1203 | * |
1204 | 1204 | * @return bool|string Url pointing to the minified css file or false. |
1205 | 1205 | */ |
1206 | - public function minify_single( $filepath, $cache_miss = false ) |
|
1206 | + public function minify_single($filepath, $cache_miss = false) |
|
1207 | 1207 | { |
1208 | - $contents = $this->prepare_minify_single( $filepath ); |
|
1208 | + $contents = $this->prepare_minify_single($filepath); |
|
1209 | 1209 | |
1210 | - if ( empty( $contents ) ) { |
|
1210 | + if (empty($contents)) { |
|
1211 | 1211 | return false; |
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // Check cache. |
1215 | - $hash = 'single_' . md5( $contents ); |
|
1216 | - $cache = new autoptimizeCache( $hash, 'css' ); |
|
1217 | - do_action( 'autoptimize_action_css_hash', $hash ); |
|
1215 | + $hash = 'single_'.md5($contents); |
|
1216 | + $cache = new autoptimizeCache($hash, 'css'); |
|
1217 | + do_action('autoptimize_action_css_hash', $hash); |
|
1218 | 1218 | |
1219 | 1219 | // If not in cache already, minify... |
1220 | - if ( ! $cache->check() || $cache_miss ) { |
|
1220 | + if (!$cache->check() || $cache_miss) { |
|
1221 | 1221 | // Fixurls... |
1222 | - $contents = self::fixurls( $filepath, $contents ); |
|
1222 | + $contents = self::fixurls($filepath, $contents); |
|
1223 | 1223 | // CDN-replace any referenced assets if needed... |
1224 | - $contents = $this->hide_fontface_and_maybe_cdn( $contents ); |
|
1225 | - $contents = $this->replace_urls( $contents ); |
|
1226 | - $contents = $this->restore_fontface( $contents ); |
|
1224 | + $contents = $this->hide_fontface_and_maybe_cdn($contents); |
|
1225 | + $contents = $this->replace_urls($contents); |
|
1226 | + $contents = $this->restore_fontface($contents); |
|
1227 | 1227 | // Now minify... |
1228 | 1228 | $cssmin = new autoptimizeCSSmin(); |
1229 | - $contents = trim( $cssmin->run( $contents ) ); |
|
1229 | + $contents = trim($cssmin->run($contents)); |
|
1230 | 1230 | |
1231 | 1231 | // Check if minified cache content is empty. |
1232 | - if ( empty( $contents ) ) { |
|
1232 | + if (empty($contents)) { |
|
1233 | 1233 | return false; |
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | // Filter contents of excluded minified CSS. |
1237 | - $contents = apply_filters( 'autoptimize_filter_css_single_after_minify', $contents ); |
|
1237 | + $contents = apply_filters('autoptimize_filter_css_single_after_minify', $contents); |
|
1238 | 1238 | |
1239 | 1239 | // Store in cache. |
1240 | - $cache->cache( $contents, 'text/css' ); |
|
1240 | + $cache->cache($contents, 'text/css'); |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | - $url = $this->build_minify_single_url( $cache ); |
|
1243 | + $url = $this->build_minify_single_url($cache); |
|
1244 | 1244 | |
1245 | 1245 | return $url; |
1246 | 1246 | } |
@@ -1260,20 +1260,20 @@ discard block |
||
1260 | 1260 | return $this->options; |
1261 | 1261 | } |
1262 | 1262 | |
1263 | - public function replaceOptions( $options ) |
|
1263 | + public function replaceOptions($options) |
|
1264 | 1264 | { |
1265 | 1265 | $this->options = $options; |
1266 | 1266 | } |
1267 | 1267 | |
1268 | - public function setOption( $name, $value ) |
|
1268 | + public function setOption($name, $value) |
|
1269 | 1269 | { |
1270 | - $this->options[ $name ] = $value; |
|
1270 | + $this->options[$name] = $value; |
|
1271 | 1271 | $this->$name = $value; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | - public function getOption( $name ) |
|
1274 | + public function getOption($name) |
|
1275 | 1275 | { |
1276 | - return $this->options[ $name ]; |
|
1276 | + return $this->options[$name]; |
|
1277 | 1277 | } |
1278 | 1278 | |
1279 | 1279 | /** |
@@ -1287,11 +1287,11 @@ discard block |
||
1287 | 1287 | * @param string $css the to be sanitized CSS |
1288 | 1288 | * @return string sanitized CSS. |
1289 | 1289 | */ |
1290 | - public static function sanitize_css( $css ) |
|
1290 | + public static function sanitize_css($css) |
|
1291 | 1291 | { |
1292 | - $css = strip_tags( $css ); |
|
1293 | - if ( strpos( $css, '<' ) !== false ) { |
|
1294 | - $css = preg_replace( '#<(\/?\w+)#', '\00003C$1', $css ); |
|
1292 | + $css = strip_tags($css); |
|
1293 | + if (strpos($css, '<') !== false) { |
|
1294 | + $css = preg_replace('#<(\/?\w+)#', '\00003C$1', $css); |
|
1295 | 1295 | } |
1296 | 1296 | return $css; |
1297 | 1297 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Critical CSS Options page. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -17,34 +17,34 @@ discard block |
||
17 | 17 | |
18 | 18 | public function __construct() |
19 | 19 | { |
20 | - $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http ); |
|
20 | + $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http); |
|
21 | 21 | $this->run(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | protected function enabled() |
25 | 25 | { |
26 | - return apply_filters( 'autoptimize_filter_show_criticalcss_tabs', true ); |
|
26 | + return apply_filters('autoptimize_filter_show_criticalcss_tabs', true); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function run() |
30 | 30 | { |
31 | - if ( $this->enabled() ) { |
|
32 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 ); |
|
33 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) ); |
|
31 | + if ($this->enabled()) { |
|
32 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1); |
|
33 | + add_action('admin_enqueue_scripts', array($this, 'admin_assets')); |
|
34 | 34 | |
35 | - if ( $this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
36 | - add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) ); |
|
35 | + if ($this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
36 | + add_action('network_admin_menu', array($this, 'add_critcss_admin_menu')); |
|
37 | 37 | } else { |
38 | - add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) ); |
|
38 | + add_action('admin_menu', array($this, 'add_critcss_admin_menu')); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax(); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | - public function add_critcss_tabs( $in ) |
|
45 | + public function add_critcss_tabs($in) |
|
46 | 46 | { |
47 | - $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) ); |
|
47 | + $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize'))); |
|
48 | 48 | |
49 | 49 | return $in; |
50 | 50 | } |
@@ -52,66 +52,66 @@ discard block |
||
52 | 52 | public function add_critcss_admin_menu() |
53 | 53 | { |
54 | 54 | // Register settings. |
55 | - register_setting( 'ao_ccss_options_group', 'autoptimize_css_defer_inline' ); |
|
56 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rules' ); |
|
57 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' ); |
|
58 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' ); |
|
59 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' ); |
|
60 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' ); |
|
61 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rtimelimit' ); |
|
62 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_noptimize' ); |
|
63 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_debug' ); |
|
64 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_key' ); |
|
65 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_keyst' ); |
|
66 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_loggedin' ); |
|
67 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_forcepath' ); |
|
68 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_deferjquery' ); |
|
69 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_domain' ); |
|
70 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_unloadccss' ); |
|
55 | + register_setting('ao_ccss_options_group', 'autoptimize_css_defer_inline'); |
|
56 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_rules'); |
|
57 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_additional'); |
|
58 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_queue'); |
|
59 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_viewport'); |
|
60 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_finclude'); |
|
61 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_rtimelimit'); |
|
62 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_noptimize'); |
|
63 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_debug'); |
|
64 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_key'); |
|
65 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_keyst'); |
|
66 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_loggedin'); |
|
67 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_forcepath'); |
|
68 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_deferjquery'); |
|
69 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_domain'); |
|
70 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_unloadccss'); |
|
71 | 71 | |
72 | 72 | // And add submenu-page. |
73 | - add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) ); |
|
73 | + add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page')); |
|
74 | 74 | } |
75 | 75 | |
76 | - public function admin_assets( $hook ) { |
|
76 | + public function admin_assets($hook) { |
|
77 | 77 | // Return if plugin is not hooked. |
78 | - if ( 'settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook ) { |
|
78 | + if ('settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook) { |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | 82 | // Stylesheets to add. |
83 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
84 | - wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) ); |
|
85 | - wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) ); |
|
83 | + wp_enqueue_style('wp-jquery-ui-dialog'); |
|
84 | + wp_enqueue_style('ao-tablesorter', plugins_url('critcss-inc/css/ao-tablesorter/style.css', __FILE__)); |
|
85 | + wp_enqueue_style('ao-ccss-admin-css', plugins_url('critcss-inc/css/admin_styles.css', __FILE__)); |
|
86 | 86 | |
87 | 87 | // Scripts to add. |
88 | - wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) ); |
|
89 | - wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true ); |
|
90 | - wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
91 | - wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
88 | + wp_enqueue_script('jquery-ui-dialog', array('jquery')); |
|
89 | + wp_enqueue_script('md5', plugins_url('critcss-inc/js/md5.min.js', __FILE__), null, null, true); |
|
90 | + wp_enqueue_script('tablesorter', plugins_url('critcss-inc/js/jquery.tablesorter.min.js', __FILE__), array('jquery'), null, true); |
|
91 | + wp_enqueue_script('ao-ccss-admin-license', plugins_url('critcss-inc/js/admin_settings.js', __FILE__), array('jquery'), null, true); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | public function ao_criticalcsssettings_page() |
95 | 95 | { |
96 | 96 | // these are not OO yet, simply require for now. |
97 | - require_once( 'critcss-inc/admin_settings_rules.php' ); |
|
98 | - require_once( 'critcss-inc/admin_settings_queue.php' ); |
|
99 | - require_once( 'critcss-inc/admin_settings_key.php' ); |
|
100 | - require_once( 'critcss-inc/admin_settings_adv.php' ); |
|
101 | - require_once( 'critcss-inc/admin_settings_explain.php' ); |
|
97 | + require_once('critcss-inc/admin_settings_rules.php'); |
|
98 | + require_once('critcss-inc/admin_settings_queue.php'); |
|
99 | + require_once('critcss-inc/admin_settings_key.php'); |
|
100 | + require_once('critcss-inc/admin_settings_adv.php'); |
|
101 | + require_once('critcss-inc/admin_settings_explain.php'); |
|
102 | 102 | |
103 | 103 | // fetch all options at once and populate them individually explicitely as globals. |
104 | 104 | $all_options = autoptimizeCriticalCSSBase::fetch_options(); |
105 | - foreach ( $all_options as $_option => $_value ) { |
|
105 | + foreach ($all_options as $_option => $_value) { |
|
106 | 106 | global ${$_option}; |
107 | 107 | ${$_option} = $_value; |
108 | 108 | } |
109 | 109 | ?> |
110 | - <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script> |
|
110 | + <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script> |
|
111 | 111 | <div class="wrap"> |
112 | 112 | <div id="autoptimize_main"> |
113 | 113 | <div id="ao_title_and_button"> |
114 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
114 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
115 | 115 | </div> |
116 | 116 | |
117 | 117 | <?php |
@@ -119,39 +119,39 @@ discard block |
||
119 | 119 | echo autoptimizeConfig::ao_admin_tabs(); |
120 | 120 | |
121 | 121 | // Make sure dir to write ao_ccss exists and is writable. |
122 | - if ( ! is_dir( AO_CCSS_DIR ) ) { |
|
123 | - $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine |
|
122 | + if (!is_dir(AO_CCSS_DIR)) { |
|
123 | + $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine |
|
124 | 124 | } else { |
125 | 125 | $mkdirresp = true; |
126 | 126 | } |
127 | 127 | |
128 | 128 | // Make sure our index.html is there. |
129 | - if ( ! is_file( AO_CCSS_DIR . 'index.html' ) ) { |
|
130 | - $fileresp = file_put_contents( AO_CCSS_DIR . 'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); |
|
129 | + if (!is_file(AO_CCSS_DIR.'index.html')) { |
|
130 | + $fileresp = file_put_contents(AO_CCSS_DIR.'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>'); |
|
131 | 131 | } else { |
132 | 132 | $fileresp = true; |
133 | 133 | } |
134 | 134 | |
135 | 135 | // Warn if we could not create those files. |
136 | - if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) { |
|
136 | + if ((!$mkdirresp) || (!$fileresp)) { |
|
137 | 137 | ?> |
138 | 138 | <div class="notice-error notice"><p> |
139 | 139 | <?php |
140 | - _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' ); |
|
140 | + _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize'); |
|
141 | 141 | ?> |
142 | 142 | </p></div> |
143 | 143 | <?php |
144 | 144 | } |
145 | 145 | |
146 | 146 | // Check for "inline & defer CSS" being active in Autoptimize. |
147 | - if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) { |
|
148 | - if ( empty( $ao_ccss_keyst ) ) { |
|
147 | + if (!empty($ao_ccss_key) && !$ao_css_defer) { |
|
148 | + if (empty($ao_ccss_keyst)) { |
|
149 | 149 | // no keystate so likely in activation-process of CCSS, let's enable "inline & defer CSS" immediately to make things easier! |
150 | - autoptimizeOptionWrapper::update_option( 'autoptimize_css_defer', 'on' ); |
|
150 | + autoptimizeOptionWrapper::update_option('autoptimize_css_defer', 'on'); |
|
151 | 151 | ?> |
152 | 152 | <div class="notice-info notice"><p> |
153 | 153 | <?php |
154 | - _e( "The \"Inline and Defer CSS\" option was activated to allow critical CSS to be used.", 'autoptimize' ); |
|
154 | + _e("The \"Inline and Defer CSS\" option was activated to allow critical CSS to be used.", 'autoptimize'); |
|
155 | 155 | ?> |
156 | 156 | </p></div> |
157 | 157 | <?php |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | ?> |
161 | 161 | <div class="notice-warning notice"><p> |
162 | 162 | <?php |
163 | - _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to ensure critical CSS is used on the front-end.", 'autoptimize' ); |
|
163 | + _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to ensure critical CSS is used on the front-end.", 'autoptimize'); |
|
164 | 164 | ?> |
165 | 165 | </p></div> |
166 | 166 | <?php |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | // check if WordPress cron is disabled and warn if so. |
171 | - if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) { |
|
171 | + if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) { |
|
172 | 172 | ?> |
173 | 173 | <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p> |
174 | 174 | <?php |
175 | - _e( 'WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' ); |
|
175 | + _e('WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize'); |
|
176 | 176 | ?> |
177 | 177 | </p></div> |
178 | 178 | <?php |
@@ -180,24 +180,24 @@ discard block |
||
180 | 180 | |
181 | 181 | // warn if it looks as though the queue processing job looks isn't running |
182 | 182 | // but store result in transient as to not to have to go through 2 arrays each and every time. |
183 | - $_warn_cron = get_transient( 'ao_ccss_cronwarning' ); |
|
184 | - if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) { |
|
183 | + $_warn_cron = get_transient('ao_ccss_cronwarning'); |
|
184 | + if (!empty($ao_ccss_key) && false === $_warn_cron) { |
|
185 | 185 | $_jobs_all_new = true; |
186 | - $_oldest_job_timestamp = microtime( true ); // now. |
|
186 | + $_oldest_job_timestamp = microtime(true); // now. |
|
187 | 187 | $_jobs_too_old = true; |
188 | 188 | |
189 | 189 | // go over queue array. |
190 | - if ( empty( $ao_ccss_queue ) ) { |
|
190 | + if (empty($ao_ccss_queue)) { |
|
191 | 191 | // no jobs, then no warning. |
192 | 192 | $_jobs_all_new = false; |
193 | 193 | } else { |
194 | - foreach ( $ao_ccss_queue as $job ) { |
|
195 | - if ( $job['jctime'] < $_oldest_job_timestamp ) { |
|
194 | + foreach ($ao_ccss_queue as $job) { |
|
195 | + if ($job['jctime'] < $_oldest_job_timestamp) { |
|
196 | 196 | // we need to catch the oldest job's timestamp. |
197 | 197 | $_oldest_job_timestamp = $job['jctime']; |
198 | 198 | } |
199 | 199 | |
200 | - if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) { |
|
200 | + if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) { |
|
201 | 201 | // we have a non-"NEW" job which is not our pending firstrun job either, break the loop. |
202 | 202 | $_jobs_all_new = false; |
203 | 203 | break; |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | // is the oldest job too old (4h)? |
209 | - if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) { |
|
209 | + if ($_oldest_job_timestamp > microtime(true) - 60*60*4) { |
|
210 | 210 | $_jobs_too_old = false; |
211 | 211 | } |
212 | 212 | |
213 | - if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) { |
|
213 | + if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) { |
|
214 | 214 | $_warn_cron = 'on'; |
215 | 215 | $_transient_multiplier = 1; // store for 1 hour. |
216 | 216 | } else { |
@@ -218,35 +218,35 @@ discard block |
||
218 | 218 | $_transient_multiplier = 4; // store for 4 hours. |
219 | 219 | } |
220 | 220 | // and set transient. |
221 | - set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS ); |
|
221 | + set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS); |
|
222 | 222 | } |
223 | 223 | |
224 | - if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) { |
|
224 | + if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) { |
|
225 | 225 | ?> |
226 | 226 | <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p> |
227 | 227 | <?php |
228 | - _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' ); |
|
228 | + _e('It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize'); |
|
229 | 229 | ?> |
230 | 230 | </p></div> |
231 | 231 | <?php |
232 | - } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) { |
|
232 | + } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) { |
|
233 | 233 | ?> |
234 | 234 | <div class="notice-success notice"><p> |
235 | 235 | <?php |
236 | - _e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' ); |
|
236 | + _e('Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize'); |
|
237 | 237 | echo ' '; |
238 | - _e( 'In the meantime you might want to <strong>edit default rule CSS now</strong>, to avoid all CSS being inlined when no (applicable) rules are found.', 'autoptimize' ); |
|
238 | + _e('In the meantime you might want to <strong>edit default rule CSS now</strong>, to avoid all CSS being inlined when no (applicable) rules are found.', 'autoptimize'); |
|
239 | 239 | ?> |
240 | 240 | </p></div> |
241 | 241 | <?php |
242 | 242 | } |
243 | 243 | |
244 | 244 | // warn if service is down. |
245 | - if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) { |
|
245 | + if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) { |
|
246 | 246 | ?> |
247 | 247 | <div class="notice-warning notice"><p> |
248 | 248 | <?php |
249 | - _e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' ); |
|
249 | + _e('The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize'); |
|
250 | 250 | ?> |
251 | 251 | </p></div> |
252 | 252 | <?php |
@@ -254,12 +254,12 @@ discard block |
||
254 | 254 | |
255 | 255 | // warn if too many rules (based on length of ao_ccss_rules option) as that might cause issues at e.g. wpengine |
256 | 256 | // see https://wpengine.com/support/database-optimization-best-practices/#Autoloaded_Data |
257 | - $_raw_rules_length = strlen( get_option( 'autoptimize_ccss_rules', '') ); |
|
258 | - if ( $_raw_rules_length > apply_filters( 'autoptimize_ccss_rules_length_warning', 500000 ) ) { |
|
257 | + $_raw_rules_length = strlen(get_option('autoptimize_ccss_rules', '')); |
|
258 | + if ($_raw_rules_length > apply_filters('autoptimize_ccss_rules_length_warning', 500000)) { |
|
259 | 259 | ?> |
260 | 260 | <div class="notice-warning notice"><p> |
261 | 261 | <?php |
262 | - _e( 'It looks like the amount of Critical CSS rules is very high, it is recommended to reconfigure Autoptimize (e.g. by manually creating broader rules) to ensure less rules are created.', 'autoptimize' ); |
|
262 | + _e('It looks like the amount of Critical CSS rules is very high, it is recommended to reconfigure Autoptimize (e.g. by manually creating broader rules) to ensure less rules are created.', 'autoptimize'); |
|
263 | 263 | ?> |
264 | 264 | </p></div> |
265 | 265 | <?php |
@@ -269,24 +269,24 @@ discard block |
||
269 | 269 | ?> |
270 | 270 | <form id="settings" method="post" action="options.php"> |
271 | 271 | <?php |
272 | - settings_fields( 'ao_ccss_options_group' ); |
|
272 | + settings_fields('ao_ccss_options_group'); |
|
273 | 273 | |
274 | 274 | // Get API key status. |
275 | - $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true ); |
|
275 | + $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true); |
|
276 | 276 | |
277 | - if ( $this->is_multisite_network_admin() ) { |
|
277 | + if ($this->is_multisite_network_admin()) { |
|
278 | 278 | ?> |
279 | 279 | <ul id="key-panel"> |
280 | 280 | <li class="itemDetail"> |
281 | 281 | <?php |
282 | 282 | // translators: the placesholder is for a line of code in wp-config.php. |
283 | - echo sprintf( __( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' ); |
|
283 | + echo sprintf(__('<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize'), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>'); |
|
284 | 284 | ?> |
285 | 285 | </li> |
286 | 286 | </ul> |
287 | 287 | <?php |
288 | 288 | } else { |
289 | - if ( 'valid' == $key['status'] ) { |
|
289 | + if ('valid' == $key['status']) { |
|
290 | 290 | // If key status is valid, render other panels. |
291 | 291 | // Render rules section. |
292 | 292 | ao_ccss_render_rules(); |
@@ -303,23 +303,23 @@ discard block |
||
303 | 303 | $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport(); |
304 | 304 | |
305 | 305 | // Add hidden fields. |
306 | - echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>"; |
|
307 | - echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>"; |
|
308 | - echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">'; |
|
309 | - echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">'; |
|
310 | - echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . esc_attr( $ao_ccss_finclude ) . '">'; |
|
311 | - echo '<input class="hidden" name="autoptimize_ccss_rtimelimit" value="' . $ao_ccss_rtimelimit . '">'; |
|
312 | - echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">'; |
|
313 | - echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">'; |
|
314 | - echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">'; |
|
315 | - echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">'; |
|
316 | - echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">'; |
|
306 | + echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>"; |
|
307 | + echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>"; |
|
308 | + echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">'; |
|
309 | + echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">'; |
|
310 | + echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.esc_attr($ao_ccss_finclude).'">'; |
|
311 | + echo '<input class="hidden" name="autoptimize_ccss_rtimelimit" value="'.$ao_ccss_rtimelimit.'">'; |
|
312 | + echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">'; |
|
313 | + echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">'; |
|
314 | + echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">'; |
|
315 | + echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">'; |
|
316 | + echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">'; |
|
317 | 317 | } |
318 | 318 | // Render key panel unconditionally. |
319 | - ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] ); |
|
319 | + ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']); |
|
320 | 320 | ?> |
321 | 321 | <p class="submit left"> |
322 | - <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /> |
|
322 | + <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /> |
|
323 | 323 | </p> |
324 | 324 | <?php |
325 | 325 | } |
@@ -337,31 +337,31 @@ discard block |
||
337 | 337 | }); |
338 | 338 | } |
339 | 339 | </script> |
340 | - <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>> |
|
341 | - <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span> |
|
342 | - <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" /> |
|
340 | + <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>> |
|
341 | + <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span> |
|
342 | + <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" /> |
|
343 | 343 | <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" /> |
344 | 344 | </form> |
345 | 345 | <div id="importdialog"></div> |
346 | 346 | </div><!-- /#autoptimize_main --> |
347 | 347 | </div><!-- /#wrap --> |
348 | 348 | <?php |
349 | - if ( ! $this->is_multisite_network_admin() ) { |
|
349 | + if (!$this->is_multisite_network_admin()) { |
|
350 | 350 | // Include debug panel if debug mode is enable. |
351 | - if ( $ao_ccss_debug ) { |
|
351 | + if ($ao_ccss_debug) { |
|
352 | 352 | ?> |
353 | 353 | <div id="debug"> |
354 | 354 | <?php |
355 | 355 | // Include debug panel. |
356 | - include( 'critcss-inc/admin_settings_debug.php' ); |
|
356 | + include('critcss-inc/admin_settings_debug.php'); |
|
357 | 357 | ?> |
358 | 358 | </div><!-- /#debug --> |
359 | 359 | <?php |
360 | 360 | } |
361 | 361 | echo '<script>'; |
362 | - include( 'critcss-inc/admin_settings_rules.js.php' ); |
|
363 | - include( 'critcss-inc/admin_settings_queue.js.php' ); |
|
364 | - include( 'critcss-inc/admin_settings_impexp.js.php' ); |
|
362 | + include('critcss-inc/admin_settings_rules.js.php'); |
|
363 | + include('critcss-inc/admin_settings_queue.js.php'); |
|
364 | + include('critcss-inc/admin_settings_impexp.js.php'); |
|
365 | 365 | echo '</script>'; |
366 | 366 | } |
367 | 367 | } |
@@ -369,19 +369,19 @@ discard block |
||
369 | 369 | public static function ao_ccss_has_autorules() { |
370 | 370 | static $_has_auto_rules = null; |
371 | 371 | |
372 | - if ( null === $_has_auto_rules ) { |
|
372 | + if (null === $_has_auto_rules) { |
|
373 | 373 | global $ao_ccss_rules; |
374 | 374 | $_has_auto_rules = false; |
375 | - if ( ! empty( $ao_ccss_rules ) ) { |
|
376 | - foreach ( array( 'types', 'paths' ) as $_typat ) { |
|
377 | - foreach ( $ao_ccss_rules[ $_typat ] as $rule ) { |
|
378 | - if ( ! empty( $rule['hash'] ) ) { |
|
375 | + if (!empty($ao_ccss_rules)) { |
|
376 | + foreach (array('types', 'paths') as $_typat) { |
|
377 | + foreach ($ao_ccss_rules[$_typat] as $rule) { |
|
378 | + if (!empty($rule['hash'])) { |
|
379 | 379 | // we have at least one AUTO job, so all is fine. |
380 | 380 | $_has_auto_rules = true; |
381 | 381 | break; |
382 | 382 | } |
383 | 383 | } |
384 | - if ( $_has_auto_rules ) { |
|
384 | + if ($_has_auto_rules) { |
|
385 | 385 | break; |
386 | 386 | } |
387 | 387 | } |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | public function is_multisite_network_admin() { |
395 | 395 | static $_multisite_network_admin = null; |
396 | 396 | |
397 | - if ( null === $_multisite_network_admin ) { |
|
398 | - if ( is_multisite() && is_network_admin() ) { |
|
397 | + if (null === $_multisite_network_admin) { |
|
398 | + if (is_multisite() && is_network_admin()) { |
|
399 | 399 | $_multisite_network_admin = true; |
400 | 400 | } else { |
401 | 401 | $_multisite_network_admin = false; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * gets called by AO core, checks the rules and if a matching rule is found returns the associated CCSS. |
5 | 5 | */ |
6 | 6 | |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | { |
14 | 14 | // fetch all options at once and populate them individually explicitely as globals. |
15 | 15 | $all_options = autoptimizeCriticalCSSBase::fetch_options(); |
16 | - foreach ( $all_options as $_option => $_value ) { |
|
16 | + foreach ($all_options as $_option => $_value) { |
|
17 | 17 | global ${$_option}; |
18 | 18 | ${$_option} = $_value; |
19 | 19 | } |
@@ -28,28 +28,28 @@ discard block |
||
28 | 28 | global $ao_ccss_unloadccss; |
29 | 29 | |
30 | 30 | // add all filters to do CCSS if key present. |
31 | - if ( $ao_css_defer && isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) ) { |
|
31 | + if ($ao_css_defer && isset($ao_ccss_key) && !empty($ao_ccss_key)) { |
|
32 | 32 | // Set AO behavior: disable minification to avoid double minifying and caching. |
33 | - add_filter( 'autoptimize_filter_css_critcss_minify', '__return_false' ); |
|
34 | - add_filter( 'autoptimize_filter_css_defer_inline', array( $this, 'ao_ccss_frontend' ), 10, 1 ); |
|
33 | + add_filter('autoptimize_filter_css_critcss_minify', '__return_false'); |
|
34 | + add_filter('autoptimize_filter_css_defer_inline', array($this, 'ao_ccss_frontend'), 10, 1); |
|
35 | 35 | |
36 | 36 | // Add the action to enqueue jobs for CriticalCSS cron. |
37 | - add_action( 'autoptimize_action_css_hash', array( 'autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue' ), 10, 1 ); |
|
37 | + add_action('autoptimize_action_css_hash', array('autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue'), 10, 1); |
|
38 | 38 | |
39 | 39 | // conditionally add the filter to defer jquery and others. |
40 | - if ( $ao_ccss_deferjquery ) { |
|
41 | - add_filter( 'autoptimize_html_after_minify', array( $this, 'ao_ccss_defer_jquery' ), 11, 1 ); |
|
40 | + if ($ao_ccss_deferjquery) { |
|
41 | + add_filter('autoptimize_html_after_minify', array($this, 'ao_ccss_defer_jquery'), 11, 1); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | // conditionally add filter to unload the CCSS. |
45 | - if ( $ao_ccss_unloadccss ) { |
|
46 | - add_filter( 'autoptimize_html_after_minify', array( $this, 'ao_ccss_unloadccss' ), 12, 1 ); |
|
45 | + if ($ao_ccss_unloadccss) { |
|
46 | + add_filter('autoptimize_html_after_minify', array($this, 'ao_ccss_unloadccss'), 12, 1); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | // Order paths by length, as longest ones have greater priority in the rules. |
50 | - if ( ! empty( $ao_ccss_rules['paths'] ) ) { |
|
51 | - $keys = array_map( 'strlen', array_keys( $ao_ccss_rules['paths'] ) ); |
|
52 | - array_multisort( $keys, SORT_DESC, $ao_ccss_rules['paths'] ); |
|
50 | + if (!empty($ao_ccss_rules['paths'])) { |
|
51 | + $keys = array_map('strlen', array_keys($ao_ccss_rules['paths'])); |
|
52 | + array_multisort($keys, SORT_DESC, $ao_ccss_rules['paths']); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | // Add an array with default WordPress's conditional tags |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | $ao_ccss_types = $this->get_ao_ccss_core_types(); |
59 | 59 | |
60 | 60 | // Extend conditional tags on plugin initalization. |
61 | - add_action( apply_filters( 'autoptimize_filter_ccss_extend_types_hook', 'init' ), array( $this, 'ao_ccss_extend_types' ) ); |
|
61 | + add_action(apply_filters('autoptimize_filter_ccss_extend_types_hook', 'init'), array($this, 'ao_ccss_extend_types')); |
|
62 | 62 | |
63 | 63 | // When autoptimize cache is cleared, also clear transient cache for page templates. |
64 | - add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCriticalCSSCore', 'ao_ccss_clear_page_tpl_cache' ), 10, 0 ); |
|
64 | + add_action('autoptimize_action_cachepurged', array('autoptimizeCriticalCSSCore', 'ao_ccss_clear_page_tpl_cache'), 10, 0); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | - public function ao_ccss_frontend( $inlined ) { |
|
68 | + public function ao_ccss_frontend($inlined) { |
|
69 | 69 | // Apply CriticalCSS to frontend pages |
70 | 70 | // Attach types and settings arrays. |
71 | 71 | global $ao_ccss_types; |
@@ -76,23 +76,23 @@ discard block |
||
76 | 76 | global $ao_ccss_keyst; |
77 | 77 | |
78 | 78 | $no_ccss = ''; |
79 | - $ao_ccss_additional = autoptimizeStyles::sanitize_css( $ao_ccss_additional ); |
|
79 | + $ao_ccss_additional = autoptimizeStyles::sanitize_css($ao_ccss_additional); |
|
80 | 80 | |
81 | 81 | // Only if keystatus is OK and option to add CCSS for logged on users is on or user is not logged in. |
82 | - if ( ( $ao_ccss_keyst && 2 == $ao_ccss_keyst ) && ( $ao_ccss_loggedin || ! is_user_logged_in() ) ) { |
|
82 | + if (($ao_ccss_keyst && 2 == $ao_ccss_keyst) && ($ao_ccss_loggedin || !is_user_logged_in())) { |
|
83 | 83 | // Check for a valid CriticalCSS based on path to return its contents. |
84 | - $req_path = strtok( $_SERVER['REQUEST_URI'], '?' ); |
|
85 | - if ( ! empty( $ao_ccss_rules['paths'] ) ) { |
|
86 | - foreach ( $ao_ccss_rules['paths'] as $path => $rule ) { |
|
84 | + $req_path = strtok($_SERVER['REQUEST_URI'], '?'); |
|
85 | + if (!empty($ao_ccss_rules['paths'])) { |
|
86 | + foreach ($ao_ccss_rules['paths'] as $path => $rule) { |
|
87 | 87 | // explicit match OR partial match if MANUAL rule. |
88 | - if ( $req_path == $path || urldecode( $req_path ) == $path || ( false == $rule['hash'] && false != $rule['file'] && strpos( $req_path, str_replace( site_url(), '', $path ) ) !== false ) ) { |
|
89 | - if ( file_exists( AO_CCSS_DIR . $rule['file'] ) ) { |
|
90 | - $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] ); |
|
91 | - if ( 'none' != $_ccss_contents ) { |
|
92 | - if ( $ao_ccss_debug ) { |
|
93 | - $_ccss_contents = '/* PATH: ' . $path . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents; |
|
88 | + if ($req_path == $path || urldecode($req_path) == $path || (false == $rule['hash'] && false != $rule['file'] && strpos($req_path, str_replace(site_url(), '', $path)) !== false)) { |
|
89 | + if (file_exists(AO_CCSS_DIR.$rule['file'])) { |
|
90 | + $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']); |
|
91 | + if ('none' != $_ccss_contents) { |
|
92 | + if ($ao_ccss_debug) { |
|
93 | + $_ccss_contents = '/* PATH: '.$path.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents; |
|
94 | 94 | } |
95 | - return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional ); |
|
95 | + return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional); |
|
96 | 96 | } else { |
97 | 97 | $no_ccss = 'none'; |
98 | 98 | } |
@@ -102,55 +102,55 @@ discard block |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | // Check for a valid CriticalCSS based on conditional tags to return its contents. |
105 | - if ( ! empty( $ao_ccss_rules['types'] ) && 'none' !== $no_ccss ) { |
|
105 | + if (!empty($ao_ccss_rules['types']) && 'none' !== $no_ccss) { |
|
106 | 106 | // order types-rules by the order of the original $ao_ccss_types array so as not to depend on the order in which rules were added. |
107 | - $ao_ccss_rules['types'] = array_replace( array_intersect_key( array_flip( $ao_ccss_types ), $ao_ccss_rules['types'] ), $ao_ccss_rules['types'] ); |
|
107 | + $ao_ccss_rules['types'] = array_replace(array_intersect_key(array_flip($ao_ccss_types), $ao_ccss_rules['types']), $ao_ccss_rules['types']); |
|
108 | 108 | $is_front_page = is_front_page(); |
109 | 109 | |
110 | - foreach ( $ao_ccss_rules['types'] as $type => $rule ) { |
|
111 | - if ( in_array( $type, $ao_ccss_types ) && file_exists( AO_CCSS_DIR . $rule['file'] ) ) { |
|
112 | - $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] ); |
|
113 | - if ( $is_front_page && 'is_front_page' == $type ) { |
|
114 | - if ( 'none' != $_ccss_contents ) { |
|
115 | - if ( $ao_ccss_debug ) { |
|
116 | - $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents; |
|
110 | + foreach ($ao_ccss_rules['types'] as $type => $rule) { |
|
111 | + if (in_array($type, $ao_ccss_types) && file_exists(AO_CCSS_DIR.$rule['file'])) { |
|
112 | + $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']); |
|
113 | + if ($is_front_page && 'is_front_page' == $type) { |
|
114 | + if ('none' != $_ccss_contents) { |
|
115 | + if ($ao_ccss_debug) { |
|
116 | + $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents; |
|
117 | 117 | } |
118 | - return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional ); |
|
118 | + return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional); |
|
119 | 119 | } else { |
120 | 120 | $no_ccss = 'none'; |
121 | 121 | } |
122 | - } elseif ( strpos( $type, 'custom_post_' ) === 0 && ! $is_front_page ) { |
|
123 | - if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) { |
|
124 | - if ( 'none' != $_ccss_contents ) { |
|
125 | - if ( $ao_ccss_debug ) { |
|
126 | - $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents; |
|
122 | + } elseif (strpos($type, 'custom_post_') === 0 && !$is_front_page) { |
|
123 | + if (get_post_type(get_the_ID()) === substr($type, 12)) { |
|
124 | + if ('none' != $_ccss_contents) { |
|
125 | + if ($ao_ccss_debug) { |
|
126 | + $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents; |
|
127 | 127 | } |
128 | - return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional ); |
|
128 | + return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional); |
|
129 | 129 | } else { |
130 | 130 | $no_ccss = 'none'; |
131 | 131 | } |
132 | 132 | } |
133 | - } elseif ( 0 === strpos( $type, 'template_' ) && ! $is_front_page ) { |
|
134 | - if ( is_page_template( substr( $type, 9 ) ) ) { |
|
135 | - if ( 'none' != $_ccss_contents ) { |
|
136 | - if ( $ao_ccss_debug ) { |
|
137 | - $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents; |
|
133 | + } elseif (0 === strpos($type, 'template_') && !$is_front_page) { |
|
134 | + if (is_page_template(substr($type, 9))) { |
|
135 | + if ('none' != $_ccss_contents) { |
|
136 | + if ($ao_ccss_debug) { |
|
137 | + $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents; |
|
138 | 138 | } |
139 | - return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional ); |
|
139 | + return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional); |
|
140 | 140 | } else { |
141 | 141 | $no_ccss = 'none'; |
142 | 142 | } |
143 | 143 | } |
144 | - } elseif ( ! $is_front_page ) { |
|
144 | + } elseif (!$is_front_page) { |
|
145 | 145 | // all "normal" conditional tags, core + woo + buddypress + edd + bbpress |
146 | 146 | // but we have to remove the prefix for the non-core ones for them to function. |
147 | - $type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type ); |
|
148 | - if ( function_exists( $type ) && call_user_func( $type ) ) { |
|
149 | - if ( 'none' != $_ccss_contents ) { |
|
150 | - if ( $ao_ccss_debug ) { |
|
151 | - $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents; |
|
147 | + $type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type); |
|
148 | + if (function_exists($type) && call_user_func($type)) { |
|
149 | + if ('none' != $_ccss_contents) { |
|
150 | + if ($ao_ccss_debug) { |
|
151 | + $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents; |
|
152 | 152 | } |
153 | - return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional ); |
|
153 | + return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional); |
|
154 | 154 | } else { |
155 | 155 | $no_ccss = 'none'; |
156 | 156 | } |
@@ -163,45 +163,45 @@ discard block |
||
163 | 163 | |
164 | 164 | // Finally, inline the default CriticalCSS if any or else the entire CSS for the page |
165 | 165 | // This also applies to logged in users if the option to add CCSS for logged in users has been disabled. |
166 | - if ( ! empty( $inlined ) && 'none' !== $no_ccss ) { |
|
167 | - return apply_filters( 'autoptimize_filter_ccss_core_ccss', $inlined . $ao_ccss_additional ); |
|
166 | + if (!empty($inlined) && 'none' !== $no_ccss) { |
|
167 | + return apply_filters('autoptimize_filter_ccss_core_ccss', $inlined.$ao_ccss_additional); |
|
168 | 168 | } else { |
169 | - add_filter( 'autoptimize_filter_css_inline', '__return_true' ); |
|
169 | + add_filter('autoptimize_filter_css_inline', '__return_true'); |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | - public function ao_ccss_defer_jquery( $in ) { |
|
174 | + public function ao_ccss_defer_jquery($in) { |
|
175 | 175 | global $ao_ccss_loggedin; |
176 | 176 | // defer all linked and inline JS. |
177 | - if ( ( ! is_user_logged_in() || $ao_ccss_loggedin ) && preg_match_all( '#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER ) ) { |
|
178 | - foreach ( $matches as $match ) { |
|
179 | - if ( str_replace( apply_filters( 'autoptimize_filter_ccss_core_defer_exclude', array( 'data-noptimize="1"', 'data-cfasync="false"', 'data-pagespeed-no-defer' ) ), '', $match[0] ) !== $match[0] ) { |
|
177 | + if ((!is_user_logged_in() || $ao_ccss_loggedin) && preg_match_all('#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER)) { |
|
178 | + foreach ($matches as $match) { |
|
179 | + if (str_replace(apply_filters('autoptimize_filter_ccss_core_defer_exclude', array('data-noptimize="1"', 'data-cfasync="false"', 'data-pagespeed-no-defer')), '', $match[0]) !== $match[0]) { |
|
180 | 180 | // do not touch JS with noptimize/ cfasync/ pagespeed-no-defer flags. |
181 | 181 | continue; |
182 | - } elseif ( '' !== $match[1] && ( ! preg_match( '/<script.* type\s?=.*>/', $match[0] ) || preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0] ) ) ) { |
|
182 | + } elseif ('' !== $match[1] && (!preg_match('/<script.* type\s?=.*>/', $match[0]) || preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0]))) { |
|
183 | 183 | // base64-encode and defer all inline JS. |
184 | - $base64_js = '<script defer src="data:text/javascript;base64,' . base64_encode( $match[1] ) . '"></script>'; |
|
185 | - $in = str_replace( $match[0], $base64_js, $in ); |
|
186 | - } elseif ( str_replace( array( ' defer', ' async' ), '', $match[0] ) === $match[0] ) { |
|
184 | + $base64_js = '<script defer src="data:text/javascript;base64,'.base64_encode($match[1]).'"></script>'; |
|
185 | + $in = str_replace($match[0], $base64_js, $in); |
|
186 | + } elseif (str_replace(array(' defer', ' async'), '', $match[0]) === $match[0]) { |
|
187 | 187 | // and defer linked JS unless already deferred or asynced. |
188 | - $new_match = str_replace( '<script ', '<script defer ', $match[0] ); |
|
189 | - $in = str_replace( $match[0], $new_match, $in ); |
|
188 | + $new_match = str_replace('<script ', '<script defer ', $match[0]); |
|
189 | + $in = str_replace($match[0], $new_match, $in); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | } |
193 | 193 | return $in; |
194 | 194 | } |
195 | 195 | |
196 | - public function ao_ccss_unloadccss( $html_in ) { |
|
196 | + public function ao_ccss_unloadccss($html_in) { |
|
197 | 197 | // set media attrib of inline CCSS to none at onLoad to avoid it impacting full CSS (rarely needed). |
198 | - $_unloadccss_js = apply_filters( 'autoptimize_filter_ccss_core_unloadccss_js', '<script>window.addEventListener("load", function(event) {document.getElementById("aoatfcss").media="none";})</script>' ); |
|
198 | + $_unloadccss_js = apply_filters('autoptimize_filter_ccss_core_unloadccss_js', '<script>window.addEventListener("load", function(event) {document.getElementById("aoatfcss").media="none";})</script>'); |
|
199 | 199 | |
200 | - if ( false !== strpos( $html_in, $_unloadccss_js . '</body>' ) ) { |
|
200 | + if (false !== strpos($html_in, $_unloadccss_js.'</body>')) { |
|
201 | 201 | return $html_in; |
202 | 202 | } |
203 | 203 | |
204 | - return str_replace( '</body>', $_unloadccss_js . '</body>', $html_in ); |
|
204 | + return str_replace('</body>', $_unloadccss_js.'</body>', $html_in); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | public function ao_ccss_extend_types() { |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | global $ao_ccss_types; |
211 | 211 | |
212 | 212 | // in some cases $ao_ccss_types is empty and/or not an array, this should work around that problem. |
213 | - if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) { |
|
213 | + if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) { |
|
214 | 214 | $ao_ccss_types = get_ao_ccss_core_types(); |
215 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Empty types array in extend, refetching array with core conditionals.', 3 ); |
|
215 | + autoptimizeCriticalCSSCore::ao_ccss_log('Empty types array in extend, refetching array with core conditionals.', 3); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | // Custom Post Types. |
@@ -224,23 +224,23 @@ discard block |
||
224 | 224 | 'names', |
225 | 225 | 'and' |
226 | 226 | ); |
227 | - foreach ( $cpts as $cpt ) { |
|
228 | - array_unshift( $ao_ccss_types, 'custom_post_' . $cpt ); |
|
227 | + foreach ($cpts as $cpt) { |
|
228 | + array_unshift($ao_ccss_types, 'custom_post_'.$cpt); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // Templates. |
232 | 232 | // Transient cache to avoid frequent disk reads. |
233 | - $templates = get_transient( 'autoptimize_ccss_page_templates' ); |
|
234 | - if ( ! $templates ) { |
|
233 | + $templates = get_transient('autoptimize_ccss_page_templates'); |
|
234 | + if (!$templates) { |
|
235 | 235 | $templates = wp_get_theme()->get_page_templates(); |
236 | - set_transient( 'autoptimize_ccss_page_templates', $templates, HOUR_IN_SECONDS ); |
|
236 | + set_transient('autoptimize_ccss_page_templates', $templates, HOUR_IN_SECONDS); |
|
237 | 237 | } |
238 | - foreach ( $templates as $tplfile => $tplname ) { |
|
239 | - array_unshift( $ao_ccss_types, 'template_' . $tplfile ); |
|
238 | + foreach ($templates as $tplfile => $tplname) { |
|
239 | + array_unshift($ao_ccss_types, 'template_'.$tplfile); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | // bbPress tags. |
243 | - if ( function_exists( 'is_bbpress' ) ) { |
|
243 | + if (function_exists('is_bbpress')) { |
|
244 | 244 | $ao_ccss_types = array_merge( |
245 | 245 | array( |
246 | 246 | 'bbp_is_bbpress', |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | // BuddyPress tags. |
275 | - if ( function_exists( 'is_buddypress' ) ) { |
|
275 | + if (function_exists('is_buddypress')) { |
|
276 | 276 | $ao_ccss_types = array_merge( |
277 | 277 | array( |
278 | 278 | 'bp_is_activation_page', |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | } |
315 | 315 | |
316 | 316 | // Easy Digital Downloads (EDD) tags. |
317 | - if ( function_exists( 'edd_is_checkout' ) ) { |
|
317 | + if (function_exists('edd_is_checkout')) { |
|
318 | 318 | $ao_ccss_types = array_merge( |
319 | 319 | array( |
320 | 320 | 'edd_is_checkout', |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | } |
327 | 327 | |
328 | 328 | // WooCommerce tags. |
329 | - if ( class_exists( 'WooCommerce' ) ) { |
|
329 | + if (class_exists('WooCommerce')) { |
|
330 | 330 | $ao_ccss_types = array_merge( |
331 | 331 | array( |
332 | 332 | 'woo_is_account_page', |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | |
346 | 346 | public function get_ao_ccss_core_types() { |
347 | 347 | global $ao_ccss_types; |
348 | - if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) { |
|
348 | + if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) { |
|
349 | 349 | return array( |
350 | 350 | 'is_404', |
351 | 351 | 'is_archive', |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | } |
367 | 367 | } |
368 | 368 | |
369 | - public static function ao_ccss_key_status( $render ) { |
|
369 | + public static function ao_ccss_key_status($render) { |
|
370 | 370 | // Provide key status |
371 | 371 | // Get key and key status. |
372 | 372 | global $ao_ccss_key; |
@@ -379,55 +379,55 @@ discard block |
||
379 | 379 | $key_return = array(); |
380 | 380 | $status = false; |
381 | 381 | |
382 | - if ( $key && 2 == $key_status ) { |
|
382 | + if ($key && 2 == $key_status) { |
|
383 | 383 | // Key exists and its status is valid. |
384 | 384 | // Set valid key status. |
385 | 385 | $status = 'valid'; |
386 | - $status_msg = __( 'Valid' ); |
|
386 | + $status_msg = __('Valid'); |
|
387 | 387 | $color = '#46b450'; // Green. |
388 | 388 | $message = null; |
389 | - } elseif ( $key && 1 == $key_status ) { |
|
389 | + } elseif ($key && 1 == $key_status) { |
|
390 | 390 | // Key exists but its validation has failed. |
391 | 391 | // Set invalid key status. |
392 | 392 | $status = 'invalid'; |
393 | - $status_msg = __( 'Invalid' ); |
|
393 | + $status_msg = __('Invalid'); |
|
394 | 394 | $color = '#dc3232'; // Red. |
395 | - $message = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' ); |
|
396 | - } elseif ( $key && ! $key_status ) { |
|
395 | + $message = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize'); |
|
396 | + } elseif ($key && !$key_status) { |
|
397 | 397 | // Key exists but it has no valid status yet |
398 | 398 | // Perform key validation. |
399 | - $key_check = $self->ao_ccss_key_validation( $key ); |
|
399 | + $key_check = $self->ao_ccss_key_validation($key); |
|
400 | 400 | |
401 | 401 | // Key is valid, set valid status. |
402 | - if ( $key_check ) { |
|
402 | + if ($key_check) { |
|
403 | 403 | $status = 'valid'; |
404 | - $status_msg = __( 'Valid' ); |
|
404 | + $status_msg = __('Valid'); |
|
405 | 405 | $color = '#46b450'; // Green. |
406 | 406 | $message = null; |
407 | 407 | } else { |
408 | 408 | // Key is invalid, set invalid status. |
409 | 409 | $status = 'invalid'; |
410 | - $status_msg = __( 'Invalid' ); |
|
410 | + $status_msg = __('Invalid'); |
|
411 | 411 | $color = '#dc3232'; // Red. |
412 | - if ( get_option( 'autoptimize_ccss_keyst' ) == 1 ) { |
|
413 | - $message = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' ); |
|
412 | + if (get_option('autoptimize_ccss_keyst') == 1) { |
|
413 | + $message = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize'); |
|
414 | 414 | } else { |
415 | - $message = __( 'Something went wrong when checking your API key, make sure you server can communicate with https://criticalcss.com and/ or try again later.', 'autoptimize' ); |
|
415 | + $message = __('Something went wrong when checking your API key, make sure you server can communicate with https://criticalcss.com and/ or try again later.', 'autoptimize'); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | } else { |
419 | 419 | // No key nor status |
420 | 420 | // Set no key status. |
421 | 421 | $status = 'nokey'; |
422 | - $status_msg = __( 'None' ); |
|
422 | + $status_msg = __('None'); |
|
423 | 423 | $color = '#ffb900'; // Yellow. |
424 | - $message = __( 'Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize' ); |
|
424 | + $message = __('Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize'); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | // Fill returned values. |
428 | 428 | $key_return['status'] = $status; |
429 | 429 | // Provide rendering information if required. |
430 | - if ( $render ) { |
|
430 | + if ($render) { |
|
431 | 431 | $key_return['stmsg'] = $status_msg; |
432 | 432 | $key_return['color'] = $color; |
433 | 433 | $key_return['msg'] = $message; |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | return $key_return; |
438 | 438 | } |
439 | 439 | |
440 | - public function ao_ccss_key_validation( $key ) { |
|
440 | + public function ao_ccss_key_validation($key) { |
|
441 | 441 | global $ao_ccss_noptimize; |
442 | 442 | |
443 | 443 | // POST a dummy job to criticalcss.com to check for key validation |
@@ -445,26 +445,26 @@ discard block |
||
445 | 445 | $src_url = get_home_url(); |
446 | 446 | |
447 | 447 | // Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO. |
448 | - if ( ! empty( $ao_ccss_noptimize ) ) { |
|
448 | + if (!empty($ao_ccss_noptimize)) { |
|
449 | 449 | $src_url .= '?ao_noptirocket=1'; |
450 | - } elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) { |
|
450 | + } elseif (class_exists('autoptimizeImages', false) && autoptimizeImages::should_lazyload_wrapper()) { |
|
451 | 451 | $src_url .= '?ao_nolazy=1'; |
452 | 452 | } |
453 | 453 | |
454 | - $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url ); |
|
454 | + $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url); |
|
455 | 455 | |
456 | 456 | // Prepare the request. |
457 | - $url = esc_url_raw( AO_CCSS_API . 'generate' ); |
|
457 | + $url = esc_url_raw(AO_CCSS_API.'generate'); |
|
458 | 458 | $args = array( |
459 | 459 | 'headers' => array( |
460 | - 'User-Agent' => 'Autoptimize v' . AO_CCSS_VER, |
|
460 | + 'User-Agent' => 'Autoptimize v'.AO_CCSS_VER, |
|
461 | 461 | 'Content-type' => 'application/json; charset=utf-8', |
462 | - 'Authorization' => 'JWT ' . $key, |
|
462 | + 'Authorization' => 'JWT '.$key, |
|
463 | 463 | 'Connection' => 'close', |
464 | 464 | ), |
465 | 465 | // Body must be JSON. |
466 | 466 | 'body' => json_encode( |
467 | - apply_filters( 'autoptimize_ccss_cron_api_generate_body', |
|
467 | + apply_filters('autoptimize_ccss_cron_api_generate_body', |
|
468 | 468 | array( |
469 | 469 | 'url' => $src_url, |
470 | 470 | 'aff' => 1, |
@@ -475,23 +475,23 @@ discard block |
||
475 | 475 | ); |
476 | 476 | |
477 | 477 | // Dispatch the request and store its response code. |
478 | - $req = wp_safe_remote_post( $url, $args ); |
|
479 | - $code = wp_remote_retrieve_response_code( $req ); |
|
480 | - $body = json_decode( wp_remote_retrieve_body( $req ), true ); |
|
478 | + $req = wp_safe_remote_post($url, $args); |
|
479 | + $code = wp_remote_retrieve_response_code($req); |
|
480 | + $body = json_decode(wp_remote_retrieve_body($req), true); |
|
481 | 481 | |
482 | - if ( 200 == $code ) { |
|
482 | + if (200 == $code) { |
|
483 | 483 | // Response is OK. |
484 | 484 | // Set key status as valid and log key check. |
485 | - update_option( 'autoptimize_ccss_keyst', 2 ); |
|
486 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 ); |
|
485 | + update_option('autoptimize_ccss_keyst', 2); |
|
486 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3); |
|
487 | 487 | |
488 | 488 | // extract job-id from $body and put it in the queue as a P job |
489 | 489 | // but only if no jobs and no rules! |
490 | 490 | global $ao_ccss_queue; |
491 | 491 | global $ao_ccss_rules; |
492 | 492 | |
493 | - if ( 0 == count( $ao_ccss_queue ) && 0 == count( $ao_ccss_rules['types'] ) && 0 == count( $ao_ccss_rules['paths'] ) ) { |
|
494 | - if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] ) { |
|
493 | + if (0 == count($ao_ccss_queue) && 0 == count($ao_ccss_rules['types']) && 0 == count($ao_ccss_rules['paths'])) { |
|
494 | + if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status']) { |
|
495 | 495 | $jprops['ljid'] = 'firstrun'; |
496 | 496 | $jprops['rtarget'] = 'types|is_front_page'; |
497 | 497 | $jprops['ptype'] = 'is_front_page'; |
@@ -502,30 +502,30 @@ discard block |
||
502 | 502 | $jprops['jqstat'] = $body['job']['status']; |
503 | 503 | $jprops['jrstat'] = null; |
504 | 504 | $jprops['jvstat'] = null; |
505 | - $jprops['jctime'] = microtime( true ); |
|
505 | + $jprops['jctime'] = microtime(true); |
|
506 | 506 | $jprops['jftime'] = null; |
507 | 507 | $ao_ccss_queue['/'] = $jprops; |
508 | - $ao_ccss_queue_raw = json_encode( $ao_ccss_queue ); |
|
509 | - update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false ); |
|
510 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Created P job for is_front_page based on API key check response.', 3 ); |
|
508 | + $ao_ccss_queue_raw = json_encode($ao_ccss_queue); |
|
509 | + update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false); |
|
510 | + autoptimizeCriticalCSSCore::ao_ccss_log('Created P job for is_front_page based on API key check response.', 3); |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | return true; |
514 | - } elseif ( 401 == $code ) { |
|
514 | + } elseif (401 == $code) { |
|
515 | 515 | // Response is unauthorized |
516 | 516 | // Set key status as invalid and log key check. |
517 | - update_option( 'autoptimize_ccss_keyst', 1 ); |
|
518 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 ); |
|
517 | + update_option('autoptimize_ccss_keyst', 1); |
|
518 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3); |
|
519 | 519 | return false; |
520 | 520 | } else { |
521 | 521 | // Response unkown |
522 | 522 | // Log key check attempt. |
523 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2 ); |
|
524 | - if ( ! empty( $body ) ) { |
|
525 | - autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 ); |
|
523 | + autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2); |
|
524 | + if (!empty($body)) { |
|
525 | + autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2); |
|
526 | 526 | } |
527 | - if ( is_wp_error( $req ) ) { |
|
528 | - autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 ); |
|
527 | + if (is_wp_error($req)) { |
|
528 | + autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2); |
|
529 | 529 | } |
530 | 530 | return false; |
531 | 531 | } |
@@ -540,14 +540,14 @@ discard block |
||
540 | 540 | $viewport = array(); |
541 | 541 | |
542 | 542 | // Viewport Width. |
543 | - if ( ! empty( $ao_ccss_viewport['w'] ) ) { |
|
543 | + if (!empty($ao_ccss_viewport['w'])) { |
|
544 | 544 | $viewport['w'] = $ao_ccss_viewport['w']; |
545 | 545 | } else { |
546 | 546 | $viewport['w'] = ''; |
547 | 547 | } |
548 | 548 | |
549 | 549 | // Viewport Height. |
550 | - if ( ! empty( $ao_ccss_viewport['h'] ) ) { |
|
550 | + if (!empty($ao_ccss_viewport['h'])) { |
|
551 | 551 | $viewport['h'] = $ao_ccss_viewport['h']; |
552 | 552 | } else { |
553 | 553 | $viewport['h'] = ''; |
@@ -556,23 +556,23 @@ discard block |
||
556 | 556 | return $viewport; |
557 | 557 | } |
558 | 558 | |
559 | - public static function ao_ccss_check_contents( $ccss ) { |
|
559 | + public static function ao_ccss_check_contents($ccss) { |
|
560 | 560 | // Perform basic exploit avoidance and CSS validation. |
561 | - if ( ! empty( $ccss ) ) { |
|
561 | + if (!empty($ccss)) { |
|
562 | 562 | // Try to avoid code injection. |
563 | - $blocklist = array( '#!/', 'function(', '<script', '<?php' ); |
|
564 | - foreach ( $blocklist as $blocklisted ) { |
|
565 | - if ( strpos( $ccss, $blocklisted ) !== false ) { |
|
566 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received contained blocklisted content.', 2 ); |
|
563 | + $blocklist = array('#!/', 'function(', '<script', '<?php'); |
|
564 | + foreach ($blocklist as $blocklisted) { |
|
565 | + if (strpos($ccss, $blocklisted) !== false) { |
|
566 | + autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received contained blocklisted content.', 2); |
|
567 | 567 | return false; |
568 | 568 | } |
569 | 569 | } |
570 | 570 | |
571 | 571 | // Check for most basics CSS structures. |
572 | - $needlist = array( '{', '}', ':' ); |
|
573 | - foreach ( $needlist as $needed ) { |
|
574 | - if ( false === strpos( $ccss, $needed ) && 'none' !== $ccss ) { |
|
575 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not seem to contain real CSS.', 2 ); |
|
572 | + $needlist = array('{', '}', ':'); |
|
573 | + foreach ($needlist as $needed) { |
|
574 | + if (false === strpos($ccss, $needed) && 'none' !== $ccss) { |
|
575 | + autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not seem to contain real CSS.', 2); |
|
576 | 576 | return false; |
577 | 577 | } |
578 | 578 | } |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | return true; |
583 | 583 | } |
584 | 584 | |
585 | - public static function ao_ccss_log( $msg, $lvl ) { |
|
585 | + public static function ao_ccss_log($msg, $lvl) { |
|
586 | 586 | // Commom logging facility |
587 | 587 | // Attach debug option. |
588 | 588 | global $ao_ccss_debug; |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | // 3: DD (for debug) |
594 | 594 | // Default: UU (for unkown). |
595 | 595 | $level = false; |
596 | - switch ( $lvl ) { |
|
596 | + switch ($lvl) { |
|
597 | 597 | case 1: |
598 | 598 | $level = 'II'; |
599 | 599 | break; |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | break; |
603 | 603 | case 3: |
604 | 604 | // Output debug messages only if debug mode is enabled. |
605 | - if ( $ao_ccss_debug ) { |
|
605 | + if ($ao_ccss_debug) { |
|
606 | 606 | $level = 'DD'; |
607 | 607 | } |
608 | 608 | break; |
@@ -611,19 +611,19 @@ discard block |
||
611 | 611 | } |
612 | 612 | |
613 | 613 | // Prepare and write a log message if there's a valid level. |
614 | - if ( $level ) { |
|
614 | + if ($level) { |
|
615 | 615 | |
616 | 616 | // Prepare message. |
617 | - $message = date( 'c' ) . ' - [' . $level . '] ' . htmlentities( $msg ) . '<br>'; |
|
617 | + $message = date('c').' - ['.$level.'] '.htmlentities($msg).'<br>'; |
|
618 | 618 | |
619 | 619 | // Write message to log file. |
620 | - error_log( $message, 3, AO_CCSS_LOG ); |
|
620 | + error_log($message, 3, AO_CCSS_LOG); |
|
621 | 621 | } |
622 | 622 | } |
623 | 623 | |
624 | 624 | public static function ao_ccss_clear_page_tpl_cache() { |
625 | 625 | // Clears transient cache for page templates. |
626 | - delete_transient( 'autoptimize_ccss_page_templates' ); |
|
626 | + delete_transient('autoptimize_ccss_page_templates'); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | global $ao_ccss_unloadccss; |
20 | 20 | |
21 | 21 | // In case domain is not set yet (done in cron.php). |
22 | - if ( empty( $ao_ccss_domain ) ) { |
|
22 | + if (empty($ao_ccss_domain)) { |
|
23 | 23 | $ao_ccss_domain = get_site_url(); |
24 | 24 | } |
25 | 25 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | ?> |
29 | 29 | <ul id="adv-panel"> |
30 | 30 | <li class="itemDetail"> |
31 | - <h2 class="itemTitle fleft"><?php _e( 'Advanced Settings', 'autoptimize' ); ?></h2> |
|
31 | + <h2 class="itemTitle fleft"><?php _e('Advanced Settings', 'autoptimize'); ?></h2> |
|
32 | 32 | <button type="button" class="toggle-btn"> |
33 | 33 | <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span> |
34 | 34 | </button> |
@@ -36,114 +36,114 @@ discard block |
||
36 | 36 | <table id="key" class="form-table"> |
37 | 37 | <tr> |
38 | 38 | <th scope="row"> |
39 | - <?php _e( 'Viewport Size', 'autoptimize' ); ?> |
|
39 | + <?php _e('Viewport Size', 'autoptimize'); ?> |
|
40 | 40 | </th> |
41 | 41 | <td> |
42 | - <label for="autoptimize_ccss_vw"><?php _e( 'Width', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" /> |
|
43 | - <label for="autoptimize_ccss_vh"><?php _e( 'Height', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" /> |
|
42 | + <label for="autoptimize_ccss_vw"><?php _e('Width', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" /> |
|
43 | + <label for="autoptimize_ccss_vh"><?php _e('Height', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" /> |
|
44 | 44 | <p class="notes"> |
45 | - <?php _e( '<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize' ); ?> |
|
45 | + <?php _e('<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize'); ?> |
|
46 | 46 | </p> |
47 | 47 | </td> |
48 | 48 | </tr> |
49 | 49 | <tr> |
50 | 50 | <th scope="row"> |
51 | - <?php _e( 'Force Include CSS selectors', 'autoptimize' ); ?> |
|
51 | + <?php _e('Force Include CSS selectors', 'autoptimize'); ?> |
|
52 | 52 | </th> |
53 | 53 | <td> |
54 | - <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e( '.button-special,//#footer', 'autoptimize' ); ?>"><?php echo trim( strip_tags( $ao_ccss_finclude ) ); ?></textarea> |
|
54 | + <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e('.button-special,//#footer', 'autoptimize'); ?>"><?php echo trim(strip_tags($ao_ccss_finclude)); ?></textarea> |
|
55 | 55 | <p class="notes"> |
56 | - <?php _e( 'Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize' ); ?> |
|
56 | + <?php _e('Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize'); ?> |
|
57 | 57 | </p> |
58 | 58 | </td> |
59 | 59 | </tr> |
60 | 60 | <tr> |
61 | 61 | <th scope="row"> |
62 | - <?php _e( 'Queue processing time limit', 'autoptimize' ); ?> |
|
62 | + <?php _e('Queue processing time limit', 'autoptimize'); ?> |
|
63 | 63 | </th> |
64 | 64 | <td> |
65 | 65 | <input type="number" id="autoptimize_ccss_rtimelimit" name="autoptimize_ccss_rtimelimit" min="0" max="240" placeholder="0" value="<?php echo $ao_ccss_rtimelimit; ?>" /> |
66 | 66 | <p class="notes"> |
67 | - <?php _e( 'The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', 'autoptimize' ); ?> |
|
67 | + <?php _e('The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', 'autoptimize'); ?> |
|
68 | 68 | </p> |
69 | 69 | </td> |
70 | 70 | </tr> |
71 | 71 | <tr> |
72 | 72 | <th scope="row"> |
73 | - <?php _e( 'Fetch Original CSS', 'autoptimize' ); ?> |
|
73 | + <?php _e('Fetch Original CSS', 'autoptimize'); ?> |
|
74 | 74 | </th> |
75 | 75 | <td> |
76 | - <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked( 1 == $ao_ccss_noptimize ); ?>> |
|
76 | + <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked(1 == $ao_ccss_noptimize); ?>> |
|
77 | 77 | <p class="notes"> |
78 | - <?php _e( 'In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize' ); ?> |
|
78 | + <?php _e('In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize'); ?> |
|
79 | 79 | </p> |
80 | 80 | </td> |
81 | 81 | </tr> |
82 | 82 | <tr> |
83 | 83 | <th scope="row"> |
84 | - <?php _e( 'Add CCSS for logged in users?', 'autoptimize' ); ?> |
|
84 | + <?php _e('Add CCSS for logged in users?', 'autoptimize'); ?> |
|
85 | 85 | </th> |
86 | 86 | <td> |
87 | - <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked( 1 == $ao_ccss_loggedin ); ?>> |
|
87 | + <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked(1 == $ao_ccss_loggedin); ?>> |
|
88 | 88 | <p class="notes"> |
89 | - <?php _e( 'Critical CSS is generated by criticalcss.com from your pages as seen by an "anonymous visitor". Disable this option if you don\'t want the "visitor" critical CSS to be used for logged in users.', 'autoptimize' ); ?> |
|
89 | + <?php _e('Critical CSS is generated by criticalcss.com from your pages as seen by an "anonymous visitor". Disable this option if you don\'t want the "visitor" critical CSS to be used for logged in users.', 'autoptimize'); ?> |
|
90 | 90 | </p> |
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | <tr> |
94 | 94 | <th scope="row"> |
95 | - <?php _e( 'Force path-based rules to be generated for pages?', 'autoptimize' ); ?> |
|
95 | + <?php _e('Force path-based rules to be generated for pages?', 'autoptimize'); ?> |
|
96 | 96 | </th> |
97 | 97 | <td> |
98 | - <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked( 1 == $ao_ccss_forcepath ); ?>> |
|
98 | + <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked(1 == $ao_ccss_forcepath); ?>> |
|
99 | 99 | <p class="notes"> |
100 | - <?php _e( 'By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize' ); ?> |
|
100 | + <?php _e('By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize'); ?> |
|
101 | 101 | </p> |
102 | 102 | </td> |
103 | 103 | </tr> |
104 | 104 | <tr> |
105 | 105 | <th scope="row"> |
106 | - <?php _e( 'Defer jQuery and other non-aggregated JS-files?', 'autoptimize' ); ?> |
|
106 | + <?php _e('Defer jQuery and other non-aggregated JS-files?', 'autoptimize'); ?> |
|
107 | 107 | </th> |
108 | 108 | <td> |
109 | - <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked( 1 == $ao_ccss_deferjquery ); ?>> |
|
109 | + <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked(1 == $ao_ccss_deferjquery); ?>> |
|
110 | 110 | <p class="notes"> |
111 | - <?php _e( 'Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize' ); ?> |
|
111 | + <?php _e('Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize'); ?> |
|
112 | 112 | </p> |
113 | 113 | </td> |
114 | 114 | </tr> |
115 | 115 | <tr> |
116 | 116 | <th scope="row"> |
117 | - <?php _e( 'Unload critical CSS after page load?', 'autoptimize' ); ?> |
|
117 | + <?php _e('Unload critical CSS after page load?', 'autoptimize'); ?> |
|
118 | 118 | </th> |
119 | 119 | <td> |
120 | - <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked( 1 == $ao_ccss_unloadccss ); ?>> |
|
120 | + <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked(1 == $ao_ccss_unloadccss); ?>> |
|
121 | 121 | <p class="notes"> |
122 | - <?php _e( 'In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize' ); ?> |
|
122 | + <?php _e('In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize'); ?> |
|
123 | 123 | </p> |
124 | 124 | </td> |
125 | 125 | </tr> |
126 | 126 | <tr> |
127 | 127 | <th scope="row"> |
128 | - <?php _e( 'Bound domain', 'autoptimize' ); ?> |
|
128 | + <?php _e('Bound domain', 'autoptimize'); ?> |
|
129 | 129 | </th> |
130 | 130 | <td> |
131 | - <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e( 'Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize' ); ?>" value="<?php echo trim( strip_tags( $ao_ccss_domain ) ); ?>"> |
|
131 | + <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e('Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize'); ?>" value="<?php echo trim(strip_tags($ao_ccss_domain)); ?>"> |
|
132 | 132 | <p class="notes"> |
133 | - <?php _e( 'Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize' ); ?> |
|
133 | + <?php _e('Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize'); ?> |
|
134 | 134 | </p> |
135 | 135 | </td> |
136 | 136 | </tr> |
137 | 137 | <tr> |
138 | 138 | <th scope="row"> |
139 | - <?php _e( 'Debug Mode', 'autoptimize' ); ?> |
|
139 | + <?php _e('Debug Mode', 'autoptimize'); ?> |
|
140 | 140 | </th> |
141 | 141 | <td> |
142 | - <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked( 1 == $ao_ccss_debug ); ?>> |
|
142 | + <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked(1 == $ao_ccss_debug); ?>> |
|
143 | 143 | <p class="notes"> |
144 | 144 | <?php |
145 | - _e( '<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize' ); |
|
146 | - echo '<code>' . AO_CCSS_LOG . '</code>'; |
|
145 | + _e('<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize'); |
|
146 | + echo '<code>'.AO_CCSS_LOG.'</code>'; |
|
147 | 147 | ?> |
148 | 148 | </p> |
149 | 149 | </td> |
@@ -12,27 +12,27 @@ discard block |
||
12 | 12 | * @param string $message Message. |
13 | 13 | * @param string $color Color to highlight message in. |
14 | 14 | */ |
15 | -function ao_ccss_render_key( $key, $status, $status_msg, $message, $color ) { |
|
16 | - if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) { |
|
17 | - $key = __( 'API key provided by your host/ WordPress administrator, no need to enter anything here. In case of problems with the API key, contact your host/ WordPress administrator.', 'autoptimize' ); |
|
15 | +function ao_ccss_render_key($key, $status, $status_msg, $message, $color) { |
|
16 | + if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) { |
|
17 | + $key = __('API key provided by your host/ WordPress administrator, no need to enter anything here. In case of problems with the API key, contact your host/ WordPress administrator.', 'autoptimize'); |
|
18 | 18 | } |
19 | 19 | ?> |
20 | 20 | <ul id="key-panel"> |
21 | 21 | <li class="itemDetail"> |
22 | - <h2 class="itemTitle fleft"><?php _e( 'API Key', 'autoptimize' ); ?>: <span style="color:<?php echo $color; ?>;"><?php echo $status_msg; ?></span></h2> |
|
22 | + <h2 class="itemTitle fleft"><?php _e('API Key', 'autoptimize'); ?>: <span style="color:<?php echo $color; ?>;"><?php echo $status_msg; ?></span></h2> |
|
23 | 23 | <button type="button" class="toggle-btn"> |
24 | - <?php if ( 'valid' != $status ) { ?> |
|
24 | + <?php if ('valid' != $status) { ?> |
|
25 | 25 | <span class="toggle-indicator dashicons dashicons-arrow-up"></span> |
26 | 26 | <?php } else { ?> |
27 | 27 | <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span> |
28 | 28 | <?php } ?> |
29 | 29 | </button> |
30 | - <?php if ( 'valid' != $status ) { ?> |
|
30 | + <?php if ('valid' != $status) { ?> |
|
31 | 31 | <div class="collapsible"> |
32 | 32 | <?php } else { ?> |
33 | 33 | <div class="collapsible hidden"> |
34 | 34 | <?php } ?> |
35 | - <?php if ( 'valid' != $status ) { ?> |
|
35 | + <?php if ('valid' != $status) { ?> |
|
36 | 36 | <div style="clear:both;padding:2px 10px;border-left:solid;border-left-width:5px;border-left-color:<?php echo $color; ?>;background-color:white;"> |
37 | 37 | <p><?php echo $message; ?></p> |
38 | 38 | </div> |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | <table id="key" class="form-table"> |
41 | 41 | <tr> |
42 | 42 | <th scope="row"> |
43 | - <?php _e( 'Your API Key', 'autoptimize' ); ?> |
|
43 | + <?php _e('Your API Key', 'autoptimize'); ?> |
|
44 | 44 | </th> |
45 | 45 | <td> |
46 | - <textarea id="autoptimize_ccss_key" name="autoptimize_ccss_key" rows='3' style="width:100%;" placeholder="<?php _e( 'Please enter your criticalcss.com API key here.', 'autoptimize' ); ?>"><?php echo trim( esc_textarea( $key ) ); ?></textarea> |
|
46 | + <textarea id="autoptimize_ccss_key" name="autoptimize_ccss_key" rows='3' style="width:100%;" placeholder="<?php _e('Please enter your criticalcss.com API key here.', 'autoptimize'); ?>"><?php echo trim(esc_textarea($key)); ?></textarea> |
|
47 | 47 | <p class="notes"> |
48 | - <?php _e( 'Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day money back guarantee</a>, you have nothing to lose!</strong>', 'autoptimize' ); ?> |
|
48 | + <?php _e('Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day money back guarantee</a>, you have nothing to lose!</strong>', 'autoptimize'); ?> |
|
49 | 49 | </p> |
50 | 50 | </td> |
51 | 51 | </tr> |
@@ -13,12 +13,12 @@ discard block |
||
13 | 13 | ?> |
14 | 14 | <ul id="rules-panel"> |
15 | 15 | <li class="itemDetail"> |
16 | - <h2 class="itemTitle"><?php _e( 'Rules', 'autoptimize' ); ?></h2> |
|
16 | + <h2 class="itemTitle"><?php _e('Rules', 'autoptimize'); ?></h2> |
|
17 | 17 | |
18 | 18 | <!-- BEGIN Rule dialogs --> |
19 | 19 | <!-- Unsaved dialog --> |
20 | 20 | <div id="unSavedWarning" class="hidden updated settings-error notice notice-warning is-dismissible"> |
21 | - <p><?php _e( "<strong>Rules or Queue changed!</strong> Don't forget to save your changes!", 'autoptimize' ); ?></p> |
|
21 | + <p><?php _e("<strong>Rules or Queue changed!</strong> Don't forget to save your changes!", 'autoptimize'); ?></p> |
|
22 | 22 | </div> |
23 | 23 | |
24 | 24 | <!-- Create/edit rule dialog --> |
@@ -26,97 +26,97 @@ discard block |
||
26 | 26 | <table class="form-table rules"> |
27 | 27 | <tr id="critcss_addedit_type_wrapper"> |
28 | 28 | <th scope="row"> |
29 | - <?php _e( 'Rule Type', 'autoptimize' ); ?> |
|
29 | + <?php _e('Rule Type', 'autoptimize'); ?> |
|
30 | 30 | </th> |
31 | 31 | <td> |
32 | 32 | <select id="critcss_addedit_type" style="width:100%;"> |
33 | - <option value="paths"><?php _e( 'Path', 'autoptimize' ); ?></option> |
|
34 | - <option value="types"><?php _e( 'Conditional Tag', 'autoptimize' ); ?></option> |
|
33 | + <option value="paths"><?php _e('Path', 'autoptimize'); ?></option> |
|
34 | + <option value="types"><?php _e('Conditional Tag', 'autoptimize'); ?></option> |
|
35 | 35 | </select> |
36 | 36 | </td> |
37 | 37 | </tr> |
38 | 38 | <tr id="critcss_addedit_path_wrapper"> |
39 | 39 | <th scope="row"> |
40 | - <?php _e( 'String in Path', 'autoptimize' ); ?> |
|
40 | + <?php _e('String in Path', 'autoptimize'); ?> |
|
41 | 41 | </th> |
42 | 42 | <td> |
43 | - <input type="text" id="critcss_addedit_path" placeholder="<?php _e( "Enter a part of the URL that identifies the page(s) you're targetting.", 'autoptimize' ); ?>" style="width:100%;" value=""> |
|
43 | + <input type="text" id="critcss_addedit_path" placeholder="<?php _e("Enter a part of the URL that identifies the page(s) you're targetting.", 'autoptimize'); ?>" style="width:100%;" value=""> |
|
44 | 44 | </td> |
45 | 45 | </tr> |
46 | 46 | <tr id="critcss_addedit_pagetype_wrapper"> |
47 | 47 | <th scope="row"> |
48 | - <?php _e( 'Conditional Tag, Custom Post Type or Page Template', 'autoptimize' ); ?> |
|
48 | + <?php _e('Conditional Tag, Custom Post Type or Page Template', 'autoptimize'); ?> |
|
49 | 49 | </th> |
50 | 50 | <td> |
51 | 51 | <select id="critcss_addedit_pagetype" style="width:100%;"> |
52 | - <option value="" disabled selected><?php _e( 'Select from the list below...', 'autoptimize' ); ?></option> |
|
53 | - <optgroup label="<?php _e( 'Standard Conditional Tags', 'autoptimize' ); ?>"> |
|
52 | + <option value="" disabled selected><?php _e('Select from the list below...', 'autoptimize'); ?></option> |
|
53 | + <optgroup label="<?php _e('Standard Conditional Tags', 'autoptimize'); ?>"> |
|
54 | 54 | <?php |
55 | 55 | // Render grouped simple conditional tags. |
56 | - foreach ( $ao_ccss_types as $ctag ) { |
|
57 | - $optgrp = substr( $ctag, 0, 3 ); |
|
58 | - if ( substr( $ctag, 0, 3 ) === 'is_' ) { |
|
59 | - echo '<option value="' . $ctag . '">' . $ctag . '</option>'; |
|
56 | + foreach ($ao_ccss_types as $ctag) { |
|
57 | + $optgrp = substr($ctag, 0, 3); |
|
58 | + if (substr($ctag, 0, 3) === 'is_') { |
|
59 | + echo '<option value="'.$ctag.'">'.$ctag.'</option>'; |
|
60 | 60 | } |
61 | - $prevgrp = substr( $ctag, 0, 3 ); |
|
61 | + $prevgrp = substr($ctag, 0, 3); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | // Render grouped custom post types, templates and specific conditional tags. |
65 | - foreach ( $ao_ccss_types as $type ) { |
|
66 | - $optgrp = substr( $type, 0, 3 ); |
|
65 | + foreach ($ao_ccss_types as $type) { |
|
66 | + $optgrp = substr($type, 0, 3); |
|
67 | 67 | |
68 | 68 | // Option groups labels. |
69 | - if ( $optgrp !== $prevgrp && 'is_' !== $optgrp ) { |
|
69 | + if ($optgrp !== $prevgrp && 'is_' !== $optgrp) { |
|
70 | 70 | ?> |
71 | 71 | </optgroup> |
72 | 72 | <?php |
73 | - if ( substr( $type, 0, 12 ) === 'custom_post_' ) { |
|
73 | + if (substr($type, 0, 12) === 'custom_post_') { |
|
74 | 74 | ?> |
75 | - <optgroup label="<?php _e( 'Custom Post Types', 'autoptimize' ); ?>"> |
|
75 | + <optgroup label="<?php _e('Custom Post Types', 'autoptimize'); ?>"> |
|
76 | 76 | <?php |
77 | - } elseif ( substr( $type, 0, 9 ) === 'template_' ) { |
|
77 | + } elseif (substr($type, 0, 9) === 'template_') { |
|
78 | 78 | ?> |
79 | - <optgroup label="<?php _e( 'Page Templates', 'autoptimize' ); ?>"> |
|
79 | + <optgroup label="<?php _e('Page Templates', 'autoptimize'); ?>"> |
|
80 | 80 | <?php |
81 | - } elseif ( substr( $type, 0, 4 ) === 'bbp_' ) { |
|
81 | + } elseif (substr($type, 0, 4) === 'bbp_') { |
|
82 | 82 | ?> |
83 | - <optgroup label="<?php _e( 'BBPress Conditional Tags', 'autoptimize' ); ?>"> |
|
83 | + <optgroup label="<?php _e('BBPress Conditional Tags', 'autoptimize'); ?>"> |
|
84 | 84 | <?php |
85 | - } elseif ( substr( $type, 0, 3 ) === 'bp_' ) { |
|
85 | + } elseif (substr($type, 0, 3) === 'bp_') { |
|
86 | 86 | ?> |
87 | - <optgroup label="<?php _e( 'BuddyPress Conditional Tags', 'autoptimize' ); ?>"> |
|
87 | + <optgroup label="<?php _e('BuddyPress Conditional Tags', 'autoptimize'); ?>"> |
|
88 | 88 | <?php |
89 | - } elseif ( substr( $type, 0, 4 ) === 'edd_' ) { |
|
89 | + } elseif (substr($type, 0, 4) === 'edd_') { |
|
90 | 90 | ?> |
91 | - <optgroup label="<?php _e( 'Easy Digital Downloads Conditional Tags', 'autoptimize' ); ?>"> |
|
91 | + <optgroup label="<?php _e('Easy Digital Downloads Conditional Tags', 'autoptimize'); ?>"> |
|
92 | 92 | <?php |
93 | - } elseif ( substr( $type, 0, 4 ) === 'woo_' ) { |
|
93 | + } elseif (substr($type, 0, 4) === 'woo_') { |
|
94 | 94 | ?> |
95 | - <optgroup label="<?php _e( 'WooCommerce Conditional Tags', 'autoptimize' ); ?>"> |
|
95 | + <optgroup label="<?php _e('WooCommerce Conditional Tags', 'autoptimize'); ?>"> |
|
96 | 96 | <?php |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | 100 | // Options. |
101 | - if ( 'is_' !== $optgrp ) { |
|
101 | + if ('is_' !== $optgrp) { |
|
102 | 102 | // Remove prefix from custom post types, templates and some specific conditional tags. |
103 | - if ( substr( $type, 0, 12 ) === 'custom_post_' ) { |
|
104 | - $_type = str_replace( 'custom_post_', '', $type ); |
|
105 | - } elseif ( substr( $type, 0, 9 ) === 'template_' ) { |
|
106 | - $_type = str_replace( 'template_', '', $type ); |
|
107 | - } elseif ( 'bbp_is_bbpress' == $type ) { |
|
108 | - $_type = str_replace( 'bbp_', '', $type ); |
|
109 | - } elseif ( 'bp_is_buddypress' == $type ) { |
|
110 | - $_type = str_replace( 'bp_', '', $type ); |
|
111 | - } elseif ( substr( $type, 0, 4 ) === 'woo_' ) { |
|
112 | - $_type = str_replace( 'woo_', '', $type ); |
|
113 | - } elseif ( substr( $type, 0, 4 ) === 'edd_' ) { |
|
114 | - $_type = str_replace( 'edd_', '', $type ); |
|
103 | + if (substr($type, 0, 12) === 'custom_post_') { |
|
104 | + $_type = str_replace('custom_post_', '', $type); |
|
105 | + } elseif (substr($type, 0, 9) === 'template_') { |
|
106 | + $_type = str_replace('template_', '', $type); |
|
107 | + } elseif ('bbp_is_bbpress' == $type) { |
|
108 | + $_type = str_replace('bbp_', '', $type); |
|
109 | + } elseif ('bp_is_buddypress' == $type) { |
|
110 | + $_type = str_replace('bp_', '', $type); |
|
111 | + } elseif (substr($type, 0, 4) === 'woo_') { |
|
112 | + $_type = str_replace('woo_', '', $type); |
|
113 | + } elseif (substr($type, 0, 4) === 'edd_') { |
|
114 | + $_type = str_replace('edd_', '', $type); |
|
115 | 115 | } else { |
116 | 116 | $_type = $type; |
117 | 117 | } |
118 | 118 | |
119 | - echo '<option value="' . $type . '">' . $_type . '</option>'; |
|
119 | + echo '<option value="'.$type.'">'.$_type.'</option>'; |
|
120 | 120 | $prevgrp = $optgrp; |
121 | 121 | } |
122 | 122 | } |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | </tr> |
128 | 128 | <tr> |
129 | 129 | <th scope="row"> |
130 | - <?php _e( 'Custom Critical CSS', 'autoptimize' ); ?> |
|
130 | + <?php _e('Custom Critical CSS', 'autoptimize'); ?> |
|
131 | 131 | </th> |
132 | 132 | <td> |
133 | - <textarea id="critcss_addedit_css" rows="13" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your specific critical CSS here and hit submit to save.', 'autoptimize' ); ?>"></textarea> |
|
133 | + <textarea id="critcss_addedit_css" rows="13" cols="10" style="width:100%;" placeholder="<?php _e('Paste your specific critical CSS here and hit submit to save.', 'autoptimize'); ?>"></textarea> |
|
134 | 134 | <input type="hidden" id="critcss_addedit_file"> |
135 | 135 | <input type="hidden" id="critcss_addedit_id"> |
136 | 136 | </td> |
@@ -139,23 +139,23 @@ discard block |
||
139 | 139 | </div> |
140 | 140 | |
141 | 141 | <!-- Remove dialog --> |
142 | - <div id="confirm-rm" title="<?php _e( 'Delete Rule', 'autoptimize' ); ?>" class="hidden"> |
|
143 | - <p><?php _e( 'This Critical CSS rule will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p> |
|
142 | + <div id="confirm-rm" title="<?php _e('Delete Rule', 'autoptimize'); ?>" class="hidden"> |
|
143 | + <p><?php _e('This Critical CSS rule will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize'); ?></p> |
|
144 | 144 | </div> |
145 | 145 | |
146 | 146 | <!-- Remove All dialog --> |
147 | - <div id="confirm-rm-all" title="<?php _e( 'Delete all Rules and Jobs', 'autoptimize' ); ?>" class="hidden"> |
|
148 | - <p><?php _e( 'All Critical CSS rules will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p> |
|
147 | + <div id="confirm-rm-all" title="<?php _e('Delete all Rules and Jobs', 'autoptimize'); ?>" class="hidden"> |
|
148 | + <p><?php _e('All Critical CSS rules will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize'); ?></p> |
|
149 | 149 | </div> |
150 | 150 | |
151 | 151 | <!-- Add/edit default critical CSS dialog --> |
152 | 152 | <div id="default_critcss_wrapper" class="hidden"> |
153 | - <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize' ); ?>"></textarea> |
|
153 | + <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e('Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize'); ?>"></textarea> |
|
154 | 154 | </div> |
155 | 155 | |
156 | 156 | <!-- Add/edit additional critical CSS dialog --> |
157 | 157 | <div id="additional_critcss_wrapper" class="hidden"> |
158 | - <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize' ); ?>"></textarea> |
|
158 | + <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e('Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize'); ?>"></textarea> |
|
159 | 159 | </div> |
160 | 160 | |
161 | 161 | <!-- Wrapper for in screen notices --> |
@@ -165,38 +165,38 @@ discard block |
||
165 | 165 | <!-- BEGIN Rules UI --> |
166 | 166 | <div class="howto"> |
167 | 167 | <div class="title-wrap"> |
168 | - <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize' ); ?></h4> |
|
169 | - <p class="subtitle"><?php _e( 'Click the side arrow to toggle instructions', 'autoptimize' ); ?></p> |
|
168 | + <h4 class="title"><?php _e('How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize'); ?></h4> |
|
169 | + <p class="subtitle"><?php _e('Click the side arrow to toggle instructions', 'autoptimize'); ?></p> |
|
170 | 170 | </div> |
171 | 171 | <button type="button" class="toggle-btn"> |
172 | 172 | <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span> |
173 | 173 | </button> |
174 | 174 | <div class="howto-wrap hidden"> |
175 | - <p><?php _e( "TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize' ); ?></p> |
|
175 | + <p><?php _e("TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize'); ?></p> |
|
176 | 176 | <ol> |
177 | - <li><?php _e( 'When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize' ); ?></li> |
|
178 | - <li><?php _e( 'Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize' ); ?></li> |
|
179 | - <li><?php _e( 'These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize' ); ?></li> |
|
180 | - <li><?php _e( 'If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize' ); ?></li> |
|
181 | - <li><?php _e( 'You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize' ); ?></li> |
|
182 | - <li><?php _e( 'You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize' ); ?></li> |
|
183 | - <li><?php _e( "If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% guaranteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize' ); ?></li> |
|
184 | - <li><?php _e( 'At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize' ); ?></li> |
|
177 | + <li><?php _e('When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize'); ?></li> |
|
178 | + <li><?php _e('Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize'); ?></li> |
|
179 | + <li><?php _e('These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize'); ?></li> |
|
180 | + <li><?php _e('If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize'); ?></li> |
|
181 | + <li><?php _e('You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize'); ?></li> |
|
182 | + <li><?php _e('You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize'); ?></li> |
|
183 | + <li><?php _e("If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% guaranteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize'); ?></li> |
|
184 | + <li><?php _e('At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize'); ?></li> |
|
185 | 185 | </ol> |
186 | 186 | </div> |
187 | 187 | </div> |
188 | - <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo autoptimizeStyles::sanitize_css( get_option( 'autoptimize_css_defer_inline', '' ) ); ?></textarea> |
|
189 | - <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo autoptimizeStyles::sanitize_css( get_option( 'autoptimize_ccss_additional', '' ) ); ?></textarea> |
|
188 | + <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo autoptimizeStyles::sanitize_css(get_option('autoptimize_css_defer_inline', '')); ?></textarea> |
|
189 | + <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo autoptimizeStyles::sanitize_css(get_option('autoptimize_ccss_additional', '')); ?></textarea> |
|
190 | 190 | <table class="rules-list" cellspacing="0"><tbody id="rules-list"></tbody></table> |
191 | - <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo ( json_encode( $ao_ccss_rules, JSON_FORCE_OBJECT ) ); ?>'> |
|
191 | + <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo (json_encode($ao_ccss_rules, JSON_FORCE_OBJECT)); ?>'> |
|
192 | 192 | <div class="submit rules-btn"> |
193 | 193 | <div class="alignleft"> |
194 | - <span id="addCritCssButton" class="button-secondary"><?php _e( 'Add New Rule', 'autoptimize' ); ?></span> |
|
195 | - <span id="editDefaultButton" class="button-secondary"><?php _e( 'Edit Default Rule CSS', 'autoptimize' ); ?></span> |
|
196 | - <span id="editAdditionalButton" class="button-secondary"><?php _e( 'Add CSS To All Rules', 'autoptimize' ); ?></span> |
|
194 | + <span id="addCritCssButton" class="button-secondary"><?php _e('Add New Rule', 'autoptimize'); ?></span> |
|
195 | + <span id="editDefaultButton" class="button-secondary"><?php _e('Edit Default Rule CSS', 'autoptimize'); ?></span> |
|
196 | + <span id="editAdditionalButton" class="button-secondary"><?php _e('Add CSS To All Rules', 'autoptimize'); ?></span> |
|
197 | 197 | </div> |
198 | 198 | <div class="alignright"> |
199 | - <span id="removeAllRules" class="button-secondary" style="color:red;"><?php _e( 'Remove all rules', 'autoptimize' ); ?></span> |
|
199 | + <span id="removeAllRules" class="button-secondary" style="color:red;"><?php _e('Remove all rules', 'autoptimize'); ?></span> |
|
200 | 200 | </div> |
201 | 201 | </div> |
202 | 202 | <!-- END Rules UI --> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Main configuration logic. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -35,33 +35,33 @@ discard block |
||
35 | 35 | */ |
36 | 36 | private function __construct() |
37 | 37 | { |
38 | - if ( is_admin() ) { |
|
38 | + if (is_admin()) { |
|
39 | 39 | // Add the admin page and settings. |
40 | - if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
41 | - add_action( 'network_admin_menu', array( $this, 'addmenu' ) ); |
|
40 | + if (autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
41 | + add_action('network_admin_menu', array($this, 'addmenu')); |
|
42 | 42 | } |
43 | 43 | |
44 | - add_action( 'admin_menu', array( $this, 'addmenu' ) ); |
|
45 | - add_action( 'admin_init', array( $this, 'registersettings' ) ); |
|
46 | - add_action( 'admin_init', array( 'PAnD', 'init' ) ); |
|
44 | + add_action('admin_menu', array($this, 'addmenu')); |
|
45 | + add_action('admin_init', array($this, 'registersettings')); |
|
46 | + add_action('admin_init', array('PAnD', 'init')); |
|
47 | 47 | |
48 | 48 | // Set meta info. |
49 | - if ( function_exists( 'plugin_row_meta' ) ) { |
|
49 | + if (function_exists('plugin_row_meta')) { |
|
50 | 50 | // 2.8 and higher. |
51 | - add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 ); |
|
52 | - } elseif ( function_exists( 'post_class' ) ) { |
|
51 | + add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2); |
|
52 | + } elseif (function_exists('post_class')) { |
|
53 | 53 | // 2.7 and lower. |
54 | - $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' ); |
|
55 | - add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) ); |
|
54 | + $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php'); |
|
55 | + add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta')); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // Clean cache? |
59 | - if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) { |
|
59 | + if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) { |
|
60 | 60 | autoptimizeCache::clearall(); |
61 | - autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 ); |
|
61 | + autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0); |
|
62 | 62 | } |
63 | 63 | |
64 | - $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http ); |
|
64 | + $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Adds the Autoptimize Toolbar to the Admin bar. |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | static public function instance() |
78 | 78 | { |
79 | 79 | // Only one instance. |
80 | - if ( null === self::$instance ) { |
|
80 | + if (null === self::$instance) { |
|
81 | 81 | self::$instance = new autoptimizeConfig(); |
82 | 82 | } |
83 | 83 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | public function show_network_message() { |
88 | 88 | ?> |
89 | 89 | <div class="wrap"> |
90 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
90 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
91 | 91 | <?php echo $this->ao_admin_tabs(); ?> |
92 | - <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p> |
|
92 | + <p style="font-size:120%;"><?php echo apply_filters('autoptimize_filter_settingsscreen_multisite_network_message', __('Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize')); ?></p> |
|
93 | 93 | </div> |
94 | 94 | <?php |
95 | 95 | } |
@@ -184,32 +184,32 @@ discard block |
||
184 | 184 | <div class="wrap"> |
185 | 185 | |
186 | 186 | <!-- Temporary nudge to disable aoccss power-up. --> |
187 | -<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?> |
|
187 | +<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?> |
|
188 | 188 | <div class="notice-info notice"><p> |
189 | - <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?> |
|
189 | + <?php _e('Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize'); ?> |
|
190 | 190 | </p></div> |
191 | 191 | <?php } ?> |
192 | 192 | |
193 | 193 | <div id="autoptimize_main"> |
194 | - <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
194 | + <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
195 | 195 | <?php echo $this->ao_admin_tabs(); ?> |
196 | 196 | |
197 | -<form method="post" action="<?php echo admin_url( 'options.php' ); ?>"> |
|
198 | -<?php settings_fields( 'autoptimize' ); ?> |
|
197 | +<form method="post" action="<?php echo admin_url('options.php'); ?>"> |
|
198 | +<?php settings_fields('autoptimize'); ?> |
|
199 | 199 | |
200 | 200 | <ul> |
201 | 201 | |
202 | 202 | <?php |
203 | 203 | // Only show enable site configuration in network site option. |
204 | -if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
204 | +if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
205 | 205 | ?> |
206 | 206 | <li class="itemDetail multiSite"> |
207 | - <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2> |
|
207 | + <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2> |
|
208 | 208 | <table class="form-table"> |
209 | 209 | <tr valign="top"> |
210 | - <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th> |
|
211 | - <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/> |
|
212 | - <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td> |
|
210 | + <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th> |
|
211 | + <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config') ? 'checked="checked" ' : ''; ?>/> |
|
212 | + <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td> |
|
213 | 213 | </tr> |
214 | 214 | </table> |
215 | 215 | </li> |
@@ -218,120 +218,120 @@ discard block |
||
218 | 218 | <?php } ?> |
219 | 219 | |
220 | 220 | <li class="itemDetail"> |
221 | -<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2> |
|
221 | +<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2> |
|
222 | 222 | <table class="form-table"> |
223 | 223 | <tr valign="top"> |
224 | -<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th> |
|
225 | -<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td> |
|
224 | +<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th> |
|
225 | +<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td> |
|
226 | 226 | </tr> |
227 | 227 | <tr valign="top" class="js_sub js_aggregate_master"> |
228 | -<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th> |
|
229 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/> |
|
230 | -<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td> |
|
228 | +<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th> |
|
229 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get('autoptimize_js_aggregate') ? 'checked="checked" ' : ''; ?>/> |
|
230 | +<?php _e('Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td> |
|
231 | 231 | </tr> |
232 | 232 | <tr valign="top" class="js_sub js_not_aggregate"> |
233 | -<th scope="row"><?php _e( 'Do not aggregate but defer?', 'autoptimize' ); ?></th> |
|
234 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get( 'autoptimize_js_defer_not_aggregate' ) ? 'checked="checked" ' : ''; ?>/> |
|
235 | -<?php _e( 'When JS is not aggregated, all linked JS-files can be deferred instead, making them non-render-blocking.', 'autoptimize' ); ?></label></td> |
|
233 | +<th scope="row"><?php _e('Do not aggregate but defer?', 'autoptimize'); ?></th> |
|
234 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get('autoptimize_js_defer_not_aggregate') ? 'checked="checked" ' : ''; ?>/> |
|
235 | +<?php _e('When JS is not aggregated, all linked JS-files can be deferred instead, making them non-render-blocking.', 'autoptimize'); ?></label></td> |
|
236 | 236 | </tr> |
237 | 237 | <tr valign="top" class="js_sub js_aggregate"> |
238 | -<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th> |
|
239 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/> |
|
240 | -<?php _e( 'Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize' ); ?></label></td> |
|
238 | +<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th> |
|
239 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/> |
|
240 | +<?php _e('Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize'); ?></label></td> |
|
241 | 241 | </tr> |
242 | 242 | <tr valign="top" class="js_sub js_aggregate"> |
243 | -<th scope="row"><?php _e( 'Force JavaScript in <head>?', 'autoptimize' ); ?></th> |
|
244 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/> |
|
245 | -<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td> |
|
243 | +<th scope="row"><?php _e('Force JavaScript in <head>?', 'autoptimize'); ?></th> |
|
244 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/> |
|
245 | +<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td> |
|
246 | 246 | </tr> |
247 | -<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?> |
|
247 | +<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?> |
|
248 | 248 | <tr valign="top" class="js_sub js_aggregate"> |
249 | 249 | <th scope="row"> |
250 | 250 | <?php |
251 | - _e( 'Look for scripts only in <head>?', 'autoptimize' ); |
|
252 | - echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>'; |
|
251 | + _e('Look for scripts only in <head>?', 'autoptimize'); |
|
252 | + echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>'; |
|
253 | 253 | ?> |
254 | 254 | </th> |
255 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/> |
|
256 | -<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td> |
|
255 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/> |
|
256 | +<?php _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize'); ?></label></td> |
|
257 | 257 | </tr> |
258 | 258 | <?php } ?> |
259 | 259 | <tr valign="top" class="js_sub"> |
260 | -<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th> |
|
261 | -<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js, js/jquery/jquery.min.js' ) ); ?>"/><br /> |
|
260 | +<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th> |
|
261 | +<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js, js/jquery/jquery.min.js')); ?>"/><br /> |
|
262 | 262 | <?php |
263 | -echo __( 'A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' ); |
|
263 | +echo __('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize'); |
|
264 | 264 | ?> |
265 | 265 | </label></td> |
266 | 266 | </tr> |
267 | 267 | <tr valign="top" class="js_sub js_aggregate"> |
268 | -<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th> |
|
269 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/> |
|
270 | -<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td> |
|
268 | +<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th> |
|
269 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/> |
|
270 | +<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td> |
|
271 | 271 | </tr> |
272 | 272 | </table> |
273 | 273 | </li> |
274 | 274 | |
275 | 275 | <li class="itemDetail"> |
276 | -<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2> |
|
276 | +<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2> |
|
277 | 277 | <table class="form-table"> |
278 | 278 | <tr valign="top"> |
279 | -<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th> |
|
280 | -<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td> |
|
279 | +<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th> |
|
280 | +<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td> |
|
281 | 281 | </tr> |
282 | 282 | <tr class="css_sub" valign="top"> |
283 | -<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th> |
|
284 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/> |
|
285 | -<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td> |
|
283 | +<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th> |
|
284 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get('autoptimize_css_aggregate') ? 'checked="checked" ' : ''; ?>/> |
|
285 | +<?php _e('Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td> |
|
286 | 286 | </tr> |
287 | 287 | <tr valign="top" class="css_sub css_aggregate"> |
288 | -<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th> |
|
289 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
290 | -<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td> |
|
288 | +<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th> |
|
289 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_include_inline', '1') ? 'checked="checked" ' : ''; ?>/> |
|
290 | +<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td> |
|
291 | 291 | </tr> |
292 | 292 | <tr class="css_sub css_aggregate" valign="top"> |
293 | -<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th> |
|
294 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/> |
|
295 | -<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td> |
|
293 | +<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th> |
|
294 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/> |
|
295 | +<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td> |
|
296 | 296 | </tr> |
297 | -<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?> |
|
297 | +<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?> |
|
298 | 298 | <tr valign="top" class="css_sub css_aggregate"> |
299 | 299 | <th scope="row"> |
300 | 300 | <?php |
301 | -_e( 'Look for styles only in <head>?', 'autoptimize' ); |
|
302 | -echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>'; |
|
301 | +_e('Look for styles only in <head>?', 'autoptimize'); |
|
302 | +echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>'; |
|
303 | 303 | ?> |
304 | 304 | </th> |
305 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/> |
|
306 | -<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td> |
|
305 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/> |
|
306 | +<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td> |
|
307 | 307 | </tr> |
308 | 308 | <?php } ?> |
309 | 309 | <tr valign="top" class="css_sub"> |
310 | -<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th> |
|
311 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/> |
|
310 | +<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th> |
|
311 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer') ? 'checked="checked" ' : ''; ?>/> |
|
312 | 312 | <?php |
313 | -_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' ); |
|
313 | +_e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize'); |
|
314 | 314 | echo ' '; |
315 | -$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' ); |
|
315 | +$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss'); |
|
316 | 316 | // translators: links "autoptimize critical CSS" tab. |
317 | -echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' ); |
|
317 | +echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>'); |
|
318 | 318 | ?> |
319 | 319 | </label></td> |
320 | 320 | </tr> |
321 | 321 | <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline"> |
322 | 322 | <th scope="row"></th> |
323 | -<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeStyles::sanitize_css( autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ) ); ?></textarea></label></td> |
|
323 | +<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeStyles::sanitize_css(autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline')); ?></textarea></label></td> |
|
324 | 324 | </tr> |
325 | 325 | <tr valign="top" class="css_sub css_aggregate"> |
326 | -<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th> |
|
327 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/> |
|
328 | -<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td> |
|
326 | +<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th> |
|
327 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_inline') ? 'checked="checked" ' : ''; ?>/> |
|
328 | +<?php _e('Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize'); ?></label></td> |
|
329 | 329 | </tr> |
330 | 330 | <tr valign="top" class="css_sub"> |
331 | -<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th> |
|
332 | -<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ) ); ?>"/><br /> |
|
331 | +<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th> |
|
332 | +<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css')); ?>"/><br /> |
|
333 | 333 | <?php |
334 | -echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' ); |
|
334 | +echo __('A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize'); |
|
335 | 335 | ?> |
336 | 336 | </label></td> |
337 | 337 | </tr> |
@@ -339,55 +339,55 @@ discard block |
||
339 | 339 | </li> |
340 | 340 | |
341 | 341 | <li class="itemDetail"> |
342 | -<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2> |
|
342 | +<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2> |
|
343 | 343 | <table class="form-table"> |
344 | 344 | <tr valign="top"> |
345 | -<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th> |
|
346 | -<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td> |
|
345 | +<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th> |
|
346 | +<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td> |
|
347 | 347 | </tr> |
348 | 348 | <tr class="html_sub" valign="top"> |
349 | -<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th> |
|
350 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/> |
|
351 | -<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td> |
|
349 | +<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th> |
|
350 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/> |
|
351 | +<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td> |
|
352 | 352 | </tr> |
353 | 353 | </table> |
354 | 354 | </li> |
355 | 355 | |
356 | 356 | <li class="itemDetail"> |
357 | -<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2> |
|
357 | +<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2> |
|
358 | 358 | <table class="form-table"> |
359 | 359 | <tr valign="top"> |
360 | -<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th> |
|
361 | -<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br /> |
|
362 | -<?php _e( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize' ); ?></label></td> |
|
360 | +<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th> |
|
361 | +<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url(autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', ''), array('http', 'https')); ?>" /><br /> |
|
362 | +<?php _e('Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize'); ?></label></td> |
|
363 | 363 | </tr> |
364 | 364 | </table> |
365 | 365 | </li> |
366 | 366 | |
367 | 367 | <li class="itemDetail"> |
368 | -<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2> |
|
368 | +<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2> |
|
369 | 369 | <table class="form-table" > |
370 | 370 | <tr valign="top" > |
371 | -<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th> |
|
372 | -<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td> |
|
371 | +<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th> |
|
372 | +<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td> |
|
373 | 373 | </tr> |
374 | 374 | <tr valign="top" > |
375 | -<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th> |
|
376 | -<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td> |
|
375 | +<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th> |
|
376 | +<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td> |
|
377 | 377 | </tr> |
378 | 378 | <tr valign="top" > |
379 | -<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th> |
|
379 | +<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th> |
|
380 | 380 | <td> |
381 | 381 | <?php |
382 | 382 | $ao_stat_arr = autoptimizeCache::stats(); |
383 | - if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) { |
|
384 | - $ao_cache_size = size_format( $ao_stat_arr[1], 2 ); |
|
383 | + if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) { |
|
384 | + $ao_cache_size = size_format($ao_stat_arr[1], 2); |
|
385 | 385 | $details = ''; |
386 | - if ( $ao_cache_size > 0 ) { |
|
387 | - $details = ', ~' . $ao_cache_size . ' total'; |
|
386 | + if ($ao_cache_size > 0) { |
|
387 | + $details = ', ~'.$ao_cache_size.' total'; |
|
388 | 388 | } |
389 | 389 | // translators: Kilobytes + timestamp shown. |
390 | - printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) ); |
|
390 | + printf(__('%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize'), $ao_stat_arr[0], $ao_cache_size, date('H:i e', $ao_stat_arr[2])); |
|
391 | 391 | } |
392 | 392 | ?> |
393 | 393 | </td> |
@@ -396,41 +396,41 @@ discard block |
||
396 | 396 | </li> |
397 | 397 | |
398 | 398 | <li class="itemDetail"> |
399 | -<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2> |
|
399 | +<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2> |
|
400 | 400 | <table class="form-table"> |
401 | 401 | <tr valign="top" > |
402 | - <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th> |
|
403 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
404 | - <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td> |
|
402 | + <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th> |
|
403 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/> |
|
404 | + <?php _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize'); ?></label></td> |
|
405 | 405 | </tr> |
406 | 406 | <?php |
407 | 407 | $_min_excl_class = ''; |
408 | - if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) { |
|
408 | + if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) { |
|
409 | 409 | $_min_excl_class = 'hidden'; |
410 | 410 | } |
411 | 411 | ?> |
412 | 412 | <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>"> |
413 | - <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th> |
|
414 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
415 | - <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td> |
|
413 | + <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th> |
|
414 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/> |
|
415 | + <?php _e('When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize'); ?></label></td> |
|
416 | 416 | </tr> |
417 | 417 | <tr valign="top"> |
418 | - <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th> |
|
419 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
420 | - <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td> |
|
418 | + <th scope="row"><?php _e('Enable 404 fallbacks?', 'autoptimize'); ?></th> |
|
419 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1') ? 'checked="checked" ' : ''; ?>/> |
|
420 | + <?php _e('Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize'); ?></label></td> |
|
421 | 421 | </tr> |
422 | 422 | <tr valign="top"> |
423 | - <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th> |
|
424 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
425 | - <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td> |
|
423 | + <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th> |
|
424 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/> |
|
425 | + <?php _e('By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize'); ?></label></td> |
|
426 | 426 | </tr> |
427 | 427 | <?php |
428 | - if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) { |
|
428 | + if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) { |
|
429 | 429 | ?> |
430 | 430 | <tr valign="top" > |
431 | - <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th> |
|
432 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/> |
|
433 | - <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label> |
|
431 | + <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th> |
|
432 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/> |
|
433 | + <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label> |
|
434 | 434 | </td> |
435 | 435 | </tr> |
436 | 436 | <?php } ?> |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | </ul> |
441 | 441 | |
442 | 442 | <p class="submit"> |
443 | -<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /> |
|
444 | -<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" /> |
|
443 | +<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /> |
|
444 | +<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" /> |
|
445 | 445 | </p> |
446 | 446 | |
447 | 447 | </form> |
@@ -450,46 +450,46 @@ discard block |
||
450 | 450 | <div class="autoptimize_banner hidden"> |
451 | 451 | <ul> |
452 | 452 | <?php |
453 | - if ( $this->settings_screen_do_remote_http ) { |
|
454 | - $ao_banner = get_transient( 'autoptimize_banner' ); |
|
455 | - if ( empty( $ao_banner ) ) { |
|
456 | - $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION ); |
|
457 | - if ( ! is_wp_error( $banner_resp ) ) { |
|
458 | - if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) { |
|
459 | - $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) ); |
|
460 | - set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS ); |
|
453 | + if ($this->settings_screen_do_remote_http) { |
|
454 | + $ao_banner = get_transient('autoptimize_banner'); |
|
455 | + if (empty($ao_banner)) { |
|
456 | + $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION); |
|
457 | + if (!is_wp_error($banner_resp)) { |
|
458 | + if ('200' == wp_remote_retrieve_response_code($banner_resp)) { |
|
459 | + $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp)); |
|
460 | + set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS); |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | } |
464 | 464 | echo $ao_banner; |
465 | 465 | } |
466 | 466 | ?> |
467 | - <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li> |
|
468 | - <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li> |
|
467 | + <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li> |
|
468 | + <li><?php _e('Happy with Autoptimize?', 'autoptimize'); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e('Try my other plugins!', 'autoptimize'); ?></a></li> |
|
469 | 469 | </ul> |
470 | 470 | </div> |
471 | 471 | <div style="margin-left:10px;margin-top:-5px;"> |
472 | 472 | <h2> |
473 | - <?php _e( 'futtta about', 'autoptimize' ); ?> |
|
473 | + <?php _e('futtta about', 'autoptimize'); ?> |
|
474 | 474 | <select id="feed_dropdown" > |
475 | - <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option> |
|
476 | - <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option> |
|
477 | - <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option> |
|
475 | + <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option> |
|
476 | + <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option> |
|
477 | + <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option> |
|
478 | 478 | </select> |
479 | 479 | </h2> |
480 | 480 | <div id="futtta_feed"> |
481 | 481 | <div id="autoptimizefeed"> |
482 | - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?> |
|
482 | + <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?> |
|
483 | 483 | </div> |
484 | 484 | <div id="wordpressfeed"> |
485 | - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?> |
|
485 | + <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?> |
|
486 | 486 | </div> |
487 | 487 | <div id="webtechfeed"> |
488 | - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?> |
|
488 | + <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?> |
|
489 | 489 | </div> |
490 | 490 | </div> |
491 | 491 | </div> |
492 | - <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div> |
|
492 | + <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e('Do not donate for this plugin!', 'autoptimize'); ?>"></a></div> |
|
493 | 493 | </div> |
494 | 494 | |
495 | 495 | <script type="text/javascript"> |
@@ -655,82 +655,82 @@ discard block |
||
655 | 655 | |
656 | 656 | public function addmenu() |
657 | 657 | { |
658 | - if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
658 | + if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
659 | 659 | // multisite, network admin, ao network activated: add normal settings page at network level. |
660 | - $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) ); |
|
661 | - } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) { |
|
660 | + $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config')); |
|
661 | + } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) { |
|
662 | 662 | // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options. |
663 | - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) ); |
|
663 | + $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message')); |
|
664 | 664 | } else { |
665 | 665 | // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on. |
666 | - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) ); |
|
666 | + $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config')); |
|
667 | 667 | } |
668 | 668 | |
669 | - add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) ); |
|
670 | - add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) ); |
|
669 | + add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts')); |
|
670 | + add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles')); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | public function autoptimize_admin_scripts() |
674 | 674 | { |
675 | - wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
676 | - wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
675 | + wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true); |
|
676 | + wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | public function autoptimize_admin_styles() |
680 | 680 | { |
681 | - wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) ); |
|
682 | - wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) ); |
|
681 | + wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__)); |
|
682 | + wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__)); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | public function registersettings() { |
686 | - register_setting( 'autoptimize', 'autoptimize_html' ); |
|
687 | - register_setting( 'autoptimize', 'autoptimize_html_keepcomments' ); |
|
688 | - register_setting( 'autoptimize', 'autoptimize_enable_site_config' ); |
|
689 | - register_setting( 'autoptimize', 'autoptimize_js' ); |
|
690 | - register_setting( 'autoptimize', 'autoptimize_js_aggregate' ); |
|
691 | - register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' ); |
|
692 | - register_setting( 'autoptimize', 'autoptimize_js_exclude' ); |
|
693 | - register_setting( 'autoptimize', 'autoptimize_js_trycatch' ); |
|
694 | - register_setting( 'autoptimize', 'autoptimize_js_justhead' ); |
|
695 | - register_setting( 'autoptimize', 'autoptimize_js_forcehead' ); |
|
696 | - register_setting( 'autoptimize', 'autoptimize_js_include_inline' ); |
|
697 | - register_setting( 'autoptimize', 'autoptimize_css' ); |
|
698 | - register_setting( 'autoptimize', 'autoptimize_css_aggregate' ); |
|
699 | - register_setting( 'autoptimize', 'autoptimize_css_exclude' ); |
|
700 | - register_setting( 'autoptimize', 'autoptimize_css_justhead' ); |
|
701 | - register_setting( 'autoptimize', 'autoptimize_css_datauris' ); |
|
702 | - register_setting( 'autoptimize', 'autoptimize_css_defer' ); |
|
703 | - register_setting( 'autoptimize', 'autoptimize_css_defer_inline' ); |
|
704 | - register_setting( 'autoptimize', 'autoptimize_css_inline' ); |
|
705 | - register_setting( 'autoptimize', 'autoptimize_css_include_inline' ); |
|
706 | - register_setting( 'autoptimize', 'autoptimize_cdn_url' ); |
|
707 | - register_setting( 'autoptimize', 'autoptimize_cache_clean' ); |
|
708 | - register_setting( 'autoptimize', 'autoptimize_cache_nogzip' ); |
|
709 | - register_setting( 'autoptimize', 'autoptimize_optimize_logged' ); |
|
710 | - register_setting( 'autoptimize', 'autoptimize_optimize_checkout' ); |
|
711 | - register_setting( 'autoptimize', 'autoptimize_minify_excluded' ); |
|
712 | - register_setting( 'autoptimize', 'autoptimize_cache_fallback' ); |
|
686 | + register_setting('autoptimize', 'autoptimize_html'); |
|
687 | + register_setting('autoptimize', 'autoptimize_html_keepcomments'); |
|
688 | + register_setting('autoptimize', 'autoptimize_enable_site_config'); |
|
689 | + register_setting('autoptimize', 'autoptimize_js'); |
|
690 | + register_setting('autoptimize', 'autoptimize_js_aggregate'); |
|
691 | + register_setting('autoptimize', 'autoptimize_js_defer_not_aggregate'); |
|
692 | + register_setting('autoptimize', 'autoptimize_js_exclude'); |
|
693 | + register_setting('autoptimize', 'autoptimize_js_trycatch'); |
|
694 | + register_setting('autoptimize', 'autoptimize_js_justhead'); |
|
695 | + register_setting('autoptimize', 'autoptimize_js_forcehead'); |
|
696 | + register_setting('autoptimize', 'autoptimize_js_include_inline'); |
|
697 | + register_setting('autoptimize', 'autoptimize_css'); |
|
698 | + register_setting('autoptimize', 'autoptimize_css_aggregate'); |
|
699 | + register_setting('autoptimize', 'autoptimize_css_exclude'); |
|
700 | + register_setting('autoptimize', 'autoptimize_css_justhead'); |
|
701 | + register_setting('autoptimize', 'autoptimize_css_datauris'); |
|
702 | + register_setting('autoptimize', 'autoptimize_css_defer'); |
|
703 | + register_setting('autoptimize', 'autoptimize_css_defer_inline'); |
|
704 | + register_setting('autoptimize', 'autoptimize_css_inline'); |
|
705 | + register_setting('autoptimize', 'autoptimize_css_include_inline'); |
|
706 | + register_setting('autoptimize', 'autoptimize_cdn_url'); |
|
707 | + register_setting('autoptimize', 'autoptimize_cache_clean'); |
|
708 | + register_setting('autoptimize', 'autoptimize_cache_nogzip'); |
|
709 | + register_setting('autoptimize', 'autoptimize_optimize_logged'); |
|
710 | + register_setting('autoptimize', 'autoptimize_optimize_checkout'); |
|
711 | + register_setting('autoptimize', 'autoptimize_minify_excluded'); |
|
712 | + register_setting('autoptimize', 'autoptimize_cache_fallback'); |
|
713 | 713 | } |
714 | 714 | |
715 | - public function setmeta( $links, $file = null ) |
|
715 | + public function setmeta($links, $file = null) |
|
716 | 716 | { |
717 | 717 | // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/. |
718 | 718 | // Do it only once - saves time. |
719 | 719 | static $plugin; |
720 | - if ( empty( $plugin ) ) { |
|
721 | - $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' ); |
|
720 | + if (empty($plugin)) { |
|
721 | + $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php'); |
|
722 | 722 | } |
723 | 723 | |
724 | - if ( null === $file ) { |
|
724 | + if (null === $file) { |
|
725 | 725 | // 2.7 and lower. |
726 | - $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ); |
|
727 | - array_unshift( $links, $settings_link ); |
|
726 | + $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')); |
|
727 | + array_unshift($links, $settings_link); |
|
728 | 728 | } else { |
729 | 729 | // 2.8 and higher. |
730 | 730 | // If it's us, add the link. |
731 | - if ( $file === $plugin ) { |
|
732 | - $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) ); |
|
733 | - $links = array_merge( $links, $newlink ); |
|
731 | + if ($file === $plugin) { |
|
732 | + $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'))); |
|
733 | + $links = array_merge($links, $newlink); |
|
734 | 734 | } |
735 | 735 | } |
736 | 736 | |
@@ -807,8 +807,8 @@ discard block |
||
807 | 807 | 'autoptimize_imgopt_select_field_2' => '2', // quality glossy. |
808 | 808 | 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off. |
809 | 809 | 'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed). |
810 | - 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty. |
|
811 | - 'autoptimize_imgopt_text_field_6' => '', // optimization exclusions empty. |
|
810 | + 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty. |
|
811 | + 'autoptimize_imgopt_text_field_6' => '', // optimization exclusions empty. |
|
812 | 812 | 'autoptimize_imgopt_number_field_7' => '0', // lazy load from nth image (0 = lazyload all). |
813 | 813 | ); |
814 | 814 | return $defaults; |
@@ -821,58 +821,58 @@ discard block |
||
821 | 821 | * |
822 | 822 | * @return string |
823 | 823 | */ |
824 | - public static function get_ao_css_preload_onload( $media = 'all' ) |
|
824 | + public static function get_ao_css_preload_onload($media = 'all') |
|
825 | 825 | { |
826 | - $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" ); |
|
826 | + $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.media='".$media."';"); |
|
827 | 827 | return $preload_onload; |
828 | 828 | } |
829 | 829 | |
830 | - public function get( $key ) |
|
830 | + public function get($key) |
|
831 | 831 | { |
832 | - if ( ! is_array( $this->config ) ) { |
|
832 | + if (!is_array($this->config)) { |
|
833 | 833 | // Default config. |
834 | 834 | $config = self::get_defaults(); |
835 | 835 | |
836 | 836 | // Override with user settings. |
837 | - foreach ( array_keys( $config ) as $name ) { |
|
838 | - $conf = autoptimizeOptionWrapper::get_option( $name ); |
|
839 | - if ( false !== $conf ) { |
|
837 | + foreach (array_keys($config) as $name) { |
|
838 | + $conf = autoptimizeOptionWrapper::get_option($name); |
|
839 | + if (false !== $conf) { |
|
840 | 840 | // It was set before! |
841 | - $config[ $name ] = $conf; |
|
841 | + $config[$name] = $conf; |
|
842 | 842 | } |
843 | 843 | } |
844 | 844 | |
845 | 845 | // Save for next call. |
846 | - $this->config = apply_filters( 'autoptimize_filter_get_config', $config ); |
|
846 | + $this->config = apply_filters('autoptimize_filter_get_config', $config); |
|
847 | 847 | } |
848 | 848 | |
849 | - if ( isset( $this->config[ $key ] ) ) { |
|
850 | - return $this->config[ $key ]; |
|
849 | + if (isset($this->config[$key])) { |
|
850 | + return $this->config[$key]; |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | return false; |
854 | 854 | } |
855 | 855 | |
856 | - private function get_futtta_feeds( $url ) { |
|
857 | - if ( $this->settings_screen_do_remote_http ) { |
|
858 | - $rss = fetch_feed( $url ); |
|
856 | + private function get_futtta_feeds($url) { |
|
857 | + if ($this->settings_screen_do_remote_http) { |
|
858 | + $rss = fetch_feed($url); |
|
859 | 859 | $maxitems = 0; |
860 | 860 | |
861 | - if ( ! is_wp_error( $rss ) ) { |
|
862 | - $maxitems = $rss->get_item_quantity( 7 ); |
|
863 | - $rss_items = $rss->get_items( 0, $maxitems ); |
|
861 | + if (!is_wp_error($rss)) { |
|
862 | + $maxitems = $rss->get_item_quantity(7); |
|
863 | + $rss_items = $rss->get_items(0, $maxitems); |
|
864 | 864 | } |
865 | 865 | ?> |
866 | 866 | <ul> |
867 | - <?php if ( 0 == $maxitems ) : ?> |
|
868 | - <li><?php _e( 'No items', 'autoptimize' ); ?></li> |
|
867 | + <?php if (0 == $maxitems) : ?> |
|
868 | + <li><?php _e('No items', 'autoptimize'); ?></li> |
|
869 | 869 | <?php else : ?> |
870 | - <?php foreach ( $rss_items as $item ) : ?> |
|
870 | + <?php foreach ($rss_items as $item) : ?> |
|
871 | 871 | <li> |
872 | - <a href="<?php echo esc_url( $item->get_permalink() ); ?>" |
|
872 | + <a href="<?php echo esc_url($item->get_permalink()); ?>" |
|
873 | 873 | <?php // translators: the variable contains a date. ?> |
874 | - title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>"> |
|
875 | - <?php echo esc_html( $item->get_title() ); ?> |
|
874 | + title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>"> |
|
875 | + <?php echo esc_html($item->get_title()); ?> |
|
876 | 876 | </a> |
877 | 877 | </li> |
878 | 878 | <?php endforeach; ?> |
@@ -885,23 +885,23 @@ discard block |
||
885 | 885 | static function ao_admin_tabs() |
886 | 886 | { |
887 | 887 | // based on http://wordpress.stackexchange.com/a/58826 . |
888 | - $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS & HTML', 'autoptimize' ) ) ); |
|
888 | + $tabs = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS & HTML', 'autoptimize'))); |
|
889 | 889 | $tab_content = ''; |
890 | - $tabs_count = count( $tabs ); |
|
891 | - if ( $tabs_count > 1 ) { |
|
892 | - if ( isset( $_GET['page'] ) ) { |
|
890 | + $tabs_count = count($tabs); |
|
891 | + if ($tabs_count > 1) { |
|
892 | + if (isset($_GET['page'])) { |
|
893 | 893 | $current_id = $_GET['page']; |
894 | 894 | } else { |
895 | 895 | $current_id = 'autoptimize'; |
896 | 896 | } |
897 | 897 | $tab_content .= '<h2 class="nav-tab-wrapper">'; |
898 | - foreach ( $tabs as $tab_id => $tab_name ) { |
|
899 | - if ( $current_id == $tab_id ) { |
|
898 | + foreach ($tabs as $tab_id => $tab_name) { |
|
899 | + if ($current_id == $tab_id) { |
|
900 | 900 | $class = ' nav-tab-active'; |
901 | 901 | } else { |
902 | 902 | $class = ''; |
903 | 903 | } |
904 | - $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>'; |
|
904 | + $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>'; |
|
905 | 905 | } |
906 | 906 | $tab_content .= '</h2>'; |
907 | 907 | } else { |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | */ |
919 | 919 | public static function is_admin_and_not_ajax() |
920 | 920 | { |
921 | - return ( is_admin() && ! self::doing_ajax() ); |
|
921 | + return (is_admin() && !self::doing_ajax()); |
|
922 | 922 | } |
923 | 923 | |
924 | 924 | /** |
@@ -928,10 +928,10 @@ discard block |
||
928 | 928 | */ |
929 | 929 | protected static function doing_ajax() |
930 | 930 | { |
931 | - if ( function_exists( 'wp_doing_ajax' ) ) { |
|
931 | + if (function_exists('wp_doing_ajax')) { |
|
932 | 932 | return wp_doing_ajax(); |
933 | 933 | } |
934 | - return ( defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
934 | + return (defined('DOING_AJAX') && DOING_AJAX); |
|
935 | 935 | } |
936 | 936 | |
937 | 937 | /** |
@@ -940,7 +940,7 @@ discard block |
||
940 | 940 | * @return bool |
941 | 941 | */ |
942 | 942 | public static function should_show_menu_tabs() { |
943 | - if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) { |
|
943 | + if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) { |
|
944 | 944 | return true; |
945 | 945 | } else { |
946 | 946 | return false; |