@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | namespace ZWF; |
| 16 | 16 | |
| 17 | -defined( 'ABSPATH' ) || exit; |
|
| 17 | +defined('ABSPATH') || exit; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Bootstraps the plugin. |
@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | * @return void |
| 25 | 25 | */ |
| 26 | 26 | function bootstrap() { |
| 27 | - if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
| 27 | + if (file_exists(__DIR__ . '/vendor/autoload.php')) { |
|
| 28 | 28 | // Composer-generated autoload file. |
| 29 | 29 | include_once __DIR__ . '/vendor/autoload.php'; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $combiner = new GoogleFontsOptimizer(); |
| 33 | - add_action( 'wp', [ $combiner, 'run' ] ); |
|
| 33 | + add_action('wp', [ $combiner, 'run' ]); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | -add_action( 'plugins_loaded', __NAMESPACE__ . '\\bootstrap', 0 ); |
|
| 36 | +add_action('plugins_loaded', __NAMESPACE__ . '\\bootstrap', 0); |
|
@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | const FILTER_OB_CLEANER = 'zwf_gfo_clean_ob'; |
| 14 | 14 | const DEFAULT_OB_CLEANER = false; |
| 15 | 15 | |
| 16 | - protected $candidates = []; |
|
| 16 | + protected $candidates = [ ]; |
|
| 17 | 17 | |
| 18 | - public function __construct(array $candidates = []) |
|
| 18 | + public function __construct(array $candidates = [ ]) |
|
| 19 | 19 | { |
| 20 | 20 | if (!empty($candidates)) { |
| 21 | 21 | $this->setCandidates($candidates); |
@@ -29,13 +29,13 @@ discard block |
||
| 29 | 29 | switch ($mode) { |
| 30 | 30 | case 'markup': |
| 31 | 31 | // Scan and optimize the entire page markup (uses more memory and requires DOM, but works on [almost] any theme) |
| 32 | - add_action('template_redirect', [$this, 'startBuffering'], 11); |
|
| 32 | + add_action('template_redirect', [ $this, 'startBuffering' ], 11); |
|
| 33 | 33 | break; |
| 34 | 34 | |
| 35 | 35 | case self::DEFAULT_OPERATION_MODE: |
| 36 | 36 | default: |
| 37 | 37 | // Scan only things added via wp_enqueue_style (uses slightly less memory usually, but requires a decently coded theme) |
| 38 | - add_filter('print_styles_array', [$this, 'processStylesHandles']); |
|
| 38 | + add_filter('print_styles_array', [ $this, 'processStylesHandles' ]); |
|
| 39 | 39 | break; |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @return bool |
| 49 | 49 | */ |
| 50 | - protected function hasEnoughElements(array $candidates = []) |
|
| 50 | + protected function hasEnoughElements(array $candidates = [ ]) |
|
| 51 | 51 | { |
| 52 | 52 | $has = true; |
| 53 | 53 | |
@@ -82,20 +82,20 @@ discard block |
||
| 82 | 82 | // Weee... |
| 83 | 83 | $fonts_array = $this->getFontsArray($this->getCandidates()); |
| 84 | 84 | if (!empty($fonts_array)) { |
| 85 | - if (isset($fonts_array['complete'])) { |
|
| 85 | + if (isset($fonts_array[ 'complete' ])) { |
|
| 86 | 86 | $combined_font_url = $this->buildGoogleFontsUrlFromFontsArray($fonts_array); |
| 87 | 87 | $handle_name = 'zwf-gfo-combined'; |
| 88 | 88 | $this->enqueueStyle($handle_name, $combined_font_url); |
| 89 | - $handles[] = $handle_name; |
|
| 89 | + $handles[ ] = $handle_name; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if (isset($fonts_array['partial'])) { |
|
| 92 | + if (isset($fonts_array[ 'partial' ])) { |
|
| 93 | 93 | $cnt = 0; |
| 94 | - foreach ($fonts_array['partial']['url'] as $url) { |
|
| 94 | + foreach ($fonts_array[ 'partial' ][ 'url' ] as $url) { |
|
| 95 | 95 | $cnt++; |
| 96 | 96 | $handle_name = 'zwf-gfo-combined-txt-' . $cnt; |
| 97 | 97 | $this->enqueueStyle($handle_name, $url); |
| 98 | - $handles[] = $handle_name; |
|
| 98 | + $handles[ ] = $handle_name; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | public function findCandidateHandles(array $handles) |
| 123 | 123 | { |
| 124 | 124 | $handler = \wp_styles(); |
| 125 | - $candidate_handles = []; |
|
| 125 | + $candidate_handles = [ ]; |
|
| 126 | 126 | |
| 127 | 127 | foreach ($handles as $handle) { |
| 128 | 128 | // $url = $handler->registered[ $handle ]->src; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $url = $dep->src; |
| 132 | 132 | if ($this->isGoogleWebFontUrl($url)) { |
| 133 | 133 | $this->addCandidate($url); |
| 134 | - $candidate_handles[$handle] = $url; |
|
| 134 | + $candidate_handles[ $handle ] = $url; |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * |
| 165 | 165 | * @return void |
| 166 | 166 | */ |
| 167 | - public function enqueueStyle($handle, $url, $deps = [], $version = null) |
|
| 167 | + public function enqueueStyle($handle, $url, $deps = [ ], $version = null) |
|
| 168 | 168 | { |
| 169 | 169 | //\wp_register_style($handle, $url, $deps, $version); |
| 170 | 170 | \wp_enqueue_style($handle, $url, $deps, $version); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $rel = null; |
| 193 | 193 | $type = null; |
| 194 | 194 | $href = null; |
| 195 | - $find = ['rel', 'type', 'href']; |
|
| 195 | + $find = [ 'rel', 'type', 'href' ]; |
|
| 196 | 196 | foreach ($find as $attr) { |
| 197 | 197 | if ($link_node->hasAttribute($attr)) { |
| 198 | 198 | $$attr = $link_node->getAttribute($attr); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | // Process what we found and modify original markup with our replacement |
| 216 | 216 | $fonts_array = $this->getFontsArray($candidates); |
| 217 | 217 | $font_markup = $this->buildFontsMarkup($fonts_array); |
| 218 | - $markup = $this->modifyMarkup($markup, $font_markup, $fonts_array['links']); |
|
| 218 | + $markup = $this->modifyMarkup($markup, $font_markup, $fonts_array[ 'links' ]); |
|
| 219 | 219 | |
| 220 | 220 | return $markup; |
| 221 | 221 | } |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | }*/ |
| 266 | 266 | |
| 267 | 267 | // Start our own buffering |
| 268 | - ob_start([$this, 'endBuffering']); |
|
| 268 | + ob_start([ $this, 'endBuffering' ]); |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | // Check w3tc UA |
| 317 | - if ($buffer && defined('W3TC_POWERED_BY') && isset($_SERVER['HTTP_USER_AGENT'])) { |
|
| 318 | - if (false !== stristr($_SERVER['HTTP_USER_AGENT'], W3TC_POWERED_BY)) { |
|
| 317 | + if ($buffer && defined('W3TC_POWERED_BY') && isset($_SERVER[ 'HTTP_USER_AGENT' ])) { |
|
| 318 | + if (false !== stristr($_SERVER[ 'HTTP_USER_AGENT' ], W3TC_POWERED_BY)) { |
|
| 319 | 319 | $buffer = false; |
| 320 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // Check for Disqus actions |
| 324 | - if ($buffer && isset($_GET['cf_action']) && !empty($_GET['cf_action'])) { |
|
| 324 | + if ($buffer && isset($_GET[ 'cf_action' ]) && !empty($_GET[ 'cf_action' ])) { |
|
| 325 | 325 | $buffer = false; |
| 326 | 326 | } |
| 327 | 327 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | */ |
| 364 | 364 | |
| 365 | 365 | // if ($has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet) { |
| 366 | - if ($has_no_html_tag && ! $has_html5_doctype || $has_xsl_stylesheet) { |
|
| 366 | + if ($has_no_html_tag && !$has_html5_doctype || $has_xsl_stylesheet) { |
|
| 367 | 367 | $doable = false; |
| 368 | 368 | } |
| 369 | 369 | |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | /** |
| 397 | 397 | * @param array $urls |
| 398 | 398 | */ |
| 399 | - public function setCandidates(array $urls = []) |
|
| 399 | + public function setCandidates(array $urls = [ ]) |
|
| 400 | 400 | { |
| 401 | 401 | $this->candidates = $urls; |
| 402 | 402 | } |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | */ |
| 407 | 407 | public function addCandidate($url) |
| 408 | 408 | { |
| 409 | - $this->candidates[] = $url; |
|
| 409 | + $this->candidates[ ] = $url; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -447,11 +447,11 @@ discard block |
||
| 447 | 447 | * |
| 448 | 448 | * @return null|string |
| 449 | 449 | */ |
| 450 | - public function buildGoogleFontsUrl(array $fonts, $subsets = []) |
|
| 450 | + public function buildGoogleFontsUrl(array $fonts, $subsets = [ ]) |
|
| 451 | 451 | { |
| 452 | 452 | $base_url = '//fonts.googleapis.com/css'; |
| 453 | - $font_args = []; |
|
| 454 | - $family = []; |
|
| 453 | + $font_args = [ ]; |
|
| 454 | + $family = [ ]; |
|
| 455 | 455 | $url = null; |
| 456 | 456 | |
| 457 | 457 | foreach ($fonts as $font_name => $font_weight) { |
@@ -459,21 +459,21 @@ discard block |
||
| 459 | 459 | if (is_array($font_weight)) { |
| 460 | 460 | $font_weight = implode(',', $font_weight); |
| 461 | 461 | } |
| 462 | - $family[] = trim($font_name . ':' . trim($font_weight)); |
|
| 462 | + $family[ ] = trim($font_name . ':' . trim($font_weight)); |
|
| 463 | 463 | } else { |
| 464 | - $family[] = trim($font_name); |
|
| 464 | + $family[ ] = trim($font_name); |
|
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (!empty($family)) { |
| 469 | 469 | $family = implode('|', $family); |
| 470 | - $font_args['family'] = $family; // spaces in font names must be encoded as '+' |
|
| 470 | + $font_args[ 'family' ] = $family; // spaces in font names must be encoded as '+' |
|
| 471 | 471 | if (!empty($subsets)) { |
| 472 | 472 | if (is_array($subsets)) { |
| 473 | 473 | $subsets = array_unique($subsets); |
| 474 | 474 | $subsets = implode(',', $subsets); |
| 475 | 475 | } |
| 476 | - $font_args['subset'] = trim($subsets); |
|
| 476 | + $font_args[ 'subset' ] = trim($subsets); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | $url = $base_url . '?' . http_build_query($font_args); |
@@ -490,42 +490,42 @@ discard block |
||
| 490 | 490 | * |
| 491 | 491 | * @return array |
| 492 | 492 | */ |
| 493 | - protected function getFontsArray(array $candidates = []) |
|
| 493 | + protected function getFontsArray(array $candidates = [ ]) |
|
| 494 | 494 | { |
| 495 | - $fonts = []; |
|
| 495 | + $fonts = [ ]; |
|
| 496 | 496 | |
| 497 | 497 | if (!empty($candidates)) { |
| 498 | 498 | foreach ($candidates as $candidate) { |
| 499 | - $fonts['links'][] = $candidate; |
|
| 499 | + $fonts[ 'links' ][ ] = $candidate; |
|
| 500 | 500 | |
| 501 | - $query_params = []; |
|
| 501 | + $query_params = [ ]; |
|
| 502 | 502 | parse_str(parse_url($candidate, PHP_URL_QUERY), $query_params); |
| 503 | 503 | |
| 504 | - if (isset($query_params['text'])) { |
|
| 504 | + if (isset($query_params[ 'text' ])) { |
|
| 505 | 505 | // Fonts with character limitations are segregated into |
| 506 | 506 | // under 'partial' (when `text` query param is used) |
| 507 | - $font_family = explode(':', $query_params['family']); |
|
| 508 | - $fonts['partial']['name'][] = $font_family[0]; |
|
| 509 | - $fonts['partial']['url'][] = $candidate; |
|
| 507 | + $font_family = explode(':', $query_params[ 'family' ]); |
|
| 508 | + $fonts[ 'partial' ][ 'name' ][ ] = $font_family[ 0 ]; |
|
| 509 | + $fonts[ 'partial' ][ 'url' ][ ] = $candidate; |
|
| 510 | 510 | } else { |
| 511 | - foreach (explode('|', $query_params['family']) as $families) { |
|
| 511 | + foreach (explode('|', $query_params[ 'family' ]) as $families) { |
|
| 512 | 512 | $font_family = explode(':', $families); |
| 513 | 513 | $subset = false; |
| 514 | - if (isset($query_params['subset'])) { |
|
| 514 | + if (isset($query_params[ 'subset' ])) { |
|
| 515 | 515 | // Use the found subset parameter |
| 516 | - $subset = $query_params['subset']; |
|
| 517 | - } elseif (isset($font_family[2])) { |
|
| 516 | + $subset = $query_params[ 'subset' ]; |
|
| 517 | + } elseif (isset($font_family[ 2 ])) { |
|
| 518 | 518 | // Use the subset in the family string |
| 519 | - $subset = $font_family[2]; |
|
| 519 | + $subset = $font_family[ 2 ]; |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | - if (strlen($font_family[0]) > 0 && strlen($font_family[1]) > 0) { |
|
| 523 | - $font_string = $font_family[0] . ':' . $font_family[1]; |
|
| 522 | + if (strlen($font_family[ 0 ]) > 0 && strlen($font_family[ 1 ]) > 0) { |
|
| 523 | + $font_string = $font_family[ 0 ] . ':' . $font_family[ 1 ]; |
|
| 524 | 524 | if ($subset) { |
| 525 | 525 | $font_string .= ':' . $subset; |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - $fonts['complete'][] = $font_string; |
|
| 528 | + $fonts[ 'complete' ][ ] = $font_string; |
|
| 529 | 529 | } |
| 530 | 530 | } |
| 531 | 531 | } |
@@ -544,20 +544,20 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | protected function buildGoogleFontsUrlFromFontsArray(array $fonts_array) |
| 546 | 546 | { |
| 547 | - $fonts = []; |
|
| 548 | - $subsets = []; |
|
| 547 | + $fonts = [ ]; |
|
| 548 | + $subsets = [ ]; |
|
| 549 | 549 | |
| 550 | - foreach ($fonts_array['complete'] as $font_string) { |
|
| 550 | + foreach ($fonts_array[ 'complete' ] as $font_string) { |
|
| 551 | 551 | $parts = explode(':', $font_string); |
| 552 | - $fonts[ $parts[0] ] = $parts[1]; |
|
| 553 | - if (isset($parts[2])) { |
|
| 554 | - $elements = explode(',', $parts[2]); |
|
| 552 | + $fonts[ $parts[ 0 ] ] = $parts[ 1 ]; |
|
| 553 | + if (isset($parts[ 2 ])) { |
|
| 554 | + $elements = explode(',', $parts[ 2 ]); |
|
| 555 | 555 | if (!empty($elements)) { |
| 556 | 556 | foreach ($elements as $subset) { |
| 557 | - $subsets[] = $subset; |
|
| 557 | + $subsets[ ] = $subset; |
|
| 558 | 558 | } |
| 559 | 559 | } else { |
| 560 | - $subsets[] = $parts[2]; |
|
| 560 | + $subsets[ ] = $parts[ 2 ]; |
|
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | 563 | } |
@@ -596,22 +596,22 @@ discard block |
||
| 596 | 596 | $font_url = $this->buildGoogleFontsUrlFromFontsArray($fonts_array); |
| 597 | 597 | $markup = '<link rel="stylesheet" type="text/css" href="' . $this->encodeUnencodedAmpersands($font_url) . '">'; |
| 598 | 598 | |
| 599 | - if (isset($fonts_array['partial'])) { |
|
| 600 | - if (is_array($fonts_array['partial']['url'])) { |
|
| 601 | - foreach ($fonts_array['partial']['url'] as $other) { |
|
| 599 | + if (isset($fonts_array[ 'partial' ])) { |
|
| 600 | + if (is_array($fonts_array[ 'partial' ][ 'url' ])) { |
|
| 601 | + foreach ($fonts_array[ 'partial' ][ 'url' ] as $other) { |
|
| 602 | 602 | $markup .= '<link rel="stylesheet" type="text/css" href="' . $this->encodeUnencodedAmpersands($other) . '">'; |
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | } else { |
| 607 | 607 | // Bulding WebFont script loader |
| 608 | - $families = "'" . implode("', '", $fonts_array['complete']) . "'"; |
|
| 608 | + $families = "'" . implode("', '", $fonts_array[ 'complete' ]) . "'"; |
|
| 609 | 609 | |
| 610 | 610 | // Check "other" |
| 611 | - if (isset($fonts_array['partial'])) { |
|
| 611 | + if (isset($fonts_array[ 'partial' ])) { |
|
| 612 | 612 | $other = ", |
| 613 | - custom: { families: [ '" . implode("', '", $fonts_array['partial']['name']) . "' ], |
|
| 614 | - urls: [ '" . implode("', '", $fonts_array['partial']['url']) . "' ] } |
|
| 613 | + custom: { families: [ '" . implode("', '", $fonts_array[ 'partial' ][ 'name' ]) . "' ], |
|
| 614 | + urls: [ '" . implode("', '", $fonts_array[ 'partial' ][ 'url' ]) . "' ] } |
|
| 615 | 615 | "; |
| 616 | 616 | } else { |
| 617 | 617 | $other = ''; |