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

Version Description

| April 5th, 2021 = * Fixed MIME type (X-Content-Type-Options: nosniff) related errors when using Download API. * When site is not using SSL, SSL verification (sslverify) is disabled while contacting the Download API. * When OMGF Pro is running in Automatic Mode, only preloads for the currently used stylesheet are loaded.

Download this release

Release Info

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

Code changes from version 4.3.1 to 4.3.2

host-webfonts-local.php CHANGED
@@ -5,7 +5,7 @@
5
  * Plugin Name: OMGF
6
  * Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
7
  * Description: Minimize DNS requests, leverage browser cache and speed up WordPress by saving Google Fonts to your server and removing external Google Fonts requests.
8
- * Version: 4.3.1
9
  * Author: Daan from FFW.Press
10
  * Author URI: https://ffw.press
11
  * License: GPL2v2 or later
5
  * Plugin Name: OMGF
6
  * Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
7
  * Description: Minimize DNS requests, leverage browser cache and speed up WordPress by saving Google Fonts to your server and removing external Google Fonts requests.
8
+ * Version: 4.3.2
9
  * Author: Daan from FFW.Press
10
  * Author URI: https://ffw.press
11
  * License: GPL2v2 or later
includes/admin/settings/class-optimize.php CHANGED
@@ -69,7 +69,7 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
69
  OMGF_Admin_Settings::OMGF_OPTIMIZATION_MODE,
70
  OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE,
71
  OMGF_OPTIMIZATION_MODE,
72
- __('<strong>Manual</strong> processing mode is best suited for configurations, which use a fixed number of fonts across the entire site. <strong>Automatic</strong> processing mode is best suited for configurations using e.g. page builders, which load different fonts on certain pages.', $this->plugin_text_domain)
73
  );
74
  }
75
 
69
  OMGF_Admin_Settings::OMGF_OPTIMIZATION_MODE,
70
  OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE,
71
  OMGF_OPTIMIZATION_MODE,
72
+ __('<strong>Manual</strong> processing mode is best suited for configurations, which use a fixed number of fonts across the entire site. When in manual mode, the generated stylesheet is forced throughout the entire site.<strong>Automatic</strong> processing mode is best suited for configurations using e.g. page builders, which load different fonts on certain pages.', $this->plugin_text_domain)
73
  );
74
  }
75
 
includes/api/class-download.php CHANGED
@@ -108,7 +108,12 @@ class OMGF_API_Download extends WP_REST_Controller
108
  foreach ($fonts as $font_key => &$font) {
109
  $fonts_request = $this->build_fonts_request($font_families, $font);
110
 
111
- list($family, $variants) = explode(':', $fonts_request);
 
 
 
 
 
112
 
113
  $variants = $this->parse_requested_variants($variants, $font);
114
 
@@ -224,7 +229,12 @@ class OMGF_API_Download extends WP_REST_Controller
224
  }
225
 
226
  foreach ($font_families as $font_family) {
227
- list($family, $weights) = explode(':', reset($font_family));
 
 
 
 
 
228
 
229
  /**
230
  * @return array [ '300', '400', '500', etc. ]
@@ -258,8 +268,8 @@ class OMGF_API_Download extends WP_REST_Controller
258
  {
259
  $url = self::OMGF_GOOGLE_FONTS_API_URL . '/api/fonts/%s';
260
 
261
- list($family, $variants) = explode(':', $font_family);
262
- $family = strtolower(str_replace([' ', '+'], '-', $family));
263
 
264
  /**
265
  * Add fonts to the request's $_GET 'family' parameter. Then pass an array to 'omgf_alternate_fonts'
@@ -364,7 +374,12 @@ class OMGF_API_Download extends WP_REST_Controller
364
  */
365
  private function filter_variants($font_id, $available, $wanted, $stylesheet_handle)
366
  {
367
- list($family, $variants) = explode(':', $wanted);
 
 
 
 
 
368
 
369
  /**
370
  * Build array and filter out empty elements.
108
  foreach ($fonts as $font_key => &$font) {
109
  $fonts_request = $this->build_fonts_request($font_families, $font);
110
 
111
+ if (strpos($fonts_request, ':') != false) {
112
+ list($family, $variants) = explode(':', $fonts_request);
113
+ } else {
114
+ $family = $fonts_request;
115
+ $variants = '';
116
+ }
117
 
118
  $variants = $this->parse_requested_variants($variants, $font);
119
 
229
  }
230
 
231
  foreach ($font_families as $font_family) {
232
+ if (strpos($font_family, ':') !== false) {
233
+ list($family, $weights) = explode(':', reset($font_family));
234
+ } else {
235
+ $family = $font_family;
236
+ $weights = '';
237
+ }
238
 
239
  /**
240
  * @return array [ '300', '400', '500', etc. ]
268
  {
269
  $url = self::OMGF_GOOGLE_FONTS_API_URL . '/api/fonts/%s';
270
 
271
+ list($family) = explode(':', $font_family);
272
+ $family = strtolower(str_replace([' ', '+'], '-', $family));
273
 
274
  /**
275
  * Add fonts to the request's $_GET 'family' parameter. Then pass an array to 'omgf_alternate_fonts'
374
  */
375
  private function filter_variants($font_id, $available, $wanted, $stylesheet_handle)
376
  {
377
+ if (strpos($wanted, ':') !== false) {
378
+ // We don't need the first variable.
379
+ list(, $variants) = explode(':', $wanted);
380
+ } else {
381
+ $variants = '';
382
+ }
383
 
384
  /**
385
  * Build array and filter out empty elements.
includes/class-optimize.php CHANGED
@@ -60,12 +60,7 @@ class OMGF_Optimize
60
  {
61
  $url = esc_url_raw($_POST[OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL]);
62
 
63
- $front_html = wp_remote_get(
64
- $this->no_cache_optimize_url($url),
65
- [
66
- 'timeout' => 30,
67
- ]
68
- );
69
 
70
  if (is_wp_error($front_html)) {
71
  $this->frontend_fetch_failed($front_html);
@@ -88,12 +83,7 @@ class OMGF_Optimize
88
  }
89
 
90
  foreach ($urls as $url) {
91
- $download = wp_remote_get(
92
- $this->no_cache_optimize_url($url),
93
- [
94
- 'timeout' => 30
95
- ]
96
- );
97
 
98
  if (is_wp_error($download)) {
99
  $this->download_failed($download);
@@ -145,6 +135,34 @@ class OMGF_Optimize
145
  );
146
  }
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  /**
149
  * @param $url
150
  *
60
  {
61
  $url = esc_url_raw($_POST[OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL]);
62
 
63
+ $front_html = $this->remote_get($url);
 
 
 
 
 
64
 
65
  if (is_wp_error($front_html)) {
66
  $this->frontend_fetch_failed($front_html);
83
  }
84
 
85
  foreach ($urls as $url) {
86
+ $download = $this->remote_get($url);
 
 
 
 
 
87
 
88
  if (is_wp_error($download)) {
89
  $this->download_failed($download);
135
  );
136
  }
137
 
138
+ /**
139
+ * Wrapper for wp_remote_get() with preset params.
140
+ *
141
+ * @param mixed $url
142
+ * @return array|WP_Error
143
+ */
144
+ private function remote_get($url)
145
+ {
146
+ return wp_remote_get(
147
+ $this->no_cache_optimize_url($url),
148
+ [
149
+ 'timeout' => 30,
150
+ 'sslverify' => $this->verify_ssl($url)
151
+ ]
152
+ );
153
+ }
154
+
155
+ /**
156
+ * If URL is non-SSL, return false.
157
+ *
158
+ * @param mixed $url
159
+ * @return bool
160
+ */
161
+ private function verify_ssl($url)
162
+ {
163
+ return strpos($url, 'https:') !== false;
164
+ }
165
+
166
  /**
167
  * @param $url
168
  *
includes/frontend/class-functions.php CHANGED
@@ -30,6 +30,10 @@ class OMGF_Frontend_Functions
30
  {
31
  $this->do_optimize = $this->maybe_optimize_fonts();
32
 
 
 
 
 
33
  add_action('wp_head', [$this, 'add_preloads'], 3);
34
  add_action('wp_print_styles', [$this, 'process_fonts'], PHP_INT_MAX - 1000);
35
  }
@@ -67,21 +71,32 @@ class OMGF_Frontend_Functions
67
  return;
68
  }
69
 
70
- $stylesheets = apply_filters('omgf_frontend_optimized_fonts', omgf_init()::optimized_fonts());
 
 
 
 
 
 
 
71
 
72
  $i = 0;
73
 
74
- foreach ($stylesheets as $stylesheet => $fonts) {
75
- foreach ($fonts as $font) {
76
- $preloads_stylesheet = $preloaded_fonts[$stylesheet] ?? [];
 
77
 
78
- if (!in_array($font->id, array_keys($preloads_stylesheet))) {
 
 
 
79
  continue;
80
  }
81
 
82
- $font_id = $font->id;
83
  $preload_variants = array_filter(
84
- (array) $font->variants,
85
  function ($variant) use ($preloads_stylesheet, $font_id) {
86
  return in_array($variant->id, $preloads_stylesheet[$font_id]);
87
  }
@@ -101,10 +116,6 @@ class OMGF_Frontend_Functions
101
  */
102
  public function process_fonts()
103
  {
104
- if (!$this->do_optimize) {
105
- return;
106
- }
107
-
108
  if (is_admin()) {
109
  return;
110
  }
30
  {
31
  $this->do_optimize = $this->maybe_optimize_fonts();
32
 
33
+ if (!$this->do_optimize) {
34
+ return;
35
+ }
36
+
37
  add_action('wp_head', [$this, 'add_preloads'], 3);
38
  add_action('wp_print_styles', [$this, 'process_fonts'], PHP_INT_MAX - 1000);
39
  }
71
  return;
72
  }
73
 
74
+ $optimized_fonts = apply_filters('omgf_frontend_optimized_fonts', omgf_init()::optimized_fonts());
75
+
76
+ /**
77
+ * When OMGF Pro is enabled and set to Automatic mode, the merged handle is used to only load selected
78
+ * preloads for the currently used stylesheet.
79
+ */
80
+ $id = get_queried_object_id();
81
+ $pro_handle = apply_filters('omgf_pro_merged_handle', '', $id);
82
 
83
  $i = 0;
84
 
85
+ foreach ($optimized_fonts as $stylesheet_handle => $font_faces) {
86
+ if ($pro_handle && $stylesheet_handle != $pro_handle) {
87
+ continue;
88
+ }
89
 
90
+ foreach ($font_faces as $font_face) {
91
+ $preloads_stylesheet = $preloaded_fonts[$stylesheet_handle] ?? [];
92
+
93
+ if (!in_array($font_face->id, array_keys($preloads_stylesheet))) {
94
  continue;
95
  }
96
 
97
+ $font_id = $font_face->id;
98
  $preload_variants = array_filter(
99
+ (array) $font_face->variants,
100
  function ($variant) use ($preloads_stylesheet, $font_id) {
101
  return in_array($variant->id, $preloads_stylesheet[$font_id]);
102
  }
116
  */
117
  public function process_fonts()
118
  {
 
 
 
 
119
  if (is_admin()) {
120
  return;
121
  }
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.7
6
- Stable tag: 4.3.1
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -123,6 +123,11 @@ No, not yet. But I will definitely try to make it compatible in the future!
123
 
124
  == Changelog ==
125
 
 
 
 
 
 
126
  = 4.3.1 | March 29th, 2021 =
127
  * Added Mukta (FKA Ek Mukta) to list of renamed Google Fonts.
128
 
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.7
6
+ Stable tag: 4.3.2
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
123
 
124
  == Changelog ==
125
 
126
+ = 4.3.2 | April 5th, 2021 =
127
+ * Fixed MIME type (`X-Content-Type-Options: nosniff`) related errors when using Download API.
128
+ * When site is not using SSL, SSL verification (`sslverify`) is disabled while contacting the Download API.
129
+ * When OMGF Pro is running in Automatic Mode, only preloads for the currently used stylesheet are loaded.
130
+
131
  = 4.3.1 | March 29th, 2021 =
132
  * Added Mukta (FKA Ek Mukta) to list of renamed Google Fonts.
133