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

Version Description

  • OMGF now supports add-ons to extend its Auto Detect and Auto Removal feature.
  • From now on, a notice containing a link to the required add-on will be thrown for known themes and frameworks which follow unconventional methods to include Google Fonts.
    • This list now contains Thrive Themes and Redux Framework, but other themes (I'm researching Avada) will be added in the near future.
  • Generated stylesheets and downloaded fonts are now be saved to the 'uploads/omgf' folder by default.
Download this release

Release Info

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

Code changes from version 3.5.0 to 3.6.0

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.5.0
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.6.0
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
includes/admin/class-settings.php CHANGED
@@ -101,7 +101,7 @@ class OMGF_Admin_Settings extends OMGF_Admin
101
  {
102
  add_options_page(
103
  'OMGF',
104
- 'Optimize Webfonts',
105
  'manage_options',
106
  'optimize-webfonts',
107
  array(
101
  {
102
  add_options_page(
103
  'OMGF',
104
+ 'Optimize Google Fonts',
105
  'manage_options',
106
  'optimize-webfonts',
107
  array(
includes/class-ajax.php CHANGED
@@ -18,8 +18,35 @@ defined('ABSPATH') || exit;
18
 
19
  class OMGF_AJAX
20
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  protected $db;
22
 
 
 
 
23
  /**
24
  * OMGF_AJAX constructor.
25
  */
@@ -49,7 +76,7 @@ class OMGF_AJAX
49
 
50
 
51
  if (!($query = $_POST['search_query'])) {
52
- OMGF_Admin_Notice::set_notice(__('Search query not found.', 'host-webfonts-local'), true, 'warning');
53
  }
54
 
55
  $query = strtolower(str_replace(', ', ',', $query));
@@ -63,7 +90,7 @@ class OMGF_AJAX
63
 
64
  // If subset search comes back empty. Add a notice and skip to the next one.
65
  if (empty($subsets)) {
66
- OMGF_Admin_Notice::set_notice(sprintf(__('Font %s not found. Are you sure it\'s a Google Font?', 'host-webfonts-local'), $searchQuery), false, 'error');
67
 
68
  continue;
69
  }
@@ -75,7 +102,7 @@ class OMGF_AJAX
75
 
76
  update_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS, $option_subsets);
77
 
78
- OMGF_Admin_Notice::set_notice(__('Subset search complete. Select subsets to generate a list of available font styles.', 'host-webfonts-local'));
79
  }
80
 
81
  /**
@@ -83,11 +110,51 @@ class OMGF_AJAX
83
  */
84
  public function enable_auto_detect()
85
  {
 
 
 
 
86
  update_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, true);
87
 
88
  $url = get_permalink(get_posts()[0]->ID);
89
 
90
- OMGF_Admin_Notice::set_notice(__("Auto Detect enabled. Open any page on your frontend (e.g. your <a href='$url' target='_blank'>latest post</a>). After the page is fully loaded, return here and <a href='javascript:location.reload()'>click here</a> to refresh this page.", "host-webfonts-local"));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  }
92
 
93
  /**
@@ -134,7 +201,7 @@ class OMGF_AJAX
134
 
135
  update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $fonts);
136
 
137
- OMGF_Admin_Notice::set_notice(count($fonts) . ' ' . __('font styles found. Trim the list to your needs and click <strong>Download Fonts</strong>.', 'host-webfonts-local'));
138
  }
139
 
140
  /**
@@ -160,7 +227,7 @@ class OMGF_AJAX
160
 
161
  update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $selected_fonts);
162
 
163
- OMGF_Admin_Notice::set_notice(count($current_fonts) - count($selected_fonts) . ' ' . __('fonts removed from list and', 'host-webfonts-local') . ' ' . count($to_be_preloaded) . ' ' . __('fonts set to preload. If you haven\'t already, you can now <strong>download</strong> the <strong>fonts</strong>. Otherwise, just (re-)<strong>generate</strong> the <strong>stylesheet</strong>.', 'host-webfonts-local'), false);
164
  }
165
 
166
  /**
@@ -190,9 +257,9 @@ class OMGF_AJAX
190
 
191
  array_map('unlink', array_filter((array) glob(OMGF_FONTS_DIR . '/*')));
192
 
193
- OMGF_Admin_Notice::set_notice(__('Cache directory successfully emptied.', 'host-webfonts-local'));
194
  } catch (\Exception $e) {
195
- OMGF_Admin_Notice::set_notice(__('Something went wrong while emptying the cache directory: ', 'host-webfonts-local') . $e->getMessage(), true, 'error', $e->getCode());
196
  }
197
  }
198
  }
18
 
19
  class OMGF_AJAX
20
  {
21
+ /**
22
+ * A list of themes which use unconventional methods to load Google Fonts.
23
+ */
24
+ const OMGF_INCOMPATIBLE_THEMES = [
25
+ 'thrive-theme'
26
+ ];
27
+
28
+ /**
29
+ * A list of frameworks (plugins) for themes which use unconventional methods to load Google Fonts.
30
+ */
31
+ const OMGF_INCOMPATIBLE_FRAMEWORKS = [
32
+ 'redux-framework' => [
33
+ 'title' => 'Redux Framework',
34
+ 'basename' => 'redux-framework/redux-framework.php'
35
+ ]
36
+ ];
37
+
38
+ /** @var string $addon_url */
39
+ private $addon_url = 'https://woosh.dev/wordpress-plugins/omgf-%s-compatibility/';
40
+
41
+ /** @var string $addon_slug */
42
+ private $addon_slug = 'omgf-%s-compatibility';
43
+
44
+ /** @var OMGF_DB $db */
45
  protected $db;
46
 
47
+ /** @var string $plugin_text_domain */
48
+ private $plugin_text_domain = 'host-webfonts-local';
49
+
50
  /**
51
  * OMGF_AJAX constructor.
52
  */
76
 
77
 
78
  if (!($query = $_POST['search_query'])) {
79
+ OMGF_Admin_Notice::set_notice(__('Search query not found.', $this->plugin_text_domain), true, 'warning');
80
  }
81
 
82
  $query = strtolower(str_replace(', ', ',', $query));
90
 
91
  // If subset search comes back empty. Add a notice and skip to the next one.
92
  if (empty($subsets)) {
93
+ OMGF_Admin_Notice::set_notice(sprintf(__('Font %s not found. Are you sure it\'s a Google Font?', $this->plugin_text_domain), $searchQuery), false, 'error');
94
 
95
  continue;
96
  }
102
 
103
  update_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS, $option_subsets);
104
 
105
+ OMGF_Admin_Notice::set_notice(__('Subset search complete. Select subsets to generate a list of available font styles.', $this->plugin_text_domain));
106
  }
107
 
108
  /**
110
  */
111
  public function enable_auto_detect()
112
  {
113
+ $this->check_theme_compatibility();
114
+
115
+ $this->check_framework_compatibility();
116
+
117
  update_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, true);
118
 
119
  $url = get_permalink(get_posts()[0]->ID);
120
 
121
+ OMGF_Admin_Notice::set_notice(__("Auto Detect enabled. Open any page on your frontend (e.g. your <a href='$url' target='_blank'>latest post</a>). After the page is fully loaded, return here and <a href='javascript:location.reload()'>click here</a> to refresh this page.", $this->plugin_text_domain));
122
+ }
123
+
124
+ /**
125
+ * Throw a warning if an incompatible theme is used.
126
+ */
127
+ private function check_theme_compatibility()
128
+ {
129
+ $theme = wp_get_theme();
130
+ $template = $theme->get_template();
131
+
132
+ $this->plugin_text_domain = 'host-webfonts-local';
133
+ $compatibility_addon = sprintf($this->addon_slug, $template) . '/' . sprintf($this->addon_slug, $template) . '.php';
134
+
135
+ if (in_array($template, self::OMGF_INCOMPATIBLE_THEMES) && !is_plugin_active($compatibility_addon)) {
136
+ $name = $theme->get('Name');
137
+ $url = sprintf($this->addon_url, $template);
138
+
139
+ OMGF_Admin_Notice::set_notice(sprintf(__("Your theme, <strong>$name</strong>, uses unconventional methods to load Google Fonts. For OMGF to work properly with $name, a premium add-on <em>(starting at € 39, -)</em> is required. Click <a href='%s' target='_blank'>here</a> for more information.", $this->plugin_text_domain), $url), true, 'warning');
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Throw a warning if an incompatible framework is used.
145
+ */
146
+ private function check_framework_compatibility()
147
+ {
148
+ foreach (self::OMGF_INCOMPATIBLE_FRAMEWORKS as $slug => $info) {
149
+ $compatibility_addon = sprintf($this->addon_slug, $slug) . '/' . sprintf($this->addon_slug, $slug) . '.php';
150
+
151
+ if (is_plugin_active($info['basename']) && !is_plugin_active($compatibility_addon)) {
152
+ $name = $info['title'];
153
+ $url = sprintf($this->addon_url, $slug);
154
+
155
+ OMGF_Admin_Notice::set_notice(sprintf(__("Your theme's framework, <strong>$name</strong>, uses unconventional methods to load Google Fonts. For OMGF to work properly with $name, a premium add-on <em>(starting at € 39, -)</em> is required. Click <a href='%s' target='_blank'>here</a> for more information.", $this->plugin_text_domain), $url), true, 'warning');
156
+ }
157
+ }
158
  }
159
 
160
  /**
201
 
202
  update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $fonts);
203
 
204
+ OMGF_Admin_Notice::set_notice(count($fonts) . ' ' . __('font styles found. Trim the list to your needs and click <strong>Download Fonts</strong>.', $this->plugin_text_domain));
205
  }
206
 
207
  /**
227
 
228
  update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $selected_fonts);
229
 
230
+ OMGF_Admin_Notice::set_notice(count($current_fonts) - count($selected_fonts) . ' ' . __('fonts removed from list and', $this->plugin_text_domain) . ' ' . count($to_be_preloaded) . ' ' . __('fonts set to preload. If you haven\'t already, you can now <strong>download</strong> the <strong>fonts</strong>. Otherwise, just (re-)<strong>generate</strong> the <strong>stylesheet</strong>.', $this->plugin_text_domain), false);
231
  }
232
 
233
  /**
257
 
258
  array_map('unlink', array_filter((array) glob(OMGF_FONTS_DIR . '/*')));
259
 
260
+ OMGF_Admin_Notice::set_notice(__('Cache directory successfully emptied.', $this->plugin_text_domain));
261
  } catch (\Exception $e) {
262
+ OMGF_Admin_Notice::set_notice(__('Something went wrong while emptying the cache directory: ', $this->plugin_text_domain) . $e->getMessage(), true, 'error', $e->getCode());
263
  }
264
  }
265
  }
includes/class-omgf.php CHANGED
@@ -73,7 +73,7 @@ class OMGF
73
  define('OMGF_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
74
  define('OMGF_FILENAME', 'fonts.css');
75
  define('OMGF_AUTO_DETECT_ENABLED', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, false)));
76
- define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH)) ?: '/cache/omgf-webfonts');
77
  define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI)) ?: '');
78
  define('OMGF_FORCE_SSL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_FORCE_SSL)));
79
  define('OMGF_RELATIVE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL)));
@@ -108,7 +108,7 @@ class OMGF
108
  }
109
 
110
  /**
111
- * @return OMGF_Admin_AutoDetect
112
  */
113
  public function do_auto_detect()
114
  {
73
  define('OMGF_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
74
  define('OMGF_FILENAME', 'fonts.css');
75
  define('OMGF_AUTO_DETECT_ENABLED', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, false)));
76
+ define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH)) ?: '/uploads/omgf');
77
  define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI)) ?: '');
78
  define('OMGF_FORCE_SSL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_FORCE_SSL)));
79
  define('OMGF_RELATIVE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL)));
108
  }
109
 
110
  /**
111
+ * @return OMGF_Admin_AutoDetect|void
112
  */
113
  public function do_auto_detect()
114
  {
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.5.0
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -41,7 +41,7 @@ Please keep in mind that, although I try to make the configuration of this plugi
41
 
42
  1. Upload the plugin files to the `/wp-content/plugins/host-webfonts-local` directory, or install the plugin through the WordPress plugins screen directly.
43
  1. Activate the plugin through the 'Plugins' screen in WordPress
44
- 1. Use the Settings -> Optimize Webfonts screen to configure the plugin
45
 
46
  For a more comprehensive guide for configuration, click [here](https://daan.dev/wordpress/host-google-fonts-locally/).
47
 
@@ -90,7 +90,7 @@ OMGF enqueues the stylesheet into WordPress' head. If the stylesheet isn't loade
90
  Yes, it does. When using subdomains, however, you might run into CORS related issues. To get around this, you should configure each site separately. Do the following:
91
 
92
  - Go to the site's own dashboard,
93
- - Change OMGF's cache directory (*Save webfonts to...*) to something unique, e.g. `/cache/site1/omgf`,
94
  - Click 'Save Changes',
95
  - If you haven't already, find the fonts you want to use,
96
  - Click 'Download Fonts' and wait for the process to finish,
@@ -108,6 +108,12 @@ N/A
108
 
109
  == Changelog ==
110
 
 
 
 
 
 
 
111
  = 3.5.0 =
112
  * Added Force SSL option, to force the usage of SSL while generating the stylesheet.
113
  * Added WP Rocket to list of Evil Plugins, because it empties the entire wp-content/cache folder instead of just its own files.
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.6.0
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
41
 
42
  1. Upload the plugin files to the `/wp-content/plugins/host-webfonts-local` directory, or install the plugin through the WordPress plugins screen directly.
43
  1. Activate the plugin through the 'Plugins' screen in WordPress
44
+ 1. Use the Settings -> Optimize Google Fonts screen to configure the plugin
45
 
46
  For a more comprehensive guide for configuration, click [here](https://daan.dev/wordpress/host-google-fonts-locally/).
47
 
90
  Yes, it does. When using subdomains, however, you might run into CORS related issues. To get around this, you should configure each site separately. Do the following:
91
 
92
  - Go to the site's own dashboard,
93
+ - Change OMGF's cache directory (*Save webfonts to...*) to something unique, e.g. `/uploads/site1/omgf`,
94
  - Click 'Save Changes',
95
  - If you haven't already, find the fonts you want to use,
96
  - Click 'Download Fonts' and wait for the process to finish,
108
 
109
  == Changelog ==
110
 
111
+ = 3.6.0 =
112
+ * OMGF now supports add-ons to extend its Auto Detect and Auto Removal feature.
113
+ * From now on, a notice containing a link to the required add-on will be thrown for known themes and frameworks which follow unconventional methods to include Google Fonts.
114
+ * This list now contains Thrive Themes and Redux Framework, but other themes (I'm researching Avada) will be added in the near future.
115
+ * Generated stylesheets and downloaded fonts are now be saved to the 'uploads/omgf' folder by default.
116
+
117
  = 3.5.0 =
118
  * Added Force SSL option, to force the usage of SSL while generating the stylesheet.
119
  * Added WP Rocket to list of Evil Plugins, because it empties the entire wp-content/cache folder instead of just its own files.
templates/admin/block-advanced-settings.phtml CHANGED
@@ -64,9 +64,9 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
64
  </label>
65
  </th>
66
  <td>
67
- <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>" placeholder="<?= __('e.g. /cache/omgf-webfonts', 'host-webfonts-local'); ?>" value="<?= OMGF_CACHE_PATH; ?>"/>
68
  <p class="description">
69
- <?php _e("The folder (inside <code>wp-content</code>) where font files should be stored. Give each site a unique value if you're using Multisite. Defaults to <code>/cache/omgf-webfonts</code>. After changing this setting, the folder will be created if it doesn't exist and existing files will be moved automatically.", 'host-webfonts-local'); ?>
70
  </p>
71
  </td>
72
  </tr>
@@ -77,7 +77,7 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
77
  </label>
78
  </th>
79
  <td>
80
- <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>" placeholder="<?= __('e.g. /app/cache/omgf-webfonts', 'host-webfonts-local'); ?>" value="<?= OMGF_CACHE_URI; ?>" />
81
  <p class="description">
82
  <?php _e('The relative path to serve font files from. Useful for when you\'re using security through obscurity plugins, such as WP Hide. If left empty, the cache directory specified above will be used.', 'host-webfonts-local'); ?>
83
  </p>
64
  </label>
65
  </th>
66
  <td>
67
+ <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>" placeholder="<?= __('e.g. /uploads/omgf', 'host-webfonts-local'); ?>" value="<?= OMGF_CACHE_PATH; ?>"/>
68
  <p class="description">
69
+ <?php _e("The folder (inside <code>wp-content</code>) where font files should be stored. Give each site a unique value if you're using Multisite. Defaults to <code>/uploads/omgf</code>. After changing this setting, the folder will be created if it doesn't exist and existing files will be moved automatically.", 'host-webfonts-local'); ?>
70
  </p>
71
  </td>
72
  </tr>
77
  </label>
78
  </th>
79
  <td>
80
+ <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>" placeholder="<?= __('e.g. /app/uploads/omgf', 'host-webfonts-local'); ?>" value="<?= OMGF_CACHE_URI; ?>" />
81
  <p class="description">
82
  <?php _e('The relative path to serve font files from. Useful for when you\'re using security through obscurity plugins, such as WP Hide. If left empty, the cache directory specified above will be used.', 'host-webfonts-local'); ?>
83
  </p>