PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | minify/class-wp-optimize-minify-fonts.php +20 -14 3.2.20 → 4.7.0 View file →
@@ -9,9 +9,9 @@
9 9
10 10 /**
11 11 * Get a list of Google fonts
12 12 *
13 - * @return Array
13 + * @return array
14 14 */
15 15 public static function get_google_fonts() {
16 16 // https://www.googleapis.com/webfonts/v1/webfonts?sort=alpha
17 17 $google_fonts_file = WPO_PLUGIN_MAIN_PATH.'google-fonts.json';
@@ -21,9 +21,9 @@
21 21 return array();
22 22 }
23 23
24 24 /**
25 - * Check if the google font exist or not
25 + * Check if the Google font exist or not
26 26 *
27 27 * @param string $font
28 28 * @return boolean
29 29 */
@@ -50,9 +50,9 @@
50 50 self::convert_v1_font_specs_to_v2();
51 51 $merge = self::build();
52 52 $config = wp_optimize_minify_config();
53 53 /**
54 - * Filters wether to add display=swap to Google fonts urls
54 + * Filters whether to add display=swap to Google fonts urls
55 55 *
56 56 * @param boolean $display - Default to true
57 57 */
58 58 if (apply_filters('wpo_minify_gfont_display_swap', $config->get('enable_display_swap'))) {
@@ -70,8 +70,10 @@
70 70 }
71 71
72 72 /**
73 73 * Parses font url based on whether it is API version 1 or 2
74 + *
75 + * @param string $font
74 76 */
75 77 private static function parse_font_url($font) {
76 78 if (false !== strpos($font, 'css?')) {
77 79 self::parse_font_api1_url($font);
@@ -81,11 +83,13 @@
81 83 }
82 84
83 85 /**
84 86 * Parses google font api version 1 url
87 + *
88 + * @param string $font
85 89 */
86 90 private static function parse_font_api1_url($font) {
87 - parse_str(parse_url(rtrim($font, '|'), PHP_URL_QUERY), $font_elements);
91 + parse_str(wp_parse_url(rtrim($font, '|'), PHP_URL_QUERY), $font_elements);
88 92 // Process each font family
89 93 foreach (explode('|', $font_elements['family']) as $font_family) {
90 94 // Separate font and sizes
91 95 $font_family = explode(':', $font_family);
@@ -94,9 +98,9 @@
94 98 self::$fonts[$font_family[0]]['specs'] = isset($font_family[1]) ? explode(',', rtrim($font_family[1], ',')) : array();
95 99 } else {
96 100 // if the family was already added, and this new one has weights, merge with previous
97 101 if (isset($font_family[1])) {
98 - if (isset(self::$fonts[$font_family[0]]['version']) && 'V2' == self::$fonts[$font_family[0]]['version']) {
102 + if (isset(self::$fonts[$font_family[0]]['version']) && 'V2' === self::$fonts[$font_family[0]]['version']) {
99 103 self::$fonts[$font_family[0]]['specs'] = explode(',', rtrim($font_family[1], ','));
100 104 } else {
101 105 self::$fonts[$font_family[0]]['specs'] = array_merge(self::$fonts[$font_family[0]]['specs'], explode(',', rtrim($font_family[1], ',')));
102 106 }
@@ -112,11 +116,13 @@
112 116 }
113 117
114 118 /**
115 119 * Parses google font api version 2 url
120 + *
121 + * @param string $font
116 122 */
117 123 private static function parse_font_api2_url($font) {
118 - $parsed_url = parse_url($font, PHP_URL_QUERY);
124 + $parsed_url = wp_parse_url($font, PHP_URL_QUERY);
119 125 $query_elements = explode('&', $parsed_url);
120 126 foreach ($query_elements as $element) {
121 127 $family_str = str_replace('family=', '', $element);
122 128 $family = explode(':', $family_str);
@@ -176,10 +182,10 @@
176 182 * Converts google font api version 1 font specification into API V2
177 183 */
178 184 private static function convert_v1_font_specs_to_v2() {
179 185 foreach (self::$fonts as $font_name => $font_details) {
180 - if ('V2' == $font_details['version']) continue;
181 - if (0 == count($font_details['specs'])) {
186 + if ('V2' === $font_details['version']) continue;
187 + if (0 === count($font_details['specs'])) {
182 188 self::$fonts[$font_name]['specs'] = array(
183 189 'wght' => array(),
184 190 'ital' => array(),
185 191 'ital,wght' => array(),
@@ -234,10 +240,10 @@
234 240 */
235 241 private static function build() {
236 242 $result = '';
237 243 foreach (self::$fonts as $font_name => $font_details) {
238 - if ('display=swap' == $font_name) continue;
239 - if ('' != $result) {
244 + if ('display=swap' === $font_name) continue;
245 + if ('' !== $result) {
240 246 $result .= '&';
241 247 }
242 248 $result .= 'family=' . str_replace(' ', '+', $font_name);
243 249 $result .= self::specs_to_string($font_details['specs']);
@@ -245,9 +251,9 @@
245 251 return $result;
246 252 }
247 253
248 254 /**
249 - * Converts font specifications into a valid google font api2 url string
255 + * Converts font specifications into a valid Google font api2 url string
250 256 *
251 257 * @param array $font_specs Font style and weight specifications
252 258 *
253 259 * @return string
@@ -264,11 +270,11 @@
264 270 }
265 271
266 272 // Italic only
267 273 if ($italic_weights && !$weights && !$all_weights) {
268 - if ('1' == $font_specs['ital'][0]) {
274 + if ('1' === $font_specs['ital'][0]) {
269 275 return ':ital@1';
270 - } elseif ('0;1' == $font_specs['ital'][0]) {
276 + } elseif ('0;1' === $font_specs['ital'][0]) {
271 277 return ':ital@0;1';
272 278 }
273 279 }
274 280
@@ -287,9 +293,9 @@
287 293 }
288 294 break;
289 295 case 'ital':
290 296 foreach ($units as $unit) {
291 - array_push($result, 1 == $unit ? '1,400' : $unit);
297 + array_push($result, 1 === (int) $unit ? '1,400' : $unit);
292 298 }
293 299 break;
294 300 case 'ital,wght':
295 301 foreach ($units as $unit) {