OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy. - Version 5.1.4

Version Description

| June 6th, 2022 = * Tested with WP 6.0 * Fixed: Font-weights weren't properly detected when stylesheets were loaded using Variable Fonts (CSS2) API. * Fixed: jQuery.fn.submit() shorthand is deprecated. * Fixed: Improved compatibility with servers using Nginx reverse proxy. * Fixed: Filter duplicate font-family requests in same Google Fonts request, e.g. fonts.googleapis.com/css?family=Roboto|Roboto. * Added: Workaround for Elementor to identify unique Google Fonts stylesheets, because Elementor always uses the (annoyingly generic) 'google-fonts-1' handle as an identifier. :-/ * Fixed: Generate a 'unique' identifier for each stylesheet without an identifier ('id' attribute) * Several minor performance improvements.

Download this release

Release Info

Developer DaanvandenBergh
Plugin Icon 128x128 OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy.
Version 5.1.4
Comparing to
See all releases

Code changes from version 5.1.3 to 5.1.4

assets/js/omgf-admin.js CHANGED
@@ -41,7 +41,7 @@ jQuery(document).ready(function ($) {
41
  $('#omgf-remove-stylesheet').on('click', this.remove_stylesheet_from_db);
42
  $('#omgf-cache-refresh').on('click', this.refresh_cache);
43
  $('.omgf-empty, #omgf-cache-flush').on('click', this.empty_cache_directory);
44
- $('#omgf-optimize-settings-form').submit(this.show_loader_before_submit);
45
 
46
  // Ticker
47
  setInterval(this.loop_ticker_items, 4000);
41
  $('#omgf-remove-stylesheet').on('click', this.remove_stylesheet_from_db);
42
  $('#omgf-cache-refresh').on('click', this.refresh_cache);
43
  $('.omgf-empty, #omgf-cache-flush').on('click', this.empty_cache_directory);
44
+ $('#omgf-optimize-settings-form').on('submit', this.show_loader_before_submit);
45
 
46
  // Ticker
47
  setInterval(this.loop_ticker_items, 4000);
host-webfonts-local.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: OMGF
5
  * Plugin URI: https://ffw.press/wordpress/omgf/
6
  * Description: Increase GDPR compliance, reduce DNS requests and leverage browser cache by automatically downloading Google Fonts to your server.
7
- * Version: 5.1.3
8
  * Author: Daan from FFW.Press
9
  * Author URI: https://ffw.press
10
  * License: GPL2v2 or later
@@ -19,7 +19,7 @@ defined('ABSPATH') || exit;
19
  define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
20
  define('OMGF_PLUGIN_FILE', __FILE__);
21
  define('OMGF_PLUGIN_BASENAME', plugin_basename(OMGF_PLUGIN_FILE));
22
- define('OMGF_STATIC_VERSION', '5.1.1');
23
  define('OMGF_DB_VERSION', '5.0.0');
24
 
25
  /**
4
  * Plugin Name: OMGF
5
  * Plugin URI: https://ffw.press/wordpress/omgf/
6
  * Description: Increase GDPR compliance, reduce DNS requests and leverage browser cache by automatically downloading Google Fonts to your server.
7
+ * Version: 5.1.4
8
  * Author: Daan from FFW.Press
9
  * Author URI: https://ffw.press
10
  * License: GPL2v2 or later
19
  define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
20
  define('OMGF_PLUGIN_FILE', __FILE__);
21
  define('OMGF_PLUGIN_BASENAME', plugin_basename(OMGF_PLUGIN_FILE));
22
+ define('OMGF_STATIC_VERSION', '5.1.4');
23
  define('OMGF_DB_VERSION', '5.0.0');
24
 
25
  /**
includes/class-optimize.php CHANGED
@@ -109,12 +109,28 @@ class OMGF_Optimize
109
  $query['subsets'] = $this->subset;
110
  }
111
 
112
- foreach ($font_families as $font_family) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  if (empty($font_family)) {
114
  continue;
115
  }
116
 
117
- $fonts[] = $this->grab_font_family($font_family, $query);
 
 
118
  }
119
 
120
  // Filter out empty elements, i.e. failed requests.
@@ -124,15 +140,15 @@ class OMGF_Optimize
124
  return '';
125
  }
126
 
127
- foreach ($fonts as &$font) {
128
- $fonts_request = $this->build_fonts_request($font_families, $font);
129
 
130
- if (strpos($fonts_request, ':') != false) {
131
- list($family, $requested_variants) = explode(':', $fonts_request);
132
- } else {
133
- $family = $fonts_request;
134
- $requested_variants = '';
135
- }
136
 
137
  $requested_variants = $this->parse_requested_variants($requested_variants, $font);
138
 
@@ -142,11 +158,10 @@ class OMGF_Optimize
142
  // Now we're sure we got 'em all. We can safely dequeue those we don't want.
143
  if (isset($unloaded_fonts[$this->original_handle][$font_id])) {
144
  $requested_variants = $this->dequeue_unloaded_variants($requested_variants, $unloaded_fonts[$this->original_handle], $font->id);
145
- $fonts_request = $family . ':' . implode(',', $requested_variants);
146
  }
147
  }
148
 
149
- $font->variants = $this->process_unload_queue($font->id, $font->variants, $fonts_request, $this->original_handle);
150
  }
151
 
152
  /**
@@ -234,40 +249,31 @@ class OMGF_Optimize
234
  {
235
  return array_filter(
236
  $variants,
237
- function ($value) use ($unloaded_fonts, $font_id) {
238
- if ($value == '400') {
239
  // Sometimes the font is defined as 'regular', so we need to check both.
240
- return !in_array('regular', $unloaded_fonts[$font_id]) && !in_array($value, $unloaded_fonts[$font_id]);
241
  }
242
 
243
- if ($value == '400italic') {
244
  // Sometimes the font is defined as 'italic', so we need to check both.
245
- return !in_array('italic', $unloaded_fonts[$font_id]) && !in_array($value, $unloaded_fonts[$font_id]);
246
  }
247
 
248
- return !in_array($value, $unloaded_fonts[$font_id]);
249
  }
250
  );
251
  }
252
 
253
  /**
254
- * @param $font_family
255
- * @param $url
256
  * @param $query
 
257
  *
258
  * @return mixed|void
259
  */
260
- private function grab_font_family($font_family, $query)
261
  {
262
- list($family) = explode(':', $font_family);
263
-
264
- /**
265
- * Replace multiple spaces or plus signs (or a combination of, with a single dash)
266
- *
267
- * @since v4.5.10
268
- */
269
- $family = strtolower(preg_replace("/[\s\+]+/", '-', $family));
270
-
271
  /**
272
  * Add fonts to the request's $_GET 'family' parameter. Then pass an array to 'omgf_alternate_fonts'
273
  * filter. Then pass an alternate API url to the 'omgf_alternate_api_url' filter to fetch fonts from
@@ -277,8 +283,8 @@ class OMGF_Optimize
277
  $alternate_url = '';
278
  $query_string = '';
279
 
280
- if (in_array($family, array_keys($alternate_fonts))) {
281
- $alternate_url = apply_filters('omgf_alternate_api_url', '', $family);
282
  unset($query);
283
  }
284
 
@@ -289,15 +295,15 @@ class OMGF_Optimize
289
  /**
290
  * If a font changed names recently, map their old name to the new name, before triggering the API request.
291
  */
292
- if (in_array($family, array_keys(self::OMGF_RENAMED_GOOGLE_FONTS))) {
293
- $family = self::OMGF_RENAMED_GOOGLE_FONTS[$family];
294
  }
295
 
296
  if (!$alternate_url) {
297
- $response = $this->remote_get($family, $query_string);
298
  } else {
299
  $response = wp_remote_get(
300
- sprintf($alternate_url . '%s', $family) . $query_string
301
  );
302
  }
303
 
@@ -312,16 +318,15 @@ class OMGF_Optimize
312
  $response_body = wp_remote_retrieve_body($response);
313
  $body = json_decode($response_body);
314
  $query_string = '?subsets=' . (isset($body->subsets) ? implode(',', $body->subsets) : 'latin,latin-ext');
315
- $response = $this->remote_get($family, $query_string);
316
  }
317
 
318
  $response_code = wp_remote_retrieve_response_code($response);
319
 
320
  if ($response_code != 200) {
321
- $font_family = str_replace('-', ' ', $family);
322
  $error_body = wp_remote_retrieve_body($response);
323
  $error_message = wp_remote_retrieve_response_message($response);
324
- $message = sprintf(__('OMGF couldn\'t find <strong>%s</strong> while parsing %s. The API returned the following error: %s.', $this->plugin_text_domain), ucwords($font_family), isset($_GET['omgf_optimize']) ? 'your homepage' : $_SERVER['REQUEST_URI'], is_wp_error($response) ? $response->get_error_message() : $error_message);
325
 
326
  OMGF_Admin_Notice::set_notice($message, 'omgf_api_error', 'error');
327
 
@@ -332,13 +337,13 @@ class OMGF_Optimize
332
  }
333
 
334
  if ($error_body == 'Not found') {
335
- $message = sprintf(__('Please verify that %s is available for free at Google Fonts by doing <a href="%s" target="_blank">a manual search</a>. Maybe it\'s a Premium font?', $this->plugin_text_domain), ucwords($font_family), 'https://fonts.google.com/?query=' . str_replace('-', '+', $family));
336
 
337
  OMGF_Admin_Notice::set_notice($message, 'omgf_api_info_not_found', 'info');
338
  }
339
 
340
  if ($error_body == 'Internal Server Error') {
341
- $message = sprintf(__('Try using the Force Subsets option (available in OMGF Pro) to force loading %s in a subset in which it\'s actually available. Use the Language filter <a href="%s" target="_blank">here</a> to verify which subsets are available for %s.', $this->plugin_text_domain), ucwords($font_family), 'https://fonts.google.com/?query=' . str_replace('-', '+', $family), ucwords($font_family));
342
 
343
  OMGF_Admin_Notice::set_notice($message, 'omgf_api_info_internal_server_error', 'info');
344
  }
@@ -373,28 +378,6 @@ class OMGF_Optimize
373
  return $response;
374
  }
375
 
376
- /**
377
- * @param $font_families
378
- * @param $font
379
- *
380
- * @return mixed
381
- */
382
- private function build_fonts_request($font_families, $font)
383
- {
384
- $font_request = array_filter(
385
- $font_families,
386
- function ($value) use ($font) {
387
- if (isset($font->early_access)) {
388
- return strpos($value, strtolower(str_replace(' ', '', $font->family))) !== false;
389
- }
390
-
391
- return strpos($value, $font->family) !== false;
392
- }
393
- );
394
-
395
- return reset($font_request);
396
- }
397
-
398
  /**
399
  * @param $request
400
  * @param $font
@@ -403,6 +386,9 @@ class OMGF_Optimize
403
  */
404
  private function parse_requested_variants($request, $font)
405
  {
 
 
 
406
  $requested_variants = array_filter(explode(',', $request));
407
 
408
  /**
@@ -419,48 +405,36 @@ class OMGF_Optimize
419
 
420
  /**
421
  *
422
- * @param mixed $font_id
423
- * @param mixed $available
424
- * @param mixed $wanted
425
- * @param mixed $stylesheet_handle
426
  * @return mixed
427
  */
428
- private function process_unload_queue($font_id, $available, $wanted, $stylesheet_handle)
429
  {
430
- if (strpos($wanted, ':') !== false) {
431
- // We don't need the first variable.
432
- list(, $variants) = explode(':', $wanted);
433
- } else {
434
- $variants = '';
435
- }
436
-
437
- /**
438
- * Build array and filter out empty elements.
439
- */
440
- $variants = array_filter(explode(',', $variants));
441
-
442
  /**
443
  * If $variants is empty and this is the first run, i.e. there are no unloaded fonts (yet)
444
  * return all available variants.
445
  */
446
- if (empty($variants) && !isset(OMGF::unloaded_fonts()[$stylesheet_handle][$font_id])) {
447
- return $available;
448
  }
449
 
450
  return array_filter(
451
- $available,
452
- function ($font) use ($variants) {
453
  $id = $font->id;
454
 
455
  if ($id == 'regular' || $id == '400') {
456
- return in_array('400', $variants) || in_array('regular', $variants);
457
  }
458
 
459
  if ($id == 'italic') {
460
- return in_array('400italic', $variants) || in_array('italic', $variants);
461
  }
462
 
463
- return in_array($id, $variants);
464
  }
465
  );
466
  }
109
  $query['subsets'] = $this->subset;
110
  }
111
 
112
+ foreach ($font_families as $key => $font_family) {
113
+ /**
114
+ * Prevent duplicate entries by generating a unique identifier, all lowercase,
115
+ * with (multiple) spaces replaced by dashes.
116
+ *
117
+ * @since v5.1.4
118
+ */
119
+ $font_name = explode(':', $font_family)[0];
120
+ $font_id = strtolower(preg_replace("/[\s\+]+/", '-', $font_name));
121
+
122
+ $font_families[$font_id] = $font_family;
123
+ unset($font_families[$key]);
124
+ }
125
+
126
+ foreach ($font_families as $font_id => $font_family) {
127
  if (empty($font_family)) {
128
  continue;
129
  }
130
 
131
+ if (!isset($fonts[$font_id])) {
132
+ $fonts[$font_id] = $this->grab_font_object($font_id, $query, $font_name);
133
+ }
134
  }
135
 
136
  // Filter out empty elements, i.e. failed requests.
140
  return '';
141
  }
