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

Version Description

  • Fixed: Previous versions of OMGF would save stylesheet handles without the appended '-css' string. This is now brought back to guarantee a smooth transition to v5.
  • Fixed: If ?nomgf=1 parameter was set, preloads would still be loaded.
  • Fixed: Added an extra check if file exists, before adding font files for preloading.
  • Enhanced: A small speed boost for Save & Optimize.
Download this release

Release Info

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

Code changes from version 5.0.0 to 5.0.1

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.0.0
8
  * Author: Daan from FFW.Press
9
  * Author URI: https://ffw.press
10
  * License: GPL2v2 or later
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.0.1
8
  * Author: Daan from FFW.Press
9
  * Author URI: https://ffw.press
10
  * License: GPL2v2 or later
includes/frontend/class-process.php CHANGED
@@ -39,6 +39,23 @@ class OMGF_Frontend_Process
39
  */
40
  public function __construct()
41
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  add_action('template_redirect', [$this, 'maybe_buffer_output'], 3);
43
  add_filter('omgf_buffer_output', [$this, 'parse']);
44
  add_action('wp_head', [$this, 'add_preloads'], 3);
@@ -61,21 +78,9 @@ class OMGF_Frontend_Process
61
  }
62
 
63
  $optimized_fonts = apply_filters('omgf_frontend_optimized_fonts', OMGF::optimized_fonts());
64
-
65
- /**
66
- * When OMGF Pro is enabled and set to Automatic mode, the merged handle is used to only load selected
67
- * preloads for the currently used stylesheet.
68
- *
69
- * @since v4.5.3 Added 2nd dummy parameter, to prevent Fatal Errors after updating.
70
- */
71
- $pro_handle = apply_filters('omgf_pro_merged_handle', '', '');
72
- $i = 0;
73
 
74
  foreach ($optimized_fonts as $stylesheet_handle => $font_faces) {
75
- if ($pro_handle && $stylesheet_handle != $pro_handle) {
76
- continue;
77
- }
78
-
79
  foreach ($font_faces as $font_face) {
80
  $preloads_stylesheet = $preloaded_fonts[$stylesheet_handle] ?? [];
81
 
@@ -93,6 +98,14 @@ class OMGF_Frontend_Process
93
 
94
  foreach ($preload_variants as $variant) {
95
  $url = rawurldecode($variant->woff2);
 
 
 
 
 
 
 
 
96
  echo "<link id='omgf-preload-$i' rel='preload' href='$url' as='font' type='font/woff2' crossorigin />\n";
97
  $i++;
98
  }
@@ -135,10 +148,10 @@ class OMGF_Frontend_Process
135
  public function maybe_buffer_output()
136
  {
137
  /**
138
- * Allows us to quickly bypass fonts optimization.
139
  */
140
- if (isset($_GET['nomgf'])) {
141
- return false;
142
  }
143
 
144
  /**
@@ -157,6 +170,16 @@ class OMGF_Frontend_Process
157
  }
158
  }
159
 
 
 
 
 
 
 
 
 
 
 
160
  /**
161
  * Customizer previews shouldn't get optimized content.
162
  */
@@ -263,7 +286,7 @@ class OMGF_Frontend_Process
263
  foreach ($links as $key => $link) {
264
  preg_match('/id=[\'"](?P<id>.*?)[\'"]/', $link, $id);
265
 
266
- $id = $id['id'] ?? "$handle-$key";
267
 
268
  preg_match('/href=[\'"](?P<href>.*?)[\'"]/', $link, $href);
269
 
@@ -280,6 +303,25 @@ class OMGF_Frontend_Process
280
  return $google_fonts;
281
  }
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  /**
284
  * Build a Search/Replace array for all found Google Fonts.
285
  *
39
  */
40
  public function __construct()
41
  {
42
+ $this->init();
43
+ }
44
+
45
+ /**
46
+ * Actions and hooks.
47
+ *
48
+ * @return void
49
+ */
50
+ private function init()
51
+ {
52
+ /**
53
+ * Halt if this parameter is set.
54
+ */
55
+ if (isset($_GET['nomgf'])) {
56
+ return;
57
+ }
58
+
59
  add_action('template_redirect', [$this, 'maybe_buffer_output'], 3);
60
  add_filter('omgf_buffer_output', [$this, 'parse']);
61
  add_action('wp_head', [$this, 'add_preloads'], 3);
78
  }
79
 
80
  $optimized_fonts = apply_filters('omgf_frontend_optimized_fonts', OMGF::optimized_fonts());
81
+ $i = 0;
 
 
 
 
 
 
 
 
82
 
83
  foreach ($optimized_fonts as $stylesheet_handle => $font_faces) {
 
 
 
 
84
  foreach ($font_faces as $font_face) {
85
  $preloads_stylesheet = $preloaded_fonts[$stylesheet_handle] ?? [];
86
 
98
 
99
  foreach ($preload_variants as $variant) {
100
  $url = rawurldecode($variant->woff2);
101
+
102
+ /**
103
+ * @since v5.0.1 An extra check, because people tend to forget to flush their caches when changing fonts, etc.
104
+ */
105
+ if (!file_exists(str_replace(content_url(), WP_CONTENT_DIR, $url))) {
106
+ continue;
107
+ }
108
+
109
  echo "<link id='omgf-preload-$i' rel='preload' href='$url' as='font' type='font/woff2' crossorigin />\n";
110
  $i++;
111
  }
148
  public function maybe_buffer_output()
149
  {
150
  /**
151
+ * Always run, if the omgf_optimize (added by Save & Optimize) is set.
152
  */
153
+ if (isset($_GET['omgf_optimize'])) {
154
+ return true;
155
  }
156
 
157
  /**
170
  }
171
  }
172
 
173
+ /**
174
+ * Honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders,
175
+ *
176
+ * @see https://www.modpagespeed.com/doc/experiment#ModPagespeed
177
+ */
178
+ if (array_key_exists('PageSpeed', $_GET) && 'off' === $_GET['PageSpeed']) {
179
+ return false;
180
+ }
181
+
182
+
183
  /**
184
  * Customizer previews shouldn't get optimized content.
185
  */
286
  foreach ($links as $key => $link) {
287
  preg_match('/id=[\'"](?P<id>.*?)[\'"]/', $link, $id);
288
 
289
+ $id = $this->strip_css_tag($id['id'] ?? "$handle-$key");
290
 
291
  preg_match('/href=[\'"](?P<href>.*?)[\'"]/', $link, $href);
292
 
303
  return $google_fonts;
304
  }
305
 
306
+ /**
307
+ * Strip "-css" from the end of the stylesheet id, which WordPress adds to properly enqueued stylesheets.
308
+ *
309
+ * @since v5.0.1 This eases the migration from v4.6.0.
310
+ *
311
+ * @param mixed $handle
312
+ * @return mixed
313
+ */
314
+ private function strip_css_tag($handle)
315
+ {
316
+ $pos = strrpos($handle, '-css');
317
+
318
+ if ($pos !== false) {
319
+ $handle = substr_replace($handle, '', $pos, strlen($handle));
320
+ }
321
+
322
+ return $handle;
323
+ }
324
+
325
  /**
326
  * Build a Search/Replace array for all found Google Fonts.
327
  *
readme.txt CHANGED
@@ -3,7 +3,7 @@ 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.0.0
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,12 @@ For the FAQ, [click here](https://docs.ffw.press/category/76-omgf-pro---faq).
75
 
76
  == Changelog ==
77
 
 
 
 
 
 
 
78
  = 5.0.0 - **The Better, Bigger, Faster, Stronger, Cooler, Awesomer Edition** | March 4th, 2022 =
79
  * Added: Parse entire HTML document for Google Fonts stylesheets (instead of just wp_head())
80
  * Added: Merged both Optimization Modes option into one automatically running option:
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.0.1
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.0.1 =
79
+ * Fixed: Previous versions of OMGF would save stylesheet handles without the appended '-css' string. This is now brought back to guarantee a smooth transition to v5.
80
+ * Fixed: If `?nomgf=1` parameter was set, preloads would still be loaded.
81
+ * Fixed: Added an extra check if file exists, before adding font files for preloading.
82
+ * Enhanced: A small speed boost for Save & Optimize.
83
+
84
  = 5.0.0 - **The Better, Bigger, Faster, Stronger, Cooler, Awesomer Edition** | March 4th, 2022 =
85
  * Added: Parse entire HTML document for Google Fonts stylesheets (instead of just wp_head())
86
  * Added: Merged both Optimization Modes option into one automatically running option: