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

Version Description

| June 14th, 2022 = * Added: toggle to disable Elementor/Divi compatibility fixes. * Fixed: when resource hints (e.g. preloads) were located in unusual places (e.g. Themify Builder places its preloads above the <title> element) this would cause other elements (e.g. stylesheets) to be removed as well.

Download this release

Release Info

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

Code changes from version 5.1.4 to 5.2.0

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.4
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.2.0
8
  * Author: Daan from FFW.Press
9
  * Author URI: https://ffw.press
10
  * License: GPL2v2 or later
includes/admin/class-settings.php CHANGED
@@ -131,7 +131,8 @@ class OMGF_Admin_Settings extends OMGF_Admin
131
  /**
132
  * Advanced Settings
133
  */
134
- const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
 
135
 
136
  /**
137
  * Miscellaneous
131
  /**
132
  * Advanced Settings
133
  */
134
+ const OMGF_ADV_SETTING_COMPATIBILITY = 'omgf_compatibility';
135
+ const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
136
 
137
  /**
138
  * Miscellaneous
includes/admin/settings/class-advanced.php CHANGED
@@ -35,6 +35,7 @@ class OMGF_Admin_Settings_Advanced extends OMGF_Admin_Settings_Builder
35
  // Settings
36
  add_filter('omgf_advanced_settings_content', [$this, 'do_cache_dir'], 50);
37
  add_filter('omgf_advanced_settings_content', [$this, 'do_promo_fonts_source_url'], 60);
 
38
  add_filter('omgf_advanced_settings_content', [$this, 'do_uninstall'], 100);
39
 
40
  // Close
@@ -48,7 +49,7 @@ class OMGF_Admin_Settings_Advanced extends OMGF_Admin_Settings_Builder
48
  {
49
  ?>
50
  <p>
51
- <?= __('If you require the downloaded/generated files to be saved in a different location or served from a different resource (e.g. a CDN) or path, use these settings to make OMGF work with your configuration.', $this->plugin_text_domain); ?>
52
  </p>
53
  <?php
54
  }
@@ -88,6 +89,19 @@ class OMGF_Admin_Settings_Advanced extends OMGF_Admin_Settings_Builder
88
  );
89
  }
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  /**
92
  * Remove Settings/Files at Uninstall.
93
  */
35
  // Settings
36
  add_filter('omgf_advanced_settings_content', [$this, 'do_cache_dir'], 50);
37
  add_filter('omgf_advanced_settings_content', [$this, 'do_promo_fonts_source_url'], 60);
38
+ add_filter('omgf_advanced_settings_content', [$this, 'do_compatibility'], 70);
39
  add_filter('omgf_advanced_settings_content', [$this, 'do_uninstall'], 100);
40
 
41
  // Close
49
  {
50
  ?>
51
  <p>
52
+ <?= __('Use these settings to make OMGF work with your specific configuration.', $this->plugin_text_domain); ?>
53
  </p>
54
  <?php
55
  }
89
  );
90
  }
91
 
92
+ /**
93
+ *
94
+ */
95
+ public function do_compatibility()
96
+ {
97
+ $this->do_checkbox(
98
+ __('Divi/Elementor Compatibility', $this->plugin_text_domain),
99
+ OMGF_Admin_Settings::OMGF_ADV_SETTING_COMPATIBILITY,
100
+ OMGF_COMPATIBILITY,
101
+ __('Divi and Elementor use the same handle for Google Fonts stylesheets with different configurations. OMGF includes compatibility fixes to make sure these different stylesheets are processed correctly. However, if you have too many different stylesheets and you want to force the usage of 1 stylesheet throughout all your pages, disabling Divi/Elementor Compatibility might help. Default: on', $this->plugin_text_domain)
102
+ );
103
+ }
104
+
105
  /**
106
  * Remove Settings/Files at Uninstall.
107
  */
includes/class-omgf.php CHANGED
@@ -59,6 +59,7 @@ class OMGF
59
  define('OMGF_UNLOAD_STYLESHEETS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, '')));
60
  define('OMGF_CACHE_KEYS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS, '')));
61
  define('OMGF_TEST_MODE', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_TEST_MODE)));
 
62
  define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
63
  define('OMGF_UPLOAD_DIR', apply_filters('omgf_upload_dir', WP_CONTENT_DIR . '/uploads/omgf'));
64
  define('OMGF_UPLOAD_URL', apply_filters('omgf_upload_url', WP_CONTENT_URL . '/uploads/omgf'));
59
  define('OMGF_UNLOAD_STYLESHEETS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, '')));
60
  define('OMGF_CACHE_KEYS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS, '')));
61
  define('OMGF_TEST_MODE', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_TEST_MODE)));
62
+ define('OMGF_COMPATIBILITY', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_COMPATIBILITY, 'on')));
63
  define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
64
  define('OMGF_UPLOAD_DIR', apply_filters('omgf_upload_dir', WP_CONTENT_DIR . '/uploads/omgf'));
65
  define('OMGF_UPLOAD_URL', apply_filters('omgf_upload_url', WP_CONTENT_URL . '/uploads/omgf'));
includes/frontend/class-process.php CHANGED
@@ -17,7 +17,9 @@ defined('ABSPATH') || exit;
17
  * * * * * * * * * * * * * * * * * * * */
18
  class OMGF_Frontend_Process
19
  {
20
- const RESOURCE_HINTS = ['fonts.googleapis.com', 'fonts.gstatic.com'];
 
 
21
 
22
  /**
23
  * @var array $page_builders Array of keys set by page builders when they're displaying their previews.
@@ -232,7 +234,11 @@ class OMGF_Frontend_Process
232
  */
233
  public function remove_resource_hints($html)
234
  {
235
- preg_match_all('/<link.*?(dns-prefetch|preconnect).*?>/', $html, $resource_hints);
 
 
 
 
236
 
237
  if (!isset($resource_hints[0]) || empty($resource_hints[0])) {
238
  return $html;
@@ -241,14 +247,20 @@ class OMGF_Frontend_Process
241
  $search = [];
242
 
243
  foreach ($resource_hints[0] as $key => $match) {
244
- if (
245
- strpos($match, 'fonts.googleapis.com') === false
246
- && strpos($match, 'fonts.gstatic.com') === false
247
- ) {
248
- continue;
 
 
 
 
 
 
 
 
249
  }
250
-
251
- $search[] = $match;
252
  }
253
 
254
  return str_replace($search, '', $html);
@@ -355,10 +367,14 @@ class OMGF_Frontend_Process
355
  * even when these contain Google Fonts, let's append a (kind of) unique
356
  * identifier to the string, to make sure we can make a difference between
357
  * different Google Fonts configurations.
 
 
 
 
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
  *
17
  * * * * * * * * * * * * * * * * * * * */
18
  class OMGF_Frontend_Process
19
  {
20
+ const RESOURCE_HINTS_URLS = ['fonts.googleapis.com', 'fonts.gstatic.com'];
21
+
22
+ const RESOURCE_HINTS_ATTR = ['dns-prefetch', 'preconnect', 'preload'];
23
 
24
  /**
25
  * @var array $page_builders Array of keys set by page builders when they're displaying their previews.
234
  */
235
  public function remove_resource_hints($html)
236
  {
237
+ /**
238
+ * @since v5.1.5 Use a lookaround that matches all link elements, because otherwise
239
+ * matches grow past their supposed boundaries.
240
+ */
241
+ preg_match_all('/(?=\<link).+?(?<=>)/', $html, $resource_hints);
242
 
243
  if (!isset($resource_hints[0]) || empty($resource_hints[0])) {
244
  return $html;
247
  $search = [];
248
 
249
  foreach ($resource_hints[0] as $key => $match) {
250
+ /**
251
+ * @since v5.1.5 Filter out any resource hints with a href pointing to Google Fonts' APIs.
252
+ *
253
+ * @todo: I think I should be able to use an array_filter here or something?
254
+ */
255
+ foreach (self::RESOURCE_HINTS_URLS as $url) {
256
+ if (strpos($match, $url) !== false) {
257
+ foreach (self::RESOURCE_HINTS_ATTR as $attr) {
258
+ if (strpos($match, $attr) !== false) {
259
+ $search[] = $match;
260
+ }
261
+ }
262
+ }
263
  }
 
 
264
  }
265
 
266
  return str_replace($search, '', $html);
367
  * even when these contain Google Fonts, let's append a (kind of) unique
368
  * identifier to the string, to make sure we can make a difference between
369
  * different Google Fonts configurations.
370
+ *
371
+ * @since v5.2.0 Allow Divi/Elementor) compatibility fixes to be disabled, for those who have too
372
+ * many different Google Fonts stylesheets configured throughout their pages and
373
+ * blame OMGF for the fact that it detects all those different stylesheets. :-/
374
  */
375
+ if (OMGF_COMPATIBILITY && strpos($id, 'et-builder-googlefonts') !== false) {
376
  $google_fonts[$key]['id'] = $id . '-' . strlen($href['href']);
377
+ } elseif (OMGF_COMPATIBILITY && $id === 'google-fonts-1') {
378
  /**
379
  * Compatibility fix for Elementor
380
  *
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: 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,6 +75,10 @@ For the FAQ, [click here](https://ffw.press/docs/omgf-pro-faq/).
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.
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.2.0
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.2.0 | June 14th, 2022 =
79
+ * Added: toggle to disable Elementor/Divi compatibility fixes.
80
+ * Fixed: when resource hints (e.g. preloads) were located in unusual places (e.g. Themify Builder places its preloads above the `<title>` element) this would cause other elements (e.g. stylesheets) to be removed as well.
81
+
82
  = 5.1.4 | June 6th, 2022 =
83
  * Tested with WP 6.0
84
  * Fixed: Font-weights weren't properly detected when stylesheets were loaded using Variable Fonts (CSS2) API.