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

Version Description

  • Better error handling for Auto Detect.
  • Increased performance in admin area.
Download this release

Release Info

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

Code changes from version 3.4.2 to 3.4.3

host-webfonts-local.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: OMGF
5
  * Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
6
  * Description: Minimize DNS requests and leverage browser cache by easily saving Google Fonts to your server and removing the external Google Fonts.
7
- * Version: 3.4.2
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
4
  * Plugin Name: OMGF
5
  * Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
6
  * Description: Minimize DNS requests and leverage browser cache by easily saving Google Fonts to your server and removing the external Google Fonts.
7
+ * Version: 3.4.3
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
includes/class-api.php CHANGED
@@ -25,17 +25,15 @@ class OMGF_API
25
  */
26
  public function get_subsets($query)
27
  {
28
- $request = wp_remote_get(OMGF_HELPER_URL . $query);
29
 
30
- if (is_wp_error($request)) {
31
- OMGF_Admin_Notice::set_notice($request->get_error_message(), true, 'error', $request->get_error_code());
32
- }
33
 
34
- if ($request == 'Not found') {
35
  return [];
36
  }
37
 
38
- $result = json_decode($request['body']);
39
 
40
  return [
41
  'subset_family' => $result->family,
@@ -53,15 +51,19 @@ class OMGF_API
53
  */
54
  public function get_font_styles($font_family, $selected_subsets)
55
  {
56
- $request = wp_remote_get(OMGF_HELPER_URL . $font_family . '?subsets=' . $selected_subsets);
 
 
57
 
58
- if (wp_remote_retrieve_body($request) == 'Not found') {
59
- OMGF_Admin_Notice::set_notice(wp_remote_retrieve_response_message($request) . ': ' . $font_family, false, 'error', wp_remote_retrieve_response_code($request));
 
 
60
 
61
  return [];
62
  }
63
 
64
- $result = json_decode($request['body']);
65
 
66
  foreach ($result->variants as $variant) {
67
  $fonts[] = [
@@ -81,4 +83,17 @@ class OMGF_API
81
 
82
  return $fonts;
83
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
25
  */
26
  public function get_subsets($query)
27
  {
28
+ $response = wp_remote_get(OMGF_HELPER_URL . $query);
29
 
30
+ if (wp_remote_retrieve_response_code($response) != 200) {
31
+ $this->throw_error($response, $query);
 
32
 
 
33
  return [];
34
  }
35
 
36
+ $result = json_decode(wp_remote_retrieve_body($response));
37
 
38
  return [
39
  'subset_family' => $result->family,
51
  */
52
  public function get_font_styles($font_family, $selected_subsets)
53
  {
54
+ if (empty($font_family)) {
55
+ return [];
56
+ }
57
 
58
+ $response = wp_remote_get(OMGF_HELPER_URL . $font_family . '?subsets=' . $selected_subsets);
59
+
60
+ if (wp_remote_retrieve_response_code($response) != 200) {
61
+ $this->throw_error($response, $font_family);
62
 
63
  return [];
64
  }
65
 
66
+ $result = json_decode(wp_remote_retrieve_body($response));
67
 
68
  foreach ($result->variants as $variant) {
69
  $fonts[] = [
83
 
84
  return $fonts;
85
  }
86
+
87
+ /**
88
+ * Throw error based on response
89
+ *
90
+ * @param $response
91
+ * @param $query
92
+ */
93
+ private function throw_error($response, $query)
94
+ {
95
+ $message = wp_remote_retrieve_response_message($response);
96
+ $code = wp_remote_retrieve_response_code($response);
97
+ OMGF_Admin_Notice::set_notice(sprintf(__('An error occurred while searching for %s: %s', 'host-webfonts-local'), $query, $message), false, 'error', $code);
98
+ }
99
  }
includes/class-omgf.php CHANGED
@@ -18,17 +18,29 @@ defined('ABSPATH') || exit;
18
 
19
  class OMGF
20
  {
 
 
 
21
  /**
22
  * OMGF constructor.
23
  */
24
  public function __construct()
25
  {
26
  $this->define_constants();
 
27
 
28
  if (is_admin()) {
29
- $this->do_auto_detect();
30
  $this->do_settings();
31
  $this->add_ajax_hooks();
 
 
 
 
 
 
 
 
 
32
  add_action('plugin_loaded', array($this, 'do_setup'));
33
  }
34
 
18
 
19
  class OMGF
20
  {
21
+ /** @var string */
22
+ private $page = '';
23
+
24
  /**
25
  * OMGF constructor.
26
  */
27
  public function __construct()
28
  {
29
  $this->define_constants();
30
+ $this->page = isset($_GET['page']) ?: '';
31
 
32
  if (is_admin()) {
 
33
  $this->do_settings();
34
  $this->add_ajax_hooks();
35
+
36
+ /**
37
+ * If auto detect can't finish properly, due to e.g. an invalid API response, OMGF's settings page crashes.
38
+ * This will prevent it from crashing the entire admin area.
39
+ */
40
+ if ($this->page == 'optimize-webfonts') {
41
+ $this->do_auto_detect();
42
+ }
43
+
44
  add_action('plugin_loaded', array($this, 'do_setup'));
45
  }
46
 
includes/frontend/class-functions.php CHANGED
@@ -134,7 +134,7 @@ class OMGF_Frontend_Functions
134
  return array_filter(
135
  $registered_styles,
136
  function ($contents) {
137
- return strpos($contents->src, 'fonts.googleapis.com') !== false
138
  || strpos($contents->src, 'fonts.gstatic.com') !== false;
139
  }
140
  );
134
  return array_filter(
135
  $registered_styles,
136
  function ($contents) {
137
+ return strpos($contents->src, 'fonts.googleapis.com/css') !== false
138
  || strpos($contents->src, 'fonts.gstatic.com') !== false;
139
  }
140
  );
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.4
6
- Stable tag: 3.4.2
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -17,7 +17,7 @@ With only 2 clicks of a button, OMGF automagically downloads your Google Fonts y
17
 
18
  Leverage Browser Cache, Minimize DNS requests and serve your Google Fonts in a 100% GDPR compliant way with OMGF!
19
 
20
- OMGF is written with performance and user-friendliness in mind. It uses the Google Fonts Helper API to automagically download the fonts you want to WordPress' contents folder and generate a stylesheet for it. The stylesheet is automatically included to your site's header and 100% compatible with CSS and JS optimizing/minification plugins like Autoptimize or W3 Total Cache. OMGF can efficiently remove any requests to external Google Fonts (loaded from fonts.gstatic.com or fonts.googleapies.com).
21
 
22
  That's it. You're done!
23
 
@@ -108,6 +108,10 @@ N/A
108
 
109
  == Changelog ==
110
 
 
 
 
 
111
  = 3.4.2 =
112
  * OMGF now returns a readable error if Auto Detect detects a misformatted fonts URL.
113
 
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.4
6
+ Stable tag: 3.4.3
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
17
 
18
  Leverage Browser Cache, Minimize DNS requests and serve your Google Fonts in a 100% GDPR compliant way with OMGF!
19
 
20
+ OMGF is written with performance and user-friendliness in mind. It uses the Google Fonts Helper API to automagically download the fonts you want to WordPress' contents folder and generate a stylesheet for it. The stylesheet is automatically included to your site's header and 100% compatible with CSS and JS optimizing/minification plugins like Autoptimize or W3 Total Cache. OMGF can efficiently remove any requests to external Google Fonts (loaded from fonts.gstatic.com or fonts.googleapis.com).
21
 
22
  That's it. You're done!
23
 
108
 
109
  == Changelog ==
110
 
111
+ = 3.4.3 =
112
+ * Better error handling for Auto Detect.
113
+ * Increased performance in admin area.
114
+
115
  = 3.4.2 =
116
  * OMGF now returns a readable error if Auto Detect detects a misformatted fonts URL.
117