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

Version Description

Updated Welcome-panel with WoOSH!-services. Preload can now be used for certain fonts only (also combined with Web Font Loader).

Download this release

Release Info

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

Code changes from version 2.4.1 to 2.5.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: 2.4.1
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
@@ -19,8 +19,8 @@ defined('ABSPATH') || exit;
19
  */
20
  define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
21
  define('OMGF_PLUGIN_FILE', __FILE__);
22
- define('OMGF_DB_VERSION', '2.2.2');
23
- define('OMGF_STATIC_VERSION', '2.4.0');
24
  define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
25
 
26
  /**
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: 2.5.0
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
19
  */
20
  define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
21
  define('OMGF_PLUGIN_FILE', __FILE__);
22
+ define('OMGF_DB_VERSION', '2.5.0');
23
+ define('OMGF_STATIC_VERSION', '2.5.0');
24
  define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
25
 
26
  /**
includes/ajax/class-download.php CHANGED
@@ -127,6 +127,7 @@ class OMGF_AJAX_Download extends OMGF_AJAX
127
  'font_weight' => sanitize_text_field($font['font-weight']),
128
  'font_style' => sanitize_text_field($font['font-style']),
129
  'local' => sanitize_text_field($font['local']),
 
130
  'downloaded' => 0,
131
  'url_ttf' => esc_url_raw($urlTtf),
132
  'url_woff' => esc_url_raw($urlWoff),
@@ -172,7 +173,7 @@ class OMGF_AJAX_Download extends OMGF_AJAX
172
  /**
173
  * We rewrite the local filename for easier debugging in the waterfall.
174
  */
175
- $filename = $font->font_family . '-' . $font->font_weight . '-' . $font->font_style . '-' . substr(basename($remoteFile), -10);
176
  $localFile = OMGF_UPLOAD_DIR . '/' . $filename;
177
 
178
  try {
127
  'font_weight' => sanitize_text_field($font['font-weight']),
128
  'font_style' => sanitize_text_field($font['font-style']),
129
  'local' => sanitize_text_field($font['local']),
130
+ 'preload' => sanitize_text_field($font['preload'] ?? null),
131
  'downloaded' => 0,
132
  'url_ttf' => esc_url_raw($urlTtf),
133
  'url_woff' => esc_url_raw($urlWoff),
173
  /**
174
  * We rewrite the local filename for easier debugging in the waterfall.
175
  */
176
+ $filename = sanitize_title_with_dashes($font->font_family) . '-' . $font->font_weight . '-' . $font->font_style . '-' . substr(basename($remoteFile), -10);
177
  $localFile = OMGF_UPLOAD_DIR . '/' . $filename;
178
 
179
  try {
includes/class-db.php CHANGED
@@ -54,6 +54,18 @@ class OMGF_DB
54
  }
55
  }
56
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  /**
58
  * @return array|\Exception
59
  */
54
  }
55
  }
56
 
57
+ /**
58
+ * @return array|Exception|object|null
59
+ */
60
+ public function get_preload_fonts()
61
+ {
62
+ try {
63
+ return $this->wpdb->get_results("SELECT * FROM " . OMGF_DB_TABLENAME . " WHERE preload = 1");
64
+ } catch(\Exception $e) {
65
+ return $e;
66
+ }
67
+ }
68
+
69
  /**
70
  * @return array|\Exception
71
  */
includes/class-omgf.php CHANGED
@@ -28,6 +28,7 @@ class OMGF
28
  if (is_admin()) {
29
  $this->do_settings();
30
  $this->add_ajax_hooks();
 
31
  }
32
 
33
  if (!is_admin()) {
@@ -35,7 +36,6 @@ class OMGF
35
  }
36
 
37
  // @formatter:off
38
- register_activation_hook(OMGF_PLUGIN_FILE, array($this, 'do_setup'));
39
  register_activation_hook(OMGF_PLUGIN_FILE, array($this, 'create_cache_dir'));
40
  register_deactivation_hook(OMGF_PLUGIN_FILE, array($this, 'dequeue_css_js'));
41
  // @formatter:on
28
  if (is_admin()) {
29
  $this->do_settings();
30
  $this->add_ajax_hooks();
31
+ add_action('plugin_loaded', array($this, 'do_setup'));
32
  }
33
 
34
  if (!is_admin()) {
36
  }
37
 
38
  // @formatter:off
 
39
  register_activation_hook(OMGF_PLUGIN_FILE, array($this, 'create_cache_dir'));
40
  register_deactivation_hook(OMGF_PLUGIN_FILE, array($this, 'dequeue_css_js'));
41
  // @formatter:on
includes/class-setup.php CHANGED
@@ -21,6 +21,8 @@ class OMGF_Setup
21
  /** @var QM_DB $wpdb */
22
  private $wpdb;
23
 
 
 
24
  /**
25
  * OMGF_Admin_Setup constructor.
26
  */
@@ -29,8 +31,11 @@ class OMGF_Setup
29
  global $wpdb;
30
 
31
  $this->wpdb = $wpdb;
 
32
 
33
- $this->run_db_updates();
 
 
34
  }
35
 
36
  /**
@@ -38,24 +43,28 @@ class OMGF_Setup
38
  */
39
  public function run_db_updates()
40
  {
41
- $currentVersion = get_option(OMGF_Admin_Settings::OMGF_SETTING_DB_VERSION) ?: get_option('caos_webfonts_db_version') ?: '1.0.0';
42
- if (version_compare($currentVersion, '1.6.1') < 0) {
43
  $this->create_webfonts_table();
44
  }
45
- if (version_compare($currentVersion, '1.7.0') < 0) {
46
  $this->create_subsets_table();
47
  }
48
- if (version_compare($currentVersion, '1.8.3') < 0) {
49
  $this->add_local_column();
50
  }
51
- if (version_compare($currentVersion, OMGF_DB_VERSION) < 0) {
52
  $this->rename_tables();
53
  $this->migrate_options();
54
  }
 
 
 
55
  }
