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

Version Description

Added experimental option for preload resource hint.

Download this release

Release Info

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

Code changes from version 1.5.7 to 1.6.0

host-webfonts-local.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: https://dev.daanvandenbergh.com/wordpress-plugins/host-google-fonts-locally
5
  * Description: Automagically save the fonts you want to use inside your content-folder, generate a
6
  * stylesheet for them and enqueue it in your theme's header.
7
- * Version: 1.5.7
8
  * Author: Daan van den Bergh
9
  * Author URI: https://dev.daanvandenbergh.com
10
  * License: GPL2v2 or later
@@ -30,7 +30,11 @@ define('CAOS_WEBFONTS_CURRENT_BLOG_ID', get_current_blog_id());
30
  define('CAOS_WEBFONTS_UPLOAD_DIR', WP_CONTENT_DIR . CAOS_WEBFONTS_CACHE_DIR);
31
  define('CAOS_WEBFONTS_UPLOAD_URL', get_site_url(CAOS_WEBFONTS_CURRENT_BLOG_ID, hwlGetContentDirName() . CAOS_WEBFONTS_CACHE_DIR));
32
  define('CAOS_WEBFONTS_DISPLAY_OPTION', esc_attr(get_option('caos_webfonts_display_option')) ?: 'auto');
 
33
 
 
 
 
34
  function hwlRegisterSettings() {
35
  register_setting('caos-webfonts-basic-settings',
36
  'caos_webfonts_cache_dir'
@@ -38,6 +42,9 @@ function hwlRegisterSettings() {
38
  register_setting('caos-webfonts-basic-settings',
39
  'caos_webfonts_display_option'
40
  );
 
 
 
41
  }
42
 
43
  /**
@@ -315,8 +322,7 @@ add_action('wp_ajax_hwlAjaxDownloadFonts', 'hwlAjaxDownloadFonts');
315
  function hwlEnqueueStylesheet() {
316
  $stylesheet = CAOS_WEBFONTS_UPLOAD_DIR . '/' . CAOS_WEBFONTS_FILENAME;
317
  if (file_exists($stylesheet)) {
318
- wp_register_style('hwl-style', CAOS_WEBFONTS_UPLOAD_URL . '/' . CAOS_WEBFONTS_FILENAME);
319
- wp_enqueue_style('hwl-style');
320
  }
321
  }
322
  add_action('wp_enqueue_scripts', 'hwlEnqueueStylesheet');
@@ -341,3 +347,23 @@ function hwlDequeueJsCss() {
341
  wp_dequeue_style('hwl-style');
342
  }
343
  register_deactivation_hook(__FILE__, 'hwlDequeueJsCss');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  * Plugin URI: https://dev.daanvandenbergh.com/wordpress-plugins/host-google-fonts-locally
5
  * Description: Automagically save the fonts you want to use inside your content-folder, generate a
6
  * stylesheet for them and enqueue it in your theme's header.
7
+ * Version: 1.6.0
8
  * Author: Daan van den Bergh
9
  * Author URI: https://dev.daanvandenbergh.com
10
  * License: GPL2v2 or later
30
  define('CAOS_WEBFONTS_UPLOAD_DIR', WP_CONTENT_DIR . CAOS_WEBFONTS_CACHE_DIR);
31
  define('CAOS_WEBFONTS_UPLOAD_URL', get_site_url(CAOS_WEBFONTS_CURRENT_BLOG_ID, hwlGetContentDirName() . CAOS_WEBFONTS_CACHE_DIR));
32
  define('CAOS_WEBFONTS_DISPLAY_OPTION', esc_attr(get_option('caos_webfonts_display_option')) ?: 'auto');
33
+ define('CAOS_WEBFONTS_PRELOAD', esc_attr(get_option('caos_webfonts_preload')));
34
 
35
+ /**
36
+ * Register settings
37
+ */
38
  function hwlRegisterSettings() {
39
  register_setting('caos-webfonts-basic-settings',
40
  'caos_webfonts_cache_dir'
42
  register_setting('caos-webfonts-basic-settings',
43
  'caos_webfonts_display_option'
44
  );
45
+ register_setting('caos-webfonts-basic-settings',
46
+ 'caos_webfonts_preload'
47
+ );
48
  }
49
 
50
  /**
322
  function hwlEnqueueStylesheet() {
323
  $stylesheet = CAOS_WEBFONTS_UPLOAD_DIR . '/' . CAOS_WEBFONTS_FILENAME;
324
  if (file_exists($stylesheet)) {
325
+ wp_enqueue_style('hwl-style', CAOS_WEBFONTS_UPLOAD_URL . '/' . CAOS_WEBFONTS_FILENAME, array(), CAOS_WEBFONTS_STATIC_VERSION);
 
326
  }
327
  }
328
  add_action('wp_enqueue_scripts', 'hwlEnqueueStylesheet');
347
  wp_dequeue_style('hwl-style');
348
  }
349
  register_deactivation_hook(__FILE__, 'hwlDequeueJsCss');
350
+
351
+ /**
352
+ * Prioritize the loading of fonts by adding a resource hint to the document head.
353
+ */
354
+ function hwlAddLinkPreload() {
355
+ global $wp_styles;
356
+
357
+ $handle = 'hwl-style';
358
+ $sstyle = $wp_styles->registered[$handle];
359
+
360
+ $source = $sstyle->src . ($sstyle->ver ? "?ver={$sstyle->ver}" : "");
361
+ echo "<link rel='preload' href='{$source}' as='style' />\n";
362
+ }
363
+
364
+ function hwlIsPreloadEnabled() {
365
+ if (CAOS_WEBFONTS_PRELOAD == 'on') {
366
+ add_action('wp_head', 'hwlAddLinkPreload', 1);
367
+ }
368
+ }
369
+ add_action('init', 'hwlIsPreloadEnabled');
includes/caos-webfonts-basic-settings.php CHANGED
@@ -13,7 +13,9 @@ if (!defined( 'ABSPATH')) exit;
13
  <h3><?php _e('Basic Settings'); ?></h3>
14
  <table class="form-table">
15
  <tr valign="top">
16
- <th scope="row"><?php _e('Save webfonts to...', 'host-webfonts-local'); ?></th>
 
 
17
  <td>
18
  <input class="caos_webfonts_cache_dir" type="text" name="caos_webfonts_cache_dir" placeholder="e.g. /cache/caos-webfonts" value="<?php echo CAOS_WEBFONTS_CACHE_DIR; ?>" />
19
  <p class="description">
@@ -25,13 +27,11 @@ if (!defined( 'ABSPATH')) exit;
25
  <th scope="row"><?php _e('Font-display option', 'host-webfonts-local'); ?></th>
26
  <td>
27
  <?php $fontDisplay = hwlFontDisplayOptions(); ?>
28
- <label>
29
- <select name="caos_webfonts_display_option">
30
- <?php foreach ($fontDisplay as $label => $value): ?>
31
- <option value="<?php echo $value; ?>" <?php echo $value == CAOS_WEBFONTS_DISPLAY_OPTION ? 'selected' : ''; ?>><?php _e($label, 'host-webfonts-local'); ?></option>
32
- <?php endforeach; ?>
33
- </select>
34
- </label>
35
  <br/>
36
  <p class="description">
37
  <?php _e('Select which font-display strategy to use. Defaults to \'Auto\'.', 'host-webfonts-local'); ?>
@@ -39,5 +39,18 @@ if (!defined( 'ABSPATH')) exit;
39
  </p>
40
  </td>
41
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  </table>
43
  </div>
13
  <h3><?php _e('Basic Settings'); ?></h3>
14
  <table class="form-table">
15
  <tr valign="top">
16
+ <th scope="row">
17
+ <label><?php _e('Save webfonts to...', 'host-webfonts-local'); ?></label>
18
+ </th>
19
  <td>
20
  <input class="caos_webfonts_cache_dir" type="text" name="caos_webfonts_cache_dir" placeholder="e.g. /cache/caos-webfonts" value="<?php echo CAOS_WEBFONTS_CACHE_DIR; ?>" />
21
  <p class="description">
27
  <th scope="row"><?php _e('Font-display option', 'host-webfonts-local'); ?></th>
28
  <td>
29
  <?php $fontDisplay = hwlFontDisplayOptions(); ?>
30
+ <select name="caos_webfonts_display_option">
31
+ <?php foreach ($fontDisplay as $label => $value): ?>
32
+ <option value="<?php echo $value; ?>" <?php echo $value == CAOS_WEBFONTS_DISPLAY_OPTION ? 'selected' : ''; ?>><?php _e($label, 'host-webfonts-local'); ?></option>
33
+ <?php endforeach; ?>
34
+ </select>
 
 
35
  <br/>
36
  <p class="description">
37
  <?php _e('Select which font-display strategy to use. Defaults to \'Auto\'.', 'host-webfonts-local'); ?>
39
  </p>
40
  </td>
41
  </tr>
42
+ <tr valign="top">
43
+ <th scope="row">
44
+ <label>
45
+ <?php _e('Enable preload for stylesheet (experimental)', 'host-webfonts-local'); ?>
46
+ </label>
47
+ </th>
48
+ <td>
49
+ <input class="caos_webfonts_preload" type="checkbox" name="caos_webfonts_preload" <?php echo CAOS_WEBFONTS_PRELOAD == 'on' ? 'checked = "checked"' : ''; ?> />
50
+ <p class="description">
51
+ <?php _e('If you\'re using a plugin (such as Autoptimize) to load stylesheets in the footer, enable this to preload the fonts.', 'host-webfonts-local'); ?> <a target="_blank" href="https://developers.google.com/web/fundamentals/performance/resource-prioritization#preload"><?php _e('Read more', 'host-webfonts-local'); ?></a>
52
+ </p>
53
+ </td>
54
+ </tr>
55
  </table>
56
  </div>
js/hwl-admin.js CHANGED
@@ -180,7 +180,6 @@ function hwlGetDownloadStatus()
180
  downloaded = response.downloaded;
181
  total = response.total;
182
  progress = (100 / total) * downloaded;
183
- console.log("[" + progress + "] Downloaded " + downloaded + " of " + total + ".")
184
  hwlUpdateStatusBar(progress);
185
  }
186
  })
180
  downloaded = response.downloaded;
181
  total = response.total;
182
  progress = (100 / total) * downloaded;
 
183
  hwlUpdateStatusBar(progress);
184
  }
185
  })
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://dev.daanvandenbergh.com/donate/
4
  Tags: update, host, save, local, locally, google, fonts, webfonts, minimize, external, requests, leverage, browser, cache
5
  Requires at least: 4.5
6
  Tested up to: 5.0
7
- Stable tag: 1.5.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -68,6 +68,9 @@ N/A
68
 
69
  == Changelog ==
70
 
 
 
 
71
  = 1.5.7 =
72
  Replaced download counter for progress-bar. Refactored logic for AJAX-requests for better
73
  performance.
4
  Tags: update, host, save, local, locally, google, fonts, webfonts, minimize, external, requests, leverage, browser, cache
5
  Requires at least: 4.5
6
  Tested up to: 5.0
7
+ Stable tag: 1.6.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
68
 
69
  == Changelog ==
70
 
71
+ = 1.6.0 =
72
+ Added experimental option for preload resource hint.
73
+
74
  = 1.5.7 =
75
  Replaced download counter for progress-bar. Refactored logic for AJAX-requests for better
76
  performance.