142
 
143
+ foreach ($fonts as $id => &$font) {
144
+ $fonts_request = $font_families[$id];
145
 
146
+ /**
147
+ * If no colon is found, @var string $requested_variants will be an empty string.
148
+ *
149
+ * @since v5.1.4
150
+ */
151
+ list(, $requested_variants) = array_pad(explode(':', $fonts_request), 2, '');
152
 
153
  $requested_variants = $this->parse_requested_variants($requested_variants, $font);
154
 
158
  // Now we're sure we got 'em all. We can safely dequeue those we don't want.
159
  if (isset($unloaded_fonts[$this->original_handle][$font_id])) {
160
  $requested_variants = $this->dequeue_unloaded_variants($requested_variants, $unloaded_fonts[$this->original_handle], $font->id);
 
161
  }
162
  }
163
 
164
+ $font->variants = $this->process_unload_queue($font->id, $font->variants, $requested_variants, $this->original_handle);
165
  }
166
 
167
  /**
249
  {
250
  return array_filter(
251
  $variants,
252
+ function ($variant) use ($unloaded_fonts, $font_id) {
253
+ if ($variant == '400') {
254
  // Sometimes the font is defined as 'regular', so we need to check both.
255
+ return !in_array('regular', $unloaded_fonts[$font_id]) && !in_array($variant, $unloaded_fonts[$font_id]);
256
  }
257
 
258
+ if ($variant == '400italic') {
259
  // Sometimes the font is defined as 'italic', so we need to check both.
260
+ return !in_array('italic', $unloaded_fonts[$font_id]) && !in_array($variant, $unloaded_fonts[$font_id]);
261
  }
262
 
263
+ return !in_array($variant, $unloaded_fonts[$font_id]);
264
  }
265
  );
266
  }
267
 
268
  /**
269
+ * @param $id Unique identifier for this Font Family, lowercase, dashes instead of spaces.
 
270
  * @param $query
271
+ * @param $name The full name of the requested Font Family, e.g. Roboto Condensed, Open Sans or Roboto.
272
  *
273
  * @return mixed|void
274
  */