56
 
57
  /**
58
  * Create the table where downloaded webfonts are registered.
 
 
59
  */
60
  private function create_webfonts_table()
61
  {
@@ -78,6 +87,8 @@ class OMGF_Setup
78
 
79
  /**
80
  * Creates the subsets table.
 
 
81
  */
82
  private function create_subsets_table()
83
  {
@@ -95,6 +106,8 @@ class OMGF_Setup
95
 
96
  /**
97
  * Adds 'local' column.
 
 
98
  */
99
  private function add_local_column()
100
  {
@@ -107,6 +120,8 @@ class OMGF_Setup
107
 
108
  /**
109
  * Delete options with old plugin names and migrate them to new names.
 
 
110
  */
111
  private function migrate_options()
112
  {
@@ -126,9 +141,12 @@ class OMGF_Setup
126
 
127
  /**
128
  * Rename tables using OMGF_DB_TABLENAME.
 
 
129
  */
130
  private function rename_tables()
131
  {
 
132
  $table = $this->wpdb->prefix . 'caos_webfonts';
133
  $subsets = $table . '_subsets';
134
  $sql = "ALTER TABLE $table RENAME TO " . OMGF_DB_TABLENAME;
@@ -140,6 +158,20 @@ class OMGF_Setup
140
  $this->set_db_version('2.2.2');
141
  }
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  /**
144
  * @param $value
145
  */
21
  /** @var QM_DB $wpdb */
22
  private $wpdb;
23
 
24
+ private $version;
25
+
26
  /**
27
  * OMGF_Admin_Setup constructor.
28
  */
31
  global $wpdb;
32
 
33
  $this->wpdb = $wpdb;
34
+ $this->version = get_option(OMGF_Admin_Settings::OMGF_SETTING_DB_VERSION) ?: get_option('caos_webfonts_db_version') ?: '1.0.0';
35
 
36
+ if (version_compare($this->version, OMGF_DB_VERSION) < 0) {
37
+ $this->run_db_updates();
38
+ }
39
  }
40
 
41
  /**
43
  */
44
  public function run_db_updates()
45
  {
46
+ if (version_compare($this->version, '1.6.1') < 0) {
 
47
  $this->create_webfonts_table();
48
  }
49
+ if (version_compare($this->version, '1.7.0') < 0) {
50
  $this->create_subsets_table();
51
  }
52
+ if (version_compare($this->version, '1.8.3') < 0) {
53
  $this->add_local_column();
54
  }
55
+ if (version_compare($this->version, '2.2.2') < 0) {
56
  $this->rename_tables();
57
  $this->migrate_options();
58
  }
59
+ if (version_compare($this->version, OMGF_DB_VERSION) < 0) {
60
+ $this->add_preload_column();
61
+ }
62
  }
63
 
64
  /**
65
  * Create the table where downloaded webfonts are registered.
66
+ *
67
+ * @since 1.6.1
68
  */
69
  private function create_webfonts_table()
70
  {
87
 
88
  /**
89
  * Creates the subsets table.
90
+ *
91
+ * @since 1.7.0
92
  */
93
  private function create_subsets_table()
94
  {
106
 
107
  /**
108
  * Adds 'local' column.
109
+ *
110
+ * @since 1.8.3
111
  */
112
  private function add_local_column()
113
  {
120
 
121
  /**
122
  * Delete options with old plugin names and migrate them to new names.
123
+ *
124
+ * @since 2.2.2
125
  */
126
  private function migrate_options()
127
  {
141
 
142
  /**
143
  * Rename tables using OMGF_DB_TABLENAME.
144
+ *
145
+ * @since 2.2.2
146
  */
147
  private function rename_tables()
148
  {
149
+ // Migrate table. DO NOT TOUCH!
150
  $table = $this->wpdb->prefix . 'caos_webfonts';
151
  $subsets = $table . '_subsets';
152
  $sql = "ALTER TABLE $table RENAME TO " . OMGF_DB_TABLENAME;
158
  $this->set_db_version('2.2.2');
159
  }
160
 
161
+ /**
162
+ * Adds preload column to OMGF_DB_TABLENAME.
163
+ *
164
+ * @since 2.5.0
165
+ */
166
+ private function add_preload_column()
167
+ {
168
+ $sql = "ALTER TABLE " . OMGF_DB_TABLENAME . " " .
169
+ "ADD COLUMN preload tinyint(1) DEFAULT 0 AFTER local;";
170
+ $this->wpdb->query($sql);
171
+
172
+ $this->set_db_version('2.5.0');
173
+ }
174
+
175
  /**
176
  * @param $value
177
  */
includes/frontend/class-functions.php CHANGED
@@ -20,6 +20,9 @@ class OMGF_Frontend_Functions
20
  {
21
  const OMGF_STYLE_HANDLE = 'omgf-fonts';
22
 
 
 
 
23
  /**
24
  * OMGF_Frontend_Functions constructor.
25
  */
@@ -36,27 +39,11 @@ class OMGF_Frontend_Functions
36
  if (!OMGF_WEB_FONT_LOADER) {
37
  add_action('init', array($this, 'is_preload_enabled'));
38
  }
39
- // @formatter:on
40
- }
41
 
42
- /**
43
- * Once the stylesheet is generated. We can enqueue it.
44
- */
45
- public function enqueue_stylesheet()
46
- {
47
- if (OMGF_WEB_FONT_LOADER) {
48
- $this->get_template('web-font-loader');
49
- } else {
50
- wp_enqueue_style(self::OMGF_STYLE_HANDLE, OMGF_UPLOAD_URL . '/' . OMGF_FILENAME, array(), (OMGF_REMOVE_VERSION ? null : OMGF_STATIC_VERSION));
51
- }
52
- }
53
-
54
- /**
55
- * @param $name
56
- */
57
- public function get_template($name)
58
- {
59
- include OMGF_PLUGIN_DIR . 'templates/frontend-' . $name . '.phtml';
60
  }
61
 
62
  /**
@@ -73,18 +60,6 @@ class OMGF_Frontend_Functions
73
  }
74
  }
75
 
76
- /**
77
- * Check if the Preload option is enabled.
78
- */
79
- public function is_preload_enabled()
80
- {
81
- if (OMGF_PRELOAD == 'on') {
82
- // @formatter:off
83
- add_action('wp_head', array($this, 'add_link_preload'), 1);
84
- // @formatter:on
85
- }
86
- }
87
-
88
  /**
89
  * Automatically dequeues any stylesheets loaded from fonts.gstatic.com or
90
  * fonts.googleapis.com. Also checks for stylesheets dependant on Google Fonts and
@@ -102,7 +77,7 @@ class OMGF_Frontend_Functions
102
  $registered, function ($contents) use ($fonts) {
103
  return !empty(array_intersect(array_keys($fonts), $contents->deps))
104
  && $contents->handle !== 'wp-block-editor';
105
- }
106
  );
107
 
108
  foreach ($fonts as $font) {
@@ -116,6 +91,11 @@ class OMGF_Frontend_Functions
116
  }
117
  }
118
 
 
 
 
 
 
119
  private function detect_registered_google_fonts($registered_styles)
120
  {
121
  return array_filter(
@@ -127,12 +107,44 @@ class OMGF_Frontend_Functions
127
  );
128
  }
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  /**
131
  * Prioritize the loading of fonts by adding a resource hint to the document head.
132
  *
133
  * Does not work with Web Font Loader enabled.
134
  */
135
- public function add_link_preload()
136
  {
137
  global $wp_styles;
138
 
@@ -162,4 +174,28 @@ class OMGF_Frontend_Functions
162
 
163
  update_option(OMGF_Admin_Settings::OMGF_SETTING_DETECTED_FONTS, json_encode($google_fonts_src));
164
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  }
20
  {
21
  const OMGF_STYLE_HANDLE = 'omgf-fonts';
22
 
23
+ /** @var OMGF_DB */
24
+ private $db;
25
+
26
  /**
27
  * OMGF_Frontend_Functions constructor.
28
  */
39
  if (!OMGF_WEB_FONT_LOADER) {
40
  add_action('init', array($this, 'is_preload_enabled'));
41
  }
 
 
42
 
43
+ $this->db = new OMGF_DB();
44
+ // Needs to be loaded before stylesheet.
45
+ add_action('wp_enqueue_scripts', array($this, 'preload_fonts'), 0);
46
+ // @formatter:on
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
 
49
  /**
60
  }
61
  }
62
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  /**
64
  * Automatically dequeues any stylesheets loaded from fonts.gstatic.com or
65
  * fonts.googleapis.com. Also checks for stylesheets dependant on Google Fonts and
77
  $registered, function ($contents) use ($fonts) {
78
  return !empty(array_intersect(array_keys($fonts), $contents->deps))
79
  && $contents->handle !== 'wp-block-editor';
80
+ }
81
  );
82
 
83
  foreach ($fonts as $font) {
91
  }
92
  }
93
 
94
+ /**
95
+ * @param $registered_styles
96
+ *
97
+ * @return array
98
+ */
99
  private function detect_registered_google_fonts($registered_styles)
100
  {
101
  return array_filter(
107
  );
108
  }
109
 
110
+ /**
111
+ * Once the stylesheet is generated. We can enqueue it.
112
+ */
113
+ public function enqueue_stylesheet()
114
+ {
115
+ if (OMGF_WEB_FONT_LOADER) {
116
+ $this->get_template('web-font-loader');
117
+ } else {
118
+ wp_enqueue_style(self::OMGF_STYLE_HANDLE, OMGF_UPLOAD_URL . '/' . OMGF_FILENAME, array(), (OMGF_REMOVE_VERSION ? null : OMGF_STATIC_VERSION));
119
+ }
120
+ }
121
+
122
+ /**
123
+ * @param $name
124
+ */
125
+ public function get_template($name)
126
+ {
127
+ include OMGF_PLUGIN_DIR . 'templates/frontend-' . $name . '.phtml';
128
+ }
129
+
130
+ /**
131
+ * Check if the Preload option is enabled.
132
+ */
133
+ public function is_preload_enabled()
134
+ {
135
+ if (OMGF_PRELOAD == 'on') {
136
+ // @formatter:off
137
+ add_action('wp_enqueue_scripts', array($this, 'add_stylesheet_preload'), 0);
138
+ // @formatter:on
139
+ }
140
+ }
141
+
142
  /**
143
  * Prioritize the loading of fonts by adding a resource hint to the document head.
144
  *
145
  * Does not work with Web Font Loader enabled.
146
  */
147
+ public function add_stylesheet_preload()
148
  {
149
  global $wp_styles;
150
 
174
 
175
  update_option(OMGF_Admin_Settings::OMGF_SETTING_DETECTED_FONTS, json_encode($google_fonts_src));
176
  }
177
+
178
+ /**
179
+ * Collect and render preload fonts in wp_head().
180
+ */
181
+ public function preload_fonts()
182
+ {
183
+ $preload_fonts = $this->db->get_preload_fonts();
184
+
185
+ if (!$preload_fonts) {
186
+ return;
187
+ }
188
+
189
+ foreach ($preload_fonts as $font) {
190
+ $font_urls[] = array_values(array_filter((array) $font, function ($properties) {
191
+ return strpos($properties, 'woff2') !== false;
192
+ }, ARRAY_FILTER_USE_KEY));
193
+ }
194
+
195
+ $urls = array_reduce($font_urls, 'array_merge', []);
196
+
197
+ foreach ($urls as $url) {
198
+ echo "<link rel='preload' href='$url' as='font' type='font/" . pathinfo($url, PATHINFO_EXTENSION) . "' crossorigin>\n";
199
+ }
200
+ }
201
  }
js/hwl-admin.js CHANGED
@@ -229,7 +229,7 @@ function hwlRenderAvailableFonts(results)
229
  fontWeight = variants[iii].fontWeight;
230
  fontStyle = variants[iii].fontStyle;
231
  fontLocal = variants[iii].local;
232
- renderedFonts[iii] = `<tr id="row-${font}" valign="top">
233
  <td>
234
  <input readonly type="text" value="${fontFamily}" name="caos_webfonts_array][${font}][font-family]" />
235
  </td>
@@ -239,6 +239,9 @@ function hwlRenderAvailableFonts(results)
239
  <td>
240
  <input readonly type="text" value="${fontWeight}" name="caos_webfonts_array][${font}][font-weight]" />
241
  </td>
 
 
 
242
  <td>
243
  <input type="hidden" value="${fontId}" name="caos_webfonts_array][${font}][id]" />
244
  <input type="hidden" value="${fontLocal}" name="caos_webfonts_array][${font}][local]" />
@@ -457,8 +460,8 @@ function hwlCleanQueue()
457
  action: 'omgf_ajax_clean_queue'
458
  },
459
  success: function() {
460
- jQuery('.caos-status-progress-percentage').html('0%')
461
- jQuery('#hwl-results, #hwl-subsets').empty()
462
  }
463
  })
464
  }
229
  fontWeight = variants[iii].fontWeight;
230
  fontStyle = variants[iii].fontStyle;
231
  fontLocal = variants[iii].local;
232
+ renderedFonts[iii] = `<tr id="row-${font}" valign="top" align="center">
233
  <td>
234
  <input readonly type="text" value="${fontFamily}" name="caos_webfonts_array][${font}][font-family]" />
235
  </td>
239
  <td>
240
  <input readonly type="text" value="${fontWeight}" name="caos_webfonts_array][${font}][font-weight]" />
241
  </td>
242
+ <td>
243
+ <input type="checkbox" value="1" name="caos_webfonts_array][${font}][preload]" />
244
+ </td>
245
  <td>
246
  <input type="hidden" value="${fontId}" name="caos_webfonts_array][${font}][id]" />
247
  <input type="hidden" value="${fontLocal}" name="caos_webfonts_array][${font}][local]" />
460
  action: 'omgf_ajax_clean_queue'
461
  },
462
  success: function() {
463
+ jQuery('.caos-status-progress-percentage').html('0%');
464
+ jQuery('#hwl-subsets, tbody[id^=hwl-section]').empty()
465
  }
466
  })
467
  }
readme.md CHANGED
@@ -28,8 +28,6 @@ This will *decrease your pageload times*, *leverage browser cache*, *minimize DN
28
 
29
  **Can I buy you a beer?**
30
 
31
- Yes, please! [Click here to buy me a beer](https://daan.dev/donate/ "Let's do shots!")!
32
-
33
  Visit the [FAQ at Wordpress.org](https://wordpress.org/plugins/host-webfonts-local/#faq)
34
 
35
  ## Support
28
 
29
  **Can I buy you a beer?**
30
 
 
 
31
  Visit the [FAQ at Wordpress.org](https://wordpress.org/plugins/host-webfonts-local/#faq)
32
 
33
  ## Support
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === OMGF | Host Google Fonts Locally ===
2
  Contributors: DaanvandenBergh
3
- Donate link: https://daan.dev/donate/
4
- Tags: google, fonts, host, save, local, locally, webfonts, update, minimize, external, requests, leverage, browser, cache
5
  Requires at least: 4.6
6
  Tested up to: 5.3
7
- Stable tag: 2.4.1
 
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -27,12 +27,12 @@ This will *decrease your pageload times*, *leverage browser cache*, *minimize DN
27
  - Change the caching path (where the fonts and stylesheet are saved) for increased compatibility with Multisite environments and Caching- and Security-plugins, such as WP Super Cache, Autoptimize and WordFence,
28
  - Serve your fonts from your CDN,
29
  - Enable Typekit's [Web Font Loader](https://github.com/typekit/webfontloader) to load your fonts asynchronously and further increase your Pagespeed Insights score (!),
 
30
  - Control font performance by adding font-display property,
31
  - Auto-generates the local source for webfonts,
32
- - Automatically remove any fonts loaded from fonts.gstatic.com or fonts.googleapis.com,
33
- - Prioritize fonts with rel='preload'.
34
 
35
- Please keep in mind that, although I try to make the configuration of this plugin as easy as possible, the concept of locally hosting a file or optimizing Google Fonts for *Pagespeed Insights* or *GT Metrix* has proven to be confusing for some people. If you're not sure of what your doing, please consult a SEO expert or Webdeveloper to help you with the configuration and optimization of your WordPress blog. Or feel free to [contact me](https://daan.dev/contact/) for a quote.
36
 
37
  == Installation ==
38
 
@@ -105,16 +105,16 @@ Repeat this for every site you want to use with OMGF. A new stylesheet, using th
105
 
106
  No, not yet. But I will definitely try to make it compatible in the future!
107
 
108
- = Can I buy you a beer? =
109
-
110
- Yes, please! [Click here to buy me a beer](https://daan.dev/donate/ "Let's do shots!")!
111
-
112
  == Screenshots ==
113
 
114
  N/A
115
 
116
  == Changelog ==
117
 
 
 
 
 
118
  = 2.4.1 =
119
  Filenames are now rewritten to be more informative and for easier debugging.
120
 
1
  === OMGF | Host Google Fonts Locally ===
2
  Contributors: DaanvandenBergh
3
+ Tags: google, fonts, preload, font-display, webfonts, subsets, remove, minimize, external, requests, leverage, browser, cache
 
4
  Requires at least: 4.6
5
  Tested up to: 5.3
6
+ Stable tag: 2.5.0
7
+ Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
27
  - Change the caching path (where the fonts and stylesheet are saved) for increased compatibility with Multisite environments and Caching- and Security-plugins, such as WP Super Cache, Autoptimize and WordFence,
28
  - Serve your fonts from your CDN,
29
  - Enable Typekit's [Web Font Loader](https://github.com/typekit/webfontloader) to load your fonts asynchronously and further increase your Pagespeed Insights score (!),
30
+ - Preload the entire stylesheet or just fonts loaded above-the-fold,
31
  - Control font performance by adding font-display property,
32
  - Auto-generates the local source for webfonts,
33
+ - Automatically remove any fonts loaded from fonts.gstatic.com or fonts.googleapis.com.
 
34
 
35
+ Please keep in mind that, although I try to make the configuration of this plugin as easy as possible, the concept of locally hosting a file or optimizing Google Fonts for *Pagespeed Insights* or *GT Metrix* has proven to be confusing for some people. If you're not sure of what your doing, please consult a SEO expert or Webdeveloper to help you with the configuration and optimization of your WordPress blog. Or [hire me to do it for you](https://woosh.dev/wordpress-services/omgf-expert-configuration/).
36
 
37
  == Installation ==
38
 
105
 
106
  No, not yet. But I will definitely try to make it compatible in the future!
107
 
 
 
 
 
108
  == Screenshots ==
109
 
110
  N/A
111
 
112
  == Changelog ==
113
 
114
+ = 2.5.0 =
115
+ Updated Welcome-panel with WoOSH!-services.
116
+ Preload can now be used for certain fonts only (also combined with Web Font Loader).
117
+
118
  = 2.4.1 =
119
  Filenames are now rewritten to be more informative and for easier debugging.
120
 
templates/admin/block-generate-stylesheet.phtml CHANGED
@@ -17,10 +17,10 @@
17
  defined('ABSPATH') || exit;
18
 
19
  $db = new OMGF_DB();
 
20
  ?>
21
  <div class="">
22
  <h3><?php _e('Generate Stylesheet', 'host-webfonts-local'); ?></h3>
23
- <p class="description">* Default WordPress font: enable only if you're sure that your theme uses it.</p>
24
  <div class="hwl-search-box">
25
  <input type="text" name="search-field"
26
  id="search-field" class="form-input-tip ui-autocomplete-input" placeholder="<?php _e('Search... (e.g. Roboto,Open Sans)', 'host-webfonts-local'); ?>"/>
@@ -28,6 +28,10 @@ $db = new OMGF_DB();
28
  id="search-btn" class="button button-primary button-hero" value="<?php _e('Search', 'host-webfonts-local'); ?>"/>
29
  <input type="button" onclick="hwlAutoDetectFonts()" name="detect-btn" id="detect-btn" class="button button-secondary button-hero" value="<?= __('Auto-detect', 'host-webfonts-local'); ?>" />
30
  </div>
 
 
 
 
31
  <table>
32
  <tr id="row" valign="top">
33
  <th align="left" colspan="3"><?php _e('Available subsets', 'host-webfonts-local'); ?></th>
@@ -41,12 +45,11 @@ $db = new OMGF_DB();
41
  <?php
42
  $availableSubsets = explode(',', $subsetFont->available_subsets);
43
  $selectedSubsets = explode(',', $subsetFont->selected_subsets);
44
- $defaultSubsets = array('open-sans', 'noto-serif');
45
  ?>
46
  <tr valign="top" id="<?= $subsetFont->subset_font; ?>">
47
  <td>
48
  <label>
49
- <input readonly type="text" class="hwl-subset-font-family" value="<?= $subsetFont->subset_family; ?> <?= in_array($subsetFont->subset_font, $defaultSubsets) ? '*' : ''; ?>" />
50
  </label>
51
  </td>
52
  <?php foreach ($availableSubsets as $availableSubset): ?>
@@ -68,13 +71,28 @@ $db = new OMGF_DB();
68
  <th align="left" colspan="3"><?php _e('Available fonts', 'host-webfonts-local'); ?></th>
69
  </tr>
70
  </table>
71
- <table align="left" id="hwl-results">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  <?php
73
  $savedFonts = $db->get_total_fonts();
74
  ?>
75
  <?php if ($savedFonts && $subsetFonts): ?>
76
  <?php foreach ($subsetFonts as $subsetFont): ?>
77
- <tbody id="hwl-section-<?= $subsetFont->subset_font; ?>">
78
  <?php
79
  $fonts = $db->get_fonts_by_family($subsetFont->subset_family);
80
  ?>
@@ -82,7 +100,7 @@ $db = new OMGF_DB();
82
  $fontId = $font->font_id;
83
  $arrayPath = "caos_webfonts_array][$fontId]";
84
  ?>
85
- <tr id="row-<?= $fontId; ?>" valign="top">
86
  <td>
87
  <input readonly type="text" value="<?= $font->font_family; ?>" name="<?= $arrayPath; ?>[font-family]"/>
88
  </td>
@@ -92,6 +110,9 @@ $db = new OMGF_DB();
92
  <td>
93
  <input readonly type="text" value="<?= $font->font_weight; ?>" name="<?= $arrayPath; ?>[font-weight]"/>
94
  </td>
 
 
 
95
  <td>
96
  <input type="hidden" value="<?= $fontId; ?>" name="<?= $arrayPath; ?>[id]"/>
97
  <input type="hidden" value="<?= $font->local; ?>" name="<?= $arrayPath; ?>[local]"/>
@@ -124,6 +145,11 @@ $db = new OMGF_DB();
124
 
125
  <table>
126
  <tbody>
 
 
 
 
 
127
  <tr valign="center" align="center">
128
  <td>
129
  <input type="button" onclick="hwlDownloadFonts()" name="save-btn"
17
  defined('ABSPATH') || exit;
18
 
19
  $db = new OMGF_DB();
20
+ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
21
  ?>
22
  <div class="">
23
  <h3><?php _e('Generate Stylesheet', 'host-webfonts-local'); ?></h3>
 
24
  <div class="hwl-search-box">
25
  <input type="text" name="search-field"
26
  id="search-field" class="form-input-tip ui-autocomplete-input" placeholder="<?php _e('Search... (e.g. Roboto,Open Sans)', 'host-webfonts-local'); ?>"/>
28
  id="search-btn" class="button button-primary button-hero" value="<?php _e('Search', 'host-webfonts-local'); ?>"/>
29
  <input type="button" onclick="hwlAutoDetectFonts()" name="detect-btn" id="detect-btn" class="button button-secondary button-hero" value="<?= __('Auto-detect', 'host-webfonts-local'); ?>" />
30
  </div>
31
+ <p class="description">
32
+ <?= __('Default WordPress fonts are left unchecked by default. Enable them only if you\'re sure that your theme uses them.', 'host-webfonts-local'); ?><br />
33
+ <a href="<?= OMGF_SITE_URL; ?>/how-to/find-wordpress-website-fonts/<?= $utmTags; ?>"><?= __('Which fonts does my theme use?', 'host-webfonts-local'); ?></a>
34
+ </p>
35
  <table>
36
  <tr id="row" valign="top">
37
  <th align="left" colspan="3"><?php _e('Available subsets', 'host-webfonts-local'); ?></th>
45
  <?php
46
  $availableSubsets = explode(',', $subsetFont->available_subsets);
47
  $selectedSubsets = explode(',', $subsetFont->selected_subsets);
 
48
  ?>
49
  <tr valign="top" id="<?= $subsetFont->subset_font; ?>">
50
  <td>
51
  <label>
52
+ <input readonly type="text" class="hwl-subset-font-family" value="<?= $subsetFont->subset_family; ?>" />
53
  </label>
54
  </td>
55
  <?php foreach ($availableSubsets as $availableSubset): ?>
71
  <th align="left" colspan="3"><?php _e('Available fonts', 'host-webfonts-local'); ?></th>
72
  </tr>
73
  </table>
74
+ <table id="hwl-results">
75
+ <thead align="center">
76
+ <th>
77
+ <?= __('Font Family', 'host-webfonts-local'); ?>
78
+ </th>
79
+ <th>
80
+ <?= __('Font Style', 'host-webfonts-local'); ?>
81
+ </th>
82
+ <th>
83
+ <?= __('Font Weight', 'host-webfonts-local'); ?>
84
+ </th>
85
+ <th>
86
+ <?= __('Preload? *', 'host-webfonts-local'); ?>
87
+ </th>
88
+ <th></th>
89
+ </thead>
90
  <?php
91
  $savedFonts = $db->get_total_fonts();
92
  ?>
93
  <?php if ($savedFonts && $subsetFonts): ?>
94
  <?php foreach ($subsetFonts as $subsetFont): ?>
95
+ <tbody align="center" id="hwl-section-<?= $subsetFont->subset_font; ?>">
96
  <?php
97
  $fonts = $db->get_fonts_by_family($subsetFont->subset_family);
98
  ?>
100
  $fontId = $font->font_id;
101
  $arrayPath = "caos_webfonts_array][$fontId]";
102
  ?>
103
+ <tr id="row-<?= $fontId; ?>" valign="top" align="center">
104
  <td>
105
  <input readonly type="text" value="<?= $font->font_family; ?>" name="<?= $arrayPath; ?>[font-family]"/>
106
  </td>
110
  <td>
111
  <input readonly type="text" value="<?= $font->font_weight; ?>" name="<?= $arrayPath; ?>[font-weight]"/>
112
  </td>
113
+ <td>
114
+ <input type="checkbox" value="1" <?= $font->preload == 1 ? 'checked' : ''; ?> name="<?= $arrayPath; ?>[preload]" />
115
+ </td>
116
  <td>
117
  <input type="hidden" value="<?= $fontId; ?>" name="<?= $arrayPath; ?>[id]"/>
118
  <input type="hidden" value="<?= $font->local; ?>" name="<?= $arrayPath; ?>[local]"/>
145
 
146
  <table>
147
  <tbody>
148
+ <tr>
149
+ <td colspan="5">
150
+ <span class="description">* <?= __('Only the <strong>woff2</strong> format is preloaded, since this format is widely supported by Modern Browsers which support preload.'); ?></span>
151
+ </td>
152
+ </tr>
153
  <tr valign="center" align="center">
154
  <td>
155
  <input type="button" onclick="hwlDownloadFonts()" name="save-btn"
templates/admin/block-welcome.phtml CHANGED
@@ -17,6 +17,7 @@
17
  defined('ABSPATH') || exit;
18
 
19
  $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=support_tab';
 
20
  ?>
21
  <div id="welcome-panel" class="welcome-panel">
22
  <div class="welcome-panel-content">
@@ -24,12 +25,18 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=support_tab';
24
  <?= get_plugin_data(OMGF_PLUGIN_FILE)['Description']; ?>
25
  </p>
26
  <div class="welcome-panel-column-container">
27
- <div class="welcome-panel-column" style="width: 32%;">
28
  <h3><?php _e( 'Quickstart', 'host-webfonts-local') ;?></h3>
29
  <ul>
30
- <li class="welcome-icon dashicons-before dashicons-admin-settings"><?php _e('Click Auto-detect and wait for the on-screen instructions', 'host-webfonts-local'); ?></li>
31
- <li class="welcome-icon dashicons-before dashicons-update"><?php _e('Click \'Download Fonts\' and wait for the download to complete', 'host-webfonts-local'); ?></li>
32
- <li class="welcome-icon dashicons-before dashicons-art"><?php _e('Click \'Generate Stylesheet\' and wait for the process to complete', 'host-webfonts-local'); ?></li>
 
 
 
 
 
 
33
  <li class="welcome-icon dashicons-before dashicons-media-text"><?php _e('The stylesheet is generated and added to your theme\'s header', 'host-webfonts-local'); ?></li>
34
  <li class="welcome-icon dashicons-before dashicons-editor-removeformatting"><?php _e('Check \'Remove Google Fonts\' and save your changes', 'host-webfonts-local'); ?></li>
35
  <li class="welcome-icon dashicons-before dashicons-smiley"><?php _e('Done!', 'host-webfonts-local'); ?></li>
@@ -38,31 +45,45 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=support_tab';
38
  <?= sprintf(__('%sClick here%s for a more comprehensive guide.', 'host-webfonts-local'), '<a target="_blank" href="' . OMGF_SITE_URL . '/wordpress/host-google-fonts-locally/' . $utmTags . '">', '</a>'); ?>
39
  </p>
40
  </div>
41
- <div class="welcome-panel-column" style="width: 32%;">
42
  <h3>
43
  <?php _e('Need Help?', 'host-webfonts-local'); ?>
44
  </h3>
45
  <p>
46
- <?= sprintf(__('If you\'re running into any issues, please make sure you\'ve read %sthe manual%s thoroughly. Visit the %sFAQ%s and %sSupport Forum%s to see if your question has already been answered. If not, ask a question on the Support Forum.', 'host-webfonts-local'), '<a href="' . OMGF_SITE_URL . '/wordpress/host-google-fonts-locally/' . $utmTags . '" target="_blank">', '</a>', '<a href="https://wordpress.org/plugins/host-webfonts-local/#description" target="_blank">', '</a>', '<a href="https://wordpress.org/support/plugin/host-webfonts-local">', '</a>'); ?>
47
-
 
 
 
 
 
 
 
48
  </p>
49
  </div>
50
- <div class="welcome-panel-column welcome-panel-last" style="width: 34%;">
51
  <h3>
52
- <?php _e('Support OMGF', 'host-webfonts-local'); ?>
53
  </h3>
54
  <p>
55
  <?= sprintf(__('I am convinced that knowledge should be free. That\'s why I will never charge you for the plugins I create and I will help you to succeed in your projects through the %stutorials%s on my blog.', 'host-webfonts-local'), '<a href="' . OMGF_SITE_URL . '/how-to/' . $utmTags . '" target="_blank">', '</a>'); ?>
56
  </p>
57
  <p>
58
- <?= sprintf(__('However, my time is just as valuable as yours. Consider supporting me by either %sdonating%s or leaving a %s5-star review%s on Wordpress.org.', 'host-webfonts-local'), '<a href="' . OMGF_SITE_URL . '/donate" target="_blank">', '</a>', '<a target="_blank" href="https://wordpress.org/support/plugin/host-webfonts-local/reviews/?rate=5#new-post">', '</a>'); ?>
 
 
 
59
  </p>
60
  <p>
61
- <a target="_blank" class="button button-primary button-hero" href="<?= OMGF_SITE_URL; ?>/donate/?utm_source=omgf&utm_medium=plugin&utm_campaign=donate_button"><span class="dashicons-before dashicons-heart"> <?php _e('Donate', 'host-webfonts-local'); ?></span></a>
62
  <a target="_blank" class="button button-secondary button-hero" href="https://wordpress.org/support/plugin/host-webfonts-local/reviews/?rate=5#new-post"><span class="dashicons-before dashicons-star-filled"> <?php _e('Review', 'host-webfonts-local'); ?></span></a>
63
- <a target="_blank" class="button button-secondary button-hero" href="https://twitter.com/Dan0sz"><span class="dashicons-before dashicons-twitter"> <?php _e('Follow', 'host-webfonts-local'); ?></span></a>
64
  </p>
65
  </div>
66
  </div>
67
  </div>
68
  </div>
 
 
 
 
 
17
  defined('ABSPATH') || exit;
18
 
19
  $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=support_tab';
20
+ $tweetUrl = 'https://twitter.com/intent/tweet?text=I+just+optimized+my+Google+Fonts+with+OMGF+for+@WordPress!+Try+it+for+yourself:&via=Dan0sz&hashtags=GoogleFonts,WordPress,Pagespeed,Insights&url=https://wordpress.org/plugins/host-webfonts-local/';
21
  ?>
22
  <div id="welcome-panel" class="welcome-panel">
23
  <div class="welcome-panel-content">
25
  <?= get_plugin_data(OMGF_PLUGIN_FILE)['Description']; ?>
26
  </p>
27
  <div class="welcome-panel-column-container">
28
+ <div class="welcome-panel-column" style="width: 31%; margin-right: 15px;">
29
  <h3><?php _e( 'Quickstart', 'host-webfonts-local') ;?></h3>
30
  <ul>
31
+ <li class="welcome-icon dashicons-before dashicons-admin-settings">
32
+ <?= sprintf(__('Click %sAuto-detect%s and wait for the on-screen instructions', 'host-webfonts-local'), '<a href="javascript: void(0);" onclick="hwlAutoDetectFonts();">', '</a>'); ?>
33
+ </li>
34
+ <li class="welcome-icon dashicons-before dashicons-update">
35
+ <?= sprintf(__('Click %sDownload Fonts%s and wait for the download to complete', 'host-webfonts-local'), '<a href="javascript: void(0);" onclick="hwlDownloadFonts();">', '</a>'); ?>
36
+ </li>
37
+ <li class="welcome-icon dashicons-before dashicons-art">
38
+ <?= sprintf(__('Click %sGenerate Stylesheet%s and wait for the process to complete', 'host-webfonts-local'), '<a href="javascript: void(0);" onclick="hwlGenerateStylesheet();">', '</a>'); ?>
39
+ </li>
40
  <li class="welcome-icon dashicons-before dashicons-media-text"><?php _e('The stylesheet is generated and added to your theme\'s header', 'host-webfonts-local'); ?></li>
41
  <li class="welcome-icon dashicons-before dashicons-editor-removeformatting"><?php _e('Check \'Remove Google Fonts\' and save your changes', 'host-webfonts-local'); ?></li>
42
  <li class="welcome-icon dashicons-before dashicons-smiley"><?php _e('Done!', 'host-webfonts-local'); ?></li>
45
  <?= sprintf(__('%sClick here%s for a more comprehensive guide.', 'host-webfonts-local'), '<a target="_blank" href="' . OMGF_SITE_URL . '/wordpress/host-google-fonts-locally/' . $utmTags . '">', '</a>'); ?>
46
  </p>
47
  </div>
48
+ <div class="welcome-panel-column" style="width: 31%; margin-right: 15px;">
49
  <h3>
50
  <?php _e('Need Help?', 'host-webfonts-local'); ?>
51
  </h3>
52
  <p>
53
+ <?= sprintf(__('Visit the %sFAQ%s and %sSupport Forum%s to see if your question has already been answered. If not, ask a question on the Support Forum.', 'host-webfonts-local'), '<a href="' . OMGF_SITE_URL . '/wordpress/host-google-fonts-locally/' . $utmTags . '" target="_blank">', '</a>', '<a href="https://wordpress.org/plugins/host-webfonts-local/#description" target="_blank">', '</a>', '<a href="https://wordpress.org/support/plugin/host-webfonts-local">', '</a>'); ?>
54
+ </p>
55
+ <hr/>
56
+ <h3><span class="dashicons dashicons-dashboard"></span> <?php _e('Make WordPress <em>Faster</em> Than Superman', 'host-webfonts-local'); ?></h3>
57
+ <p>
58
+ <?= __('Superman can reach the other side of the world in <strong>3 seconds</strong>. Google wants your website to do it <strong>faster</strong>. Let\'s give Google a run for its money.', 'host-webfonts-local'); ?>
59
+ </p>
60
+ <p>
61
+ <a target="_blank" class="button button-primary button-hero" href="https://woosh.dev/wordpress-services/<?= $utmTags; ?>"><span class="dashicons dashicons-thumbs-up"></span> <?= __('Hire me', 'host-webfonts-local'); ?></a> <span><em>(<?= __('Starting at € 99,-', 'host-analyticsjs-local'); ?>)</em></span>
62
  </p>
63
  </div>
64
+ <div class="welcome-panel-column welcome-panel-last" style="width: 33%;">
65
  <h3>
66
+ <?php _e('Support OMGF by Spreading the Word!', 'host-webfonts-local'); ?>
67
  </h3>
68
  <p>
69
  <?= sprintf(__('I am convinced that knowledge should be free. That\'s why I will never charge you for the plugins I create and I will help you to succeed in your projects through the %stutorials%s on my blog.', 'host-webfonts-local'), '<a href="' . OMGF_SITE_URL . '/how-to/' . $utmTags . '" target="_blank">', '</a>'); ?>
70
  </p>
71
  <p>
72
+ <?= __('But that doesn\'t mean there\'s nothing you can do to show your support! :)', 'host-webfonts-local'); ?>
73
+ </p>
74
+ <p>
75
+ <?= sprintf(__('Please help me spread the word by leaving a %s5-star review%s on Wordpress.org or sending a %sTweet%s about OMGF.', 'host-webfonts-local'), '<a target="_blank" href="https://wordpress.org/support/plugin/host-webfonts-local/reviews/?rate=5#new-post">', '</a>', "<a href='$tweetUrl'>", '</a>'); ?>
76
  </p>
77
  <p>
 
78
  <a target="_blank" class="button button-secondary button-hero" href="https://wordpress.org/support/plugin/host-webfonts-local/reviews/?rate=5#new-post"><span class="dashicons-before dashicons-star-filled"> <?php _e('Review', 'host-webfonts-local'); ?></span></a>
79
+ <a target="_blank" class="button button-secondary button-hero" href="<?= $tweetUrl; ?>"><span class="dashicons-before dashicons-twitter"> <?php _e('Tweet', 'host-webfonts-local'); ?></span></a>
80
  </p>
81
  </div>
82
  </div>
83
  </div>
84
  </div>
85
+ <style>
86
+ h3 > .dashicons {
87
+ line-height: 1.4;
88
+ }
89
+ </style>