275
+ private function grab_font_object($id, $query, $name)
276
  {
 
 
 
 
 
 
 
 
 
277
  /**
278
  * Add fonts to the request's $_GET 'family' parameter. Then pass an array to 'omgf_alternate_fonts'
279
  * filter. Then pass an alternate API url to the 'omgf_alternate_api_url' filter to fetch fonts from
283
  $alternate_url = '';
284
  $query_string = '';
285
 
286
+ if (in_array($id, array_keys($alternate_fonts))) {
287
+ $alternate_url = apply_filters('omgf_alternate_api_url', '', $id);
288
  unset($query);
289
  }
290
 
295
  /**
296
  * If a font changed names recently, map their old name to the new name, before triggering the API request.
297
  */
298
+ if (in_array($id, array_keys(self::OMGF_RENAMED_GOOGLE_FONTS))) {
299
+ $id = self::OMGF_RENAMED_GOOGLE_FONTS[$id];
300
  }
301
 
302
  if (!$alternate_url) {
303
+ $response = $this->remote_get($id, $query_string);
304
  } else {
305
  $response = wp_remote_get(
306
+ sprintf($alternate_url . '%s', $id) . $query_string
307
  );
308
  }
309
 
318
  $response_body = wp_remote_retrieve_body($response);
319
  $body = json_decode($response_body);
320
  $query_string = '?subsets=' . (isset($body->subsets) ? implode(',', $body->subsets) : 'latin,latin-ext');
321
+ $response = $this->remote_get($id, $query_string);
322
  }
323
 
324
  $response_code = wp_remote_retrieve_response_code($response);
325
 
326
  if ($response_code != 200) {
 
327
  $error_body = wp_remote_retrieve_body($response);
328
  $error_message = wp_remote_retrieve_response_message($response);
329
+ $message = sprintf(__('OMGF couldn\'t find <strong>%s</strong> while parsing %s. The API returned the following error: %s.', $this->plugin_text_domain), $name, isset($_GET['omgf_optimize']) ? 'your homepage' : $_SERVER['REQUEST_URI'], is_wp_error($response) ? $response->get_error_message() : $error_message);
330
 
331
  OMGF_Admin_Notice::set_notice($message, 'omgf_api_error', 'error');
332
 
337
  }
338
 
339
  if ($error_body == 'Not found') {
340
+ $message = sprintf(__('Please verify that %s is available for free at Google Fonts by doing <a href="%s" target="_blank">a manual search</a>. Maybe it\'s a Premium font?', $this->plugin_text_domain), $name, 'https://fonts.google.com/?query=' . str_replace('-', '+', $id));
341
 
342
  OMGF_Admin_Notice::set_notice($message, 'omgf_api_info_not_found', 'info');
343
  }
344
 
345
  if ($error_body == 'Internal Server Error') {
346
+ $message = sprintf(__('Try using the Force Subsets option (available in OMGF Pro) to force loading %s in a subset in which it\'s actually available. Use the Language filter <a href="%s" target="_blank">here</a> to verify which subsets are available for %s.', $this->plugin_text_domain), $name, 'https://fonts.google.com/?query=' . str_replace('-', '+', $id), $name);
347
 
348
  OMGF_Admin_Notice::set_notice($message, 'omgf_api_info_internal_server_error', 'info');
349
  }
378
  return $response;
379
  }
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  /**
382
  * @param $request
383
  * @param $font
386
  */
387
  private function parse_requested_variants($request, $font)
388
  {
389
+ /**
390
+ * Build an array and filter out empty elements.
391
+ */
392
  $requested_variants = array_filter(explode(',', $request));
393
 
394
  /**
405
 
406
  /**
407
  *
408
+ * @param string $font_id
409
+ * @param array $all_variants An array of all available font family variants.
410
+ * @param array $wanted_variants An array of requested variants in this font family request.
411
+ * @param string $stylesheet_handle
412
  * @return mixed
413
  */
414
+ private function process_unload_queue($font_id, $all_variants, $wanted_variants, $stylesheet_handle)
415
  {
 
 
 
 
 
 
 
 
 
 
 
 
416
  /**
417
  * If $variants is empty and this is the first run, i.e. there are no unloaded fonts (yet)
418
  * return all available variants.
419
  */
420
+ if (empty($wanted_variants) && !isset(OMGF::unloaded_fonts()[$stylesheet_handle][$font_id])) {
421
+ return $all_variants;
422
  }
423
 
424
  return array_filter(
425
+ $all_variants,
426
+ function ($font) use ($wanted_variants) {
427
  $id = $font->id;
428
 
429
  if ($id == 'regular' || $id == '400') {
430
+ return in_array('400', $wanted_variants) || in_array('regular', $wanted_variants);
431
  }
432
 
433
  if ($id == 'italic') {
434
+ return in_array('400italic', $wanted_variants) || in_array('italic', $wanted_variants);
435
  }
436
 
437
+ return in_array($id, $wanted_variants);
438
  }
439
  );
440
  }
includes/frontend/class-process.php CHANGED
@@ -323,14 +323,31 @@ class OMGF_Frontend_Process
323
  foreach ($links as $key => $link) {
324
  preg_match('/id=[\'"](?P<id>.*?)[\'"]/', $link, $id);
325
 
326
- $id = $this->strip_css_tag($id['id'] ?? "$handle-$key");
 
 
 
327
 
328
  preg_match('/href=[\'"](?P<href>.*?)[\'"]/', $link, $href);
329
 
 
 
 
330
  if (!isset($href['href'])) {
331
  continue;
332
  }
333
 
 
 
 
 
 
 
 
 
 
 
 
334
  /**
335
  * Compatibility fix for Divi Builder
336
  *
@@ -341,9 +358,20 @@ class OMGF_Frontend_Process
341
  */
342
  if (strpos($id, 'et-builder-googlefonts') !== false) {
343
  $google_fonts[$key]['id'] = $id . '-' . strlen($href['href']);
 
 
 
 
 
 
 
 
 
 
344
  } else {
345
  $google_fonts[$key]['id'] = $id;
346
  }
 
347
  $google_fonts[$key]['href'] = $href['href'];
348
  }
349
 
@@ -547,9 +575,9 @@ class OMGF_Frontend_Process
547
  }
548
 
549
  /**
550
- * @var array|string $weights [ '300', '400', '500', etc. ] | ''
551
  */
552
- $weights = strpos($weights, ';') !== false ? explode(';', substr($weights, strpos($weights, '@') + 1)) : '';
553
 
554
  if (!$weights) {
555
  $fonts[] = $family;
@@ -557,6 +585,9 @@ class OMGF_Frontend_Process
557
  continue;
558
  }
559
 
 
 
 
560
  foreach ($weights as &$weight) {
561
  $properties = explode(',', $weight);
562
  $weight = $properties[0] == '1' && isset($properties[1]) ? $properties[1] . 'italic' : ($properties[0] != '0' ? $properties[0] : $properties[1]);
323
  foreach ($links as $key => $link) {
324
  preg_match('/id=[\'"](?P<id>.*?)[\'"]/', $link, $id);
325
 
326
+ /**
327
+ * @var string $id Fallback to empty string if no id attribute exists.
328
+ */
329
+ $id = $this->strip_css_tag($id['id'] ?? '');
330
 
331
  preg_match('/href=[\'"](?P<href>.*?)[\'"]/', $link, $href);
332
 
333
+ /**
334
+ * No valid href attribute provide in link element.
335
+ */
336
  if (!isset($href['href'])) {
337
  continue;
338
  }
339
 
340
+ /**
341
+ * If no valid id attribute was found then this means that this stylesheet wasn't enqueued
342
+ * using proper WordPress conventions. We generate our own using the length of the href attribute
343
+ * to serve as a UID. This prevents clashes with other non-properly enqueued stylesheets on other pages.
344
+ *
345
+ * @since v5.1.4
346
+ */
347
+ if (!$id) {
348
+ $id = "$handle-" . strlen($href['href']);
349
+ }
350
+
351
  /**
352
  * Compatibility fix for Divi Builder
353
  *
358
  */
359
  if (strpos($id, 'et-builder-googlefonts') !== false) {
360
  $google_fonts[$key]['id'] = $id . '-' . strlen($href['href']);
361
+ } elseif ($id === 'google-fonts-1') {
362
+ /**
363
+ * Compatibility fix for Elementor
364
+ *
365
+ * @since v5.1.4 Because Elementor uses the same (annoyingly generic) handle for Google Fonts
366
+ * stylesheets on each page, even when these contain different Google Fonts than
367
+ * other pages, let's append a (kind of) unique identifier to the string, to make
368
+ * sure we can make a difference between different Google Fonts configurations.
369
+ */
370
+ $google_fonts[$key]['id'] = str_replace('-1', '-' . strlen($href['href']), $id);
371
  } else {
372
  $google_fonts[$key]['id'] = $id;
373
  }
374
+
375
  $google_fonts[$key]['href'] = $href['href'];
376
  }
377
 
575
  }
576
 
577
  /**
578
+ * @var string $weights [ '300', '400', '500', etc. ] || ''
579
  */
580
+ $weights = strpos($weights, ';') !== false ? explode(';', substr($weights, strpos($weights, '@') + 1)) : [substr($weights, strpos($weights, '@') + 1)];
581
 
582
  if (!$weights) {
583
  $fonts[] = $family;
585
  continue;
586
  }
587
 
588
+ /**
589
+ * @var array $weights Multiple weights, e.g. [ '300', '400', '500', '0,600', '1,700' ] || Single weight, e.g. [ '500' ] or [ '1,600' ]
590
+ */
591
  foreach ($weights as &$weight) {
592
  $properties = explode(',', $weight);
593
  $weight = $properties[0] == '1' && isset($properties[1]) ? $properties[1] . 'italic' : ($properties[0] != '0' ? $properties[0] : $properties[1]);
includes/optimize/class-run.php CHANGED
@@ -38,7 +38,7 @@ class OMGF_Optimize_Run
38
  */
39
  private function run()
40
  {
41
- $front_html = $this->get_front_html(home_url());
42
  $error = false;
43
 
44
  if (is_wp_error($front_html) || wp_remote_retrieve_response_code($front_html) != 200) {
@@ -103,6 +103,11 @@ class OMGF_Optimize_Run
103
  */
104
  private function frontend_fetch_failed($response)
105
  {
 
 
 
 
 
106
  add_settings_error('general', 'omgf_frontend_fetch_failed', __('OMGF encountered an error while fetching this site\'s frontend HTML', $this->plugin_text_domain) . ': ' . $this->get_error_code($response) . ' - ' . $this->get_error_message($response), 'error');
107
  }
108
 
@@ -113,11 +118,6 @@ class OMGF_Optimize_Run
113
  */
114
  private function get_error_code($response)
115
  {
116
- if ($response instanceof WP_REST_Response && $response->is_error()) {
117
- // Convert to WP_Error if WP_REST_Response
118
- $response = $response->as_error();
119
- }
120
-
121
  if (is_wp_error($response)) {
122
  return $response->get_error_code();
123
  }
@@ -132,11 +132,6 @@ class OMGF_Optimize_Run
132
  */
133
  private function get_error_message($response)
134
  {
135
- if ($response instanceof WP_REST_Response && $response->is_error()) {
136
- // Convert to WP_Error if WP_REST_Response
137
- $response = $response->as_error();
138
- }
139
-
140
  if (is_wp_error($response)) {
141
  return $response->get_error_message();
142
  }
38
  */
39
  private function run()
40
  {
41
+ $front_html = $this->get_front_html(get_home_url());
42
  $error = false;
43
 
44
  if (is_wp_error($front_html) || wp_remote_retrieve_response_code($front_html) != 200) {
103
  */
104
  private function frontend_fetch_failed($response)
105
  {
106
+ if ($response instanceof WP_REST_Response && $response->is_error()) {
107
+ // Convert to WP_Error if WP_REST_Response
108
+ $response = $response->as_error();
109
+ }
110
+
111
  add_settings_error('general', 'omgf_frontend_fetch_failed', __('OMGF encountered an error while fetching this site\'s frontend HTML', $this->plugin_text_domain) . ': ' . $this->get_error_code($response) . ' - ' . $this->get_error_message($response), 'error');
112
  }
113
 
118
  */
119
  private function get_error_code($response)
120
  {
 
 
 
 
 
121
  if (is_wp_error($response)) {
122
  return $response->get_error_code();
123
  }
132
  */
133
  private function get_error_message($response)
134
  {
 
 
 
 
 
135
  if (is_wp_error($response)) {
136
  return $response->get_error_message();
137
  }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: DaanvandenBergh
3
  Tags: google, fonts, gdpr, cache, speed, preload, font-display, webfonts, subsets, remove, minimize, external, requests
4
  Requires at least: 4.6
5
- Tested up to: 5.9
6
- Stable tag: 5.1.3
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -75,6 +75,16 @@ For the FAQ, [click here](https://ffw.press/docs/omgf-pro-faq/).
75
 
76
  == Changelog ==
77
 
 
 
 
 
 
 
 
 
 
 
78
  = 5.1.3 =
79
  * Added: workaround for Divi builder to identify unique Google Fonts stylesheets.
80
  * Added: extra links to documentation in Manage Optimized Fonts section.
@@ -144,243 +154,7 @@ For the FAQ, [click here](https://ffw.press/docs/omgf-pro-faq/).
144
  * Fixed: Smart Slider 3 compatibility.
145
  * Several bugfixes, UX improvements and code optimizations.
146
 
147
- = 4.6.0 | February 16th, 2022 =
148
- * Fixed: Loading spinner wasn't center aligned.
149
- * Added: Force Optimization Mode Task Manager.
150
- - Offers an easy overview of downloaded stylesheets and where they're stored,
151
- - Indicates stale cache files.
152
- * Added: Clearer explanation of when to use Scan Posts/Pages VS Force Optimization Mode.
153
- * Fixed: Cache handles weren't removed when cache directory was emptied.
154
- * Fixed: Tooltip in Manage Optimized Fonts section wasn't aligned properly.
155
- * Renamed: Manual Optimization Mode to Force and Automatic to Scan Posts/Pages.
156
-
157
- = 4.5.19 | February 5th, 2022 =
158
- * Fixed: Use of undefined constant in OMGF_Admin_Settings_Help class.
159
-
160
- = 4.5.18 =
161
- * Fixed: use of undefined constant 'OMGF_DEBUG_MODE'.
162
-
163
- = 4.5.17 | February 4th, 2022 =
164
- * Hotfix: array to string conversion on line 252 in class OMGF_Frontend_Functions.
165
-
166
- = 4.5.16 | February 2nd, 2022 =
167
- * Fixed: WP 5.9 welcome banner removed from Help section.
168
- * Added: Basic debugging throughout the plugin (can be enable by setting the OMGF_DEBUG_MODE constant to true);
169
- * Fixed: Updated handle was overwritten by empty value if cache key wasn't defined.
170
- * Added: More user friendly error messages.
171
- * Fixed: "Handle not provided" error should not kill the entire Download API process (post OMGF v4)
172
- * Pro Feature: Fallback Font Stacks can now Replace an entire Google Fonts font-family.
173
-
174
- = 4.5.15 | January 26th, 2022 =
175
- * Tested with WP 5.9
176
- - Fixed: WP 5.9 welcome banner displayed in Optimized Fonts Manager section.
177
-
178
- = 4.5.14 | January 18th, 2022 =
179
- * Fixed: Pro options Google Fonts Source URL and AMP handling couldn't be saved.
180
-
181
- = 4.5.13 | January 4th, 2022 =
182
- * Secured: Properly check permissions when Download API is accessed.
183
-
184
- = 4.5.12 | November 27th, 2021 =
185
- * Secured: Prevent path traversal when cache directory setting is changed. (Thanks, @jsgm!)
186
-
187
- = 4.5.11 | November 17th, 2021 =
188
- * Documented: Updated links to fancy new documentation hub: docs.ffw.press
189
- * Dev: Added $font_family to omgf_alternate_api_url filter.
190
- * Dev: Added filter to detect_registered_stylesheets().
191
- * Fixed: disable preload/unload when opposite checkbox is checked.
192
- * Fixed: Updated RSS feed URL and properly encode retrieved XML to prevent parse error simplexml_load_string().
193
- * Promo: Added force font-display promo material.
194
-
195
- = 4.5.10 | October 18th, 2021 =
196
- * Enhanced: API now cleans up excessive spacing and + symbols in requests before fetching fonts. This comes in handy when e.g. @import statements in CSS stylesheets are auto-formatted by IDEs.
197
- * Fixed: API would crash when Google Fonts request turned up empty.
198
- * Fixed: Added proper error handling for when downloading fonts failed.
199
- * Documented: Added link to Troubleshooting Guide to Help tab.
200
-
201
- = 4.5.9 | October 5th, 2021 =
202
- * Fixed: content_url() should always be encoded, also if file already exists.
203
- * Enhanced: If stylesheet is already generated, stop execution to decrease API request time.
204
-
205
- = 4.5.8 =
206
- * Fixed: use array_merge() to prevent unsupported operand types error.
207
-
208
- = 4.5.7 | September 29th, 2021 =
209
- * Enhanced: significantly reduced code running frontend.
210
- * Fixed: internal requests to OMGF's Download API are no longer treated as 'remote'.
211
- * Fixed: stylesheets are no longer skipped in some situations by the temp storage layer, before writing them to the database.
212
- * Fixed: using the mass actions (e.g. unload all, unload italics) no longer affect font families with the same name in a stylesheet with a different handle.
213
- * Fixed: Italic fonts are now properly detected by the API when CSS2 (variable fonts) API is used by themes and/or plugins.
214
- * Fixed: Added my own self-managed fallback API mirror to prevent more Google Fonts API downtime.
215
- * Enhanced: reduced code in Download API by ~20%.
216
- * Dev: add-ons for OMGF can now use the show_loader() method.
217
- * Several UX and performance tweaks.
218
-
219
- = 4.5.6 =
220
- * Fixed: Added Fallback API URL for when Google Fonts Helper is down.
221
- * Enhanced: Added extra error handling in Force Optimization Mode.
222
- * Fixed: API requests made in Force Optimization Mode are no longer forced to SSL. It now uses the protocol configured in Settings > General > WordPress URL.
223
- * Fixed: Stylesheet handles containing spaces would prevent Optimize Google Fonts screen from rendering properly.
224
- * Several refactors and code optimizations.
225
-
226
- = 4.5.5 =
227
- * Fixed: Prevent collision with other plugins when authenticating AJAX-calls.
228
-
229
- = 4.5.4 | August 18th, 2021 =
230
- * Security: Access to the Download API now requires a valid nonce to prevent CSRF.
231
- * Security: Added authentication to Empty Cache Directory AJAX-call.
232
-
233
- = 4.5.3 | August 17th, 2021 =
234
- * Fixed: "Too few arguments to function OmgfPro_Frontend_AutoReplace::passthru_handle()" would occur if OMGF Pro was updated to v2.5.1 before OMGF was updated to v4.5.2.
235
- * Security: Added checks to prevent path traversal and CSRF in Empty Cache Directory AJAX call.
236
-
237
- = 4.5.2 | August 16th, 2021 =
238
- * Pro Feature: Added promo material for @font-face detection in local stylesheets.
239
- * Fixed: Fixed several warnings and notices.
240
-
241
- = 4.5.1 | August 2nd, 2021 =
242
- * Enhanced: Added post update notice to inform user of the plugin's database changes. The current notice you were viewed was simply, because the current DB version wasn't logged yet on your system. So if you're reading this: Ha! Made you look! ;)
243
- * Pro Feature: Added promo material for Fallback Font Stack (Pro) feature.
244
- * Enhanced: moved Stylesheet Generator to its own backend API.
245
- * Enhanced: moved Font Downloader to its own backend API.
246
- * Enhanced: Updated description of Optimization Modes.
247
- * Fixed: Fixed glitch in footer news ticker.
248
- * Enhanced: Added several filter and action hooks to allow a more seamless integration with OMGF Pro and OMGF Additional Fonts.
249
- * Several code and performance optimizations.
250
-
251
- = 4.5.0 | July 28th, 2021 =
252
- * [Removed] WOFF2 only option is superseded by Include File Types option, only available in OMGF Pro.
253
- * [Removed] CDN URL, Cache URI and Relative URL options are combined into Fonts Source URL option, only available in OMGF Pro.
254
- * [Removed] Optimization Mode > Automatic is only available in OMGF Pro.
255
- * Tested with WordPress 5.8
256
- * Several code optimizations.
257
-
258
- = 4.4.4 =
259
- * Fixed logo for Safari compatibility.
260
- * Added updater notices for future important updates.
261
-
262
- = 4.4.3 =
263
- * Fixed a few warnings/notices.
264
- * Re-worded some options and option descriptions.
265
-
266
- = 4.4.2 =
267
- * Upped static version of Admin CSS files.
268
-
269
- = 4.4.1 | April 23rd, 2021 =
270
- * Fixed footer logo (load from local source instead of external URL).
271
- * Added tooltip for preload option.
272
- * Added link to OMGF Additional Fonts under Optimize tab.
273
-
274
- = 4.4.0 | April 10th, 2021 =
275
- * Moved sidebar to its own 'Help' tab to clean up the interface.
276
- * Manage Optimize Fonts panel is now shown inline with other options (and has its own label).
277
- * Each stylesheet's handle is now more prominently visible and the font family is more readable.
278
- * Added mass actions to each font family for easier management of each stylesheet.
279
- * Took a different approach to deal with SSL/Non-SSL for local Dev environments.
280
- * Performance improvements to manual detection mode (decreased risk of timeouts!)
281
- * Overall UX tweaks and performance improvements.
282
-
283
- = 4.3.2 | April 5th, 2021 =
284
- * Fixed MIME type (`X-Content-Type-Options: nosniff`) related errors when using Download API.
285
- * When site is not using SSL, sslverify is disabled when contacting the Download API.
286
- * When OMGF Pro is running in Automatic Mode, only preloads for the currently used stylesheet are loaded.
287
-
288
- = 4.3.1 | March 29th, 2021 =
289
- * Added Mukta (FKA Ek Mukta) to list of renamed Google Fonts.
290
-
291
- = 4.3.0 | March 17th, 2021 =
292
- * [FEAT] Renamed fonts will now be captured using their new name (e.g. Mulish), but remain in the stylesheet with their old name (e.g. Muli) to prevent manual changes to the stylesheet after optimization.
293
- * [FEAT] Added Load WOFF2 Only option.
294
- * Small code optimizations in Download API's code.
295
-
296
- = 4.2.8 | March 12th, 2021 =
297
- * [FIX] Strings with a + instead of a space would returned errors in the API.
298
-
299
- = 4.2.7 | March 10th, 2021 =
300
- * Addding ?nomgf=1 to any URL will now temporarily bypass fonts optimization, which allows for easier debugging.
301
-
302
- = 4.2.6 | March 6th, 2021 =
303
- * Tested with WP 5.7
304
- * [FIX] All fonts would be loaded, when all fonts of one font-family were checked for unloading.
305
- * [FIX] Fixed some notices and warnings.
306
- * Added compatibility for OMGF Pro's Early Access compatibility.
307
- * OMGF's admin JS is now only loaded on OMGF's settings screens.
308
- * [FIX] Fixed bug where Italic 400 fonts couldn't be unloaded.
309
-
310
- = 4.2.5 | January 27th, 2021 =
311
- * Improved compatibility with WordPress subdirectory installs.
312
- * Implemented some actions/filters needed for upcoming release of OMGF Additional Fonts.
313
- * Fixed duplicate preload ID's issue.
314
- * Fixed some notices/warnings.
315
- * Minor UX improvements.
316
-
317
- = 4.2.4 | December 8th, 2020 =
318
- * Cache keys are now fixed values instead of dynamically generated. This fixes the bug where preloads wouldn't load properly when combined with unloaded fonts of the same stylesheet.
319
- * **IMPORTANT**: To fix any bugs with preloads/unloads, emptying the cache directory is required.
320
- * Cleaned up the sidebar and added a notification to reassure people that no features were moved from Free to Pro after upgrading to v4.
321
- * Advanced Processing can now be disabled even when OMGF Pro is active. Before it was always on (accidentally).
322
- * When preload is enabled for a font style, its associated unload checkbox is disabled and vice versa.
323
- * Minor fixes, increased usability and optimizations.
324
-
325
- = 4.2.3 =
326
- * Fixed invalid preload header,
327
- * Fixed warning: `array_keys() expects parameter 1 to be array, null given` when multiple stylesheets are loaded, but preloads are only enabled for one of them.
328
-
329
- = 4.2.2 =
330
- * Small fix for themes/page builders which requests Google Fonts with protocol relative URI i.e. '//fonts.googleapis.com' instead of 'https://fonts.googleapis.com'.
331
- * Tested with Elementor. Works.
332
-
333
- = 4.2.1 =
334
- * OMGF now checks secure (https://) and non-secure (http://) requests to Google Fonts, because apparently some themes still do that, even though it's 2020, but whatever.
335
- * Tested with Divi and Bridge Theme. Works.
336
-
337
- = 4.2.0 | The What-4.0-should've-been Edition | October 7th, 2020 =
338
- * **IMPORTANT NOTICE: If you're upgrading from v4.x.x it's required to Empty your Cache Directory. Otherwise the Optimized Google Fonts Overview will not work.**
339
- * Added CSS2 (Variable Fonts) compatiblity,
340
- * No more spaces in filenames of downloaded fonts,
341
- * Added Optimize Fonts tab, which resembles the 'Generate Stylesheet' tab from v3, and features,
342
- * Optimization Mode: Force or Scan Posts/Pages,
343
- * If Force is selected, the URL can be specified which should be scanned for Google Fonts,
344
- * A complete overview of all detected fonts, grouped by stylesheet,
345
- * Options to preload or unload for each font.
346
- * Move settings to more sensible places and re-grouped them in 3 groups:
347
- * Optimize Fonts,
348
- * Detection Settings,
349
- * Advanced Settings.
350
- * OMGF will now throw a notice when a settings is changed which requires the cache to be flushed.
351
- * Several tweaks and fixes in OMGF's Auto Detection mechanism and Fonts Download API.
352
- * Fixed issue where OMGF wouldn't detect fonts in weight 400 (and 400 italic).
353
- * Major UX improvements,
354
- * Pros and Cons of each Optimization Mode are outlined upon selection,
355
- * Show loaded while actions are taking place,
356
- * Cleaned up sidebar and added a clear overview of available documentation.
357
- * Several tweaks and optimizations in overall performance.
358
-
359
- = 4.1.3 =
360
- * Fixed bug which would continuously show 'No fonts founds' notice in admin, among others.
361
- * Increased compatibility with caching plugins, which would cause static pages to be served and block OMGF from pointing requests to its Download API.
362
- * Added some notices (which disappear ;-)) for manual optimization process in admin area, making it clear when optimization is finished.
363
-
364
- = 4.1.2 =
365
- * Fixed syntax error (unexpected ')' on line 147).
366
-
367
- = 4.1.1 =
368
- * Use transients instead of options.
369
- * Fixed some minor notices and warnings.
370
-
371
- = 4.1.0 | October 1st, 2020 =
372
- * Added some on-boarding to ease the use of the new interface.
373
- * OMGF will now show a notice in the admin area, if the optimization never ran, to increase UX.
374
- * Added a loader when any of the following actions are triggered:
375
- * Empty Cache Directory
376
- * Start Optimization
377
- * Minor tweaks and optimizations.
378
-
379
- = 4.0.2 =
380
- * Fixed bug where OMGF would trigger too late for the requests to fonts.googleapis.com to be captured.
381
-
382
- = 4.0.1 =
383
- * The tiniest bugfix ever: one space too much in a str_replace() caused Font Names with spaces (e.g. Roboto Condensed, or Open Sans) to not be captured correctly.
384
 
385
  = 4.0.0 | September 30th, 2020 =
386
  * OMGF now runs fully automatic to replace/remove Google Fonts from your pages using OMGF's new Download API. No initial configuration required!
2
  Contributors: DaanvandenBergh
3
  Tags: google, fonts, gdpr, cache, speed, preload, font-display, webfonts, subsets, remove, minimize, external, requests
4
  Requires at least: 4.6
5
+ Tested up to: 6.0
6
+ Stable tag: 5.1.4
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
75
 
76
  == Changelog ==
77
 
78
+ = 5.1.4 | June 6th, 2022 =
79
+ * Tested with WP 6.0
80
+ * Fixed: Font-weights weren't properly detected when stylesheets were loaded using Variable Fonts (CSS2) API.
81
+ * Fixed: jQuery.fn.submit() shorthand is deprecated.
82
+ * Fixed: Improved compatibility with servers using Nginx reverse proxy.
83
+ * Fixed: Filter duplicate font-family requests in same Google Fonts request, e.g. fonts.googleapis.com/css?family=Roboto|Roboto.
84
+ * Added: Workaround for Elementor to identify unique Google Fonts stylesheets, because Elementor always uses the (annoyingly generic) 'google-fonts-1' handle as an identifier. :-/
85
+ * Fixed: Generate a 'unique' identifier for each stylesheet without an identifier ('id' attribute)
86
+ * Several minor performance improvements.
87
+
88
  = 5.1.3 =
89
  * Added: workaround for Divi builder to identify unique Google Fonts stylesheets.
90
  * Added: extra links to documentation in Manage Optimized Fonts section.
154
  * Fixed: Smart Slider 3 compatibility.
155
  * Several bugfixes, UX improvements and code optimizations.
156
 
157
+ [ Changelog shortened ... ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
  = 4.0.0 | September 30th, 2020 =
160
  * OMGF now runs fully automatic to replace/remove Google Fonts from your pages using OMGF's new Download API. No initial configuration required!