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

Version Description

| December 8th, 2020 = * Cache keys are now fixed values instead of dynamically generated. This fixes the bug where preloads wouldn't load properly when combined with unloaded fonts of the same stylesheet. * IMPORTANT: To fix any bugs with preloads/unloads, emptying the cache directory is required. * Cleaned up the sidebar and added a notification to reassure people that no features were moved from Free to Pro after upgrading to v4. * Advanced Processing can now be disabled even when OMGF Pro is active. Before it was always on (accidentally). * When preload is enabled for a font style, its associated unload checkbox is disabled and vice versa. * Minor fixes, increased usability and optimizations.

Download this release

Release Info

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

Code changes from version 4.2.3 to 4.2.4

assets/js/omgf-admin.js CHANGED
@@ -13,18 +13,22 @@
13
  * @url : https://daan.dev
14
  * * * * * * * * * * * * * * * * * * * */
15
 
16
- jQuery(document).ready(function($) {
17
  var omgf_admin = {
18
- empty_cache_directory_xhr : false,
19
- optimize_xhr : false,
 
20
 
21
  /**
22
  * Initialize all on click events.
23
  */
24
- init : function() {
25
  // Settings
26
  $('input[name="omgf_optimization_mode"]').on('click', this.toggle_optimization_mode_content);
27
- $('tbody input.unload').on('change', this.unload_stylesheets);
 
 
 
28
 
29
  // Buttons
30
  $('.omgf-empty').on('click', this.empty_cache_directory);
@@ -34,7 +38,7 @@ jQuery(document).ready(function($) {
34
  /**
35
  *
36
  */
37
- toggle_optimization_mode_content : function() {
38
  if (this.value == 'manual') {
39
  $('.omgf-optimize-fonts-manual').show();
40
  $('.omgf-optimize-fonts-automatic').hide();
@@ -43,17 +47,17 @@ jQuery(document).ready(function($) {
43
  $('.omgf-optimize-fonts-manual').hide();
44
  }
45
  },
46
-
47
  /**
48
  * Populates the omgf_unload_stylesheets hidden field.
49
  */
50
- unload_stylesheets : function() {
51
- var handle = $(this).closest('tbody');
52
- var id = handle[0].id;
53
- var checked = $('tbody' + '#' + id + ' input.unload:checked').length;
54
- var total = $('tbody' + '#' + id + ' input.unload').length;
55
  var unloaded_stylesheets_option = $('#omgf_unload_stylesheets');
56
- var unloaded_stylesheets = unloaded_stylesheets_option.val().split(',');
57
 
58
  if (checked === total) {
59
  if (unloaded_stylesheets.indexOf(id) === -1) {
@@ -66,50 +70,143 @@ jQuery(document).ready(function($) {
66
  } else {
67
  position = unloaded_stylesheets.indexOf(id);
68
 
69
- if ( ~position ) unloaded_stylesheets.splice(position, 1);
70
 
71
  unloaded_stylesheets_option.val(unloaded_stylesheets);
72
  }
73
  },
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  /**
76
  * Empty queue, db and cache directory.
77
  */
78
- empty_cache_directory : function() {
79
  if (omgf_admin.empty_cache_directory_xhr) {
80
  omgf_admin.empty_cache_directory_xhr.abort();
81
  }
82
 
83
  omgf_admin.empty_cache_directory_xhr = $.ajax({
84
- type : 'POST',
85
- url : ajaxurl,
86
- data : {
87
- action : 'omgf_ajax_empty_dir'
88
  },
89
- beforeSend : function() {
90
  omgf_admin.show_loader();
91
  },
92
- complete : function() {
93
  location.reload();
94
  }
95
  });
96
  },
97
 
98
- show_loader_before_submit : function(e) {
99
  omgf_admin.show_loader();
100
  },
101
 
102
  /**
103
  *
104
  */
105
- show_loader : function() {
106
  $('#wpcontent').append('<div class="omgf-loading"><span class="spinner is-active"></span></div>');
107
  }
108
  };
109
 
110
  omgf_admin.init();
111
 
112
- $('#omgf_relative_url').click(function() {
113
  if (this.checked === true) {
114
  $('#omgf_cdn_url').prop('disabled', true);
115
  } else {
13
  * @url : https://daan.dev
14
  * * * * * * * * * * * * * * * * * * * */
15
 
16
+ jQuery(document).ready(function ($) {
17
  var omgf_admin = {
18
+ empty_cache_directory_xhr: false,
19
+ optimize_xhr: false,
20
+ cache_prefix: '-ul-',
21
 
22
  /**
23
  * Initialize all on click events.
24
  */
25
+ init: function () {
26
  // Settings
27
  $('input[name="omgf_optimization_mode"]').on('click', this.toggle_optimization_mode_content);
28
+ $('.omgf-optimize-fonts-manage .unload').on('change', this.unload_stylesheets);
29
+ $('.omgf-optimize-fonts-manage .unload').on('change', this.generate_cache_key);
30
+ $('.omgf-optimize-fonts-manage .unload').on('change', this.toggle_preload);
31
+ $('.omgf-optimize-fonts-manage .preload').on('change', this.toggle_unload);
32
 
33
  // Buttons
34
  $('.omgf-empty').on('click', this.empty_cache_directory);
38
  /**
39
  *
40
  */
41
+ toggle_optimization_mode_content: function () {
42
  if (this.value == 'manual') {
43
  $('.omgf-optimize-fonts-manual').show();
44
  $('.omgf-optimize-fonts-automatic').hide();
47
  $('.omgf-optimize-fonts-manual').hide();
48
  }
49
  },
50
+
51
  /**
52
  * Populates the omgf_unload_stylesheets hidden field.
53
  */
54
+ unload_stylesheets: function () {
55
+ var handle = $(this).closest('tbody');
56
+ var id = handle[0].id;
57
+ var checked = $('tbody' + '#' + id + ' input.unload:checked').length;
58
+ var total = $('tbody' + '#' + id + ' input.unload').length;
59
  var unloaded_stylesheets_option = $('#omgf_unload_stylesheets');
60
+ var unloaded_stylesheets = unloaded_stylesheets_option.val().split(',');
61
 
62
  if (checked === total) {
63
  if (unloaded_stylesheets.indexOf(id) === -1) {
70
  } else {
71
  position = unloaded_stylesheets.indexOf(id);
72
 
73
+ if (~position) unloaded_stylesheets.splice(position, 1);
74
 
75
  unloaded_stylesheets_option.val(unloaded_stylesheets);
76
  }
77
  },
78
 
79
+ /**
80
+ * Generate a new cache key upon each unload change.
81
+ */
82
+ generate_cache_key: function () {
83
+ var current_handle = $(this).data('handle'),
84
+ cache_keys_input = $('#omgf_cache_keys'),
85
+ cache_keys = cache_keys_input.val().split(','),
86
+ checked = $('#' + current_handle + ' input.unload:checked').length,
87
+ total = $('#' + current_handle + ' input.unload').length,
88
+ cache_key_index = cache_keys.findIndex((key, index) => {
89
+ if (key.indexOf(current_handle) !== -1) {
90
+ return true;
91
+ }
92
+ }),
93
+ no_cache_key = false;
94
+
95
+ /**
96
+ * If no or all boxes are checked, (re-)set cache key to default (without random string).
97
+ */
98
+ if (checked === 0 || checked === total) {
99
+ cache_keys[cache_key_index] = current_handle;
100
+
101
+ no_cache_key = true;
102
+ }
103
+
104
+ if (no_cache_key === true) {
105
+ cache_keys_input.val(cache_keys.join());
106
+
107
+ return;
108
+ }
109
+
110
+ /**
111
+ * Generate a unique cache key if some of this stylesheet's fonts are unloaded.
112
+ */
113
+ if (cache_key_index !== -1) {
114
+ var current_cache_key = cache_keys[cache_key_index];
115
+
116
+ var cache_key = omgf_admin.cache_prefix + Math.random().toString(36).substring(2, 7);
117
+
118
+ if (current_cache_key.indexOf(omgf_admin.cache_prefix) !== -1) {
119
+ var parts = current_cache_key.split(omgf_admin.cache_prefix),
120
+ last_part = omgf_admin.get_last_element_index(parts);
121
+ parts[last_part] = Math.random().toString(36).substring(2, 7);
122
+ current_cache_key = parts[0];
123
+ cache_key = omgf_admin.cache_prefix + parts[last_part];
124
+ }
125
+
126
+ cache_keys[cache_key_index] = current_cache_key + cache_key;
127
+ }
128
+
129
+ cache_keys_input.val(cache_keys.join());
130
+ },
131
+
132
+ /**
133
+ * Toggle preload option associated with this unload option.
134
+ */
135
+ toggle_preload: function () {
136
+ omgf_admin.toggle(this, 'preload');
137
+ },
138
+
139
+ /**
140
+ * Toggle unload option associated with the current preload option.
141
+ */
142
+ toggle_unload: function () {
143
+ omgf_admin.toggle(this, 'unload');
144
+ },
145
+
146
+ /**
147
+ * Toggle a checkbox.
148
+ *
149
+ * @param elem
150
+ * @param option
151
+ */
152
+ toggle: function (elem, option) {
153
+ var this_option = $(elem);
154
+ var other_option = $('.' + option + '-' + this_option.data('handle') + '-' + this_option.data('font-id') + '-' + this_option.val() + ' .' + option);
155
+
156
+ if (elem.checked) {
157
+ other_option.attr('disabled', true);
158
+ } else {
159
+ other_option.attr('disabled', false);
160
+ }
161
+ },
162
+
163
+ /**
164
+ *
165
+ * @param array
166
+ * @returns {number}
167
+ */
168
+ get_last_element_index: function (array) {
169
+ return array.length - 1;
170
+ },
171
+
172
  /**
173
  * Empty queue, db and cache directory.
174
  */
175
+ empty_cache_directory: function () {
176
  if (omgf_admin.empty_cache_directory_xhr) {
177
  omgf_admin.empty_cache_directory_xhr.abort();
178
  }
179
 
180
  omgf_admin.empty_cache_directory_xhr = $.ajax({
181
+ type: 'POST',
182
+ url: ajaxurl,
183
+ data: {
184
+ action: 'omgf_ajax_empty_dir'
185
  },
186
+ beforeSend: function () {
187
  omgf_admin.show_loader();
188
  },
189
+ complete: function () {
190
  location.reload();
191
  }
192
  });
193
  },
194
 
195
+ show_loader_before_submit: function (e) {
196
  omgf_admin.show_loader();
197
  },
198
 
199
  /**
200
  *
201
  */
202
+ show_loader: function () {
203
  $('#wpcontent').append('<div class="omgf-loading"><span class="spinner is-active"></span></div>');
204
  }
205
  };
206
 
207
  omgf_admin.init();
208
 
209
+ $('#omgf_relative_url').click(function () {
210
  if (this.checked === true) {
211
  $('#omgf_cdn_url').prop('disabled', true);
212
  } else {
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, leverage browser cache and speed up WordPress by saving Google Fonts to your server and removing external Google Fonts requests.
7
- * Version: 4.2.3
8
  * Author: Daan (from Fast FW Press)
9
  * Author URI: https://ffwp.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, leverage browser cache and speed up WordPress by saving Google Fonts to your server and removing external Google Fonts requests.
7
+ * Version: 4.2.4
8
  * Author: Daan (from Fast FW Press)
9
  * Author URI: https://ffwp.dev
10
  * License: GPL2v2 or later
includes/admin/class-settings.php CHANGED
@@ -85,6 +85,7 @@ class OMGF_Admin_Settings extends OMGF_Admin
85
  const OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS = 'omgf_preload_fonts';
86
  const OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS = 'omgf_unload_fonts';
87
  const OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS = 'omgf_unload_stylesheets';
 
88
 
89
  /**
90
  * Detection Settings
@@ -115,6 +116,9 @@ class OMGF_Admin_Settings extends OMGF_Admin
115
  /** @var string $plugin_text_domain */
116
  private $plugin_text_domain = 'host-webfonts-local';
117
 
 
 
 
118
  /**
119
  * OMGF_Admin_Settings constructor.
120
  */
@@ -131,6 +135,10 @@ class OMGF_Admin_Settings extends OMGF_Admin
131
  return;
132
  }
133
 
 
 
 
 
134
  // Tabs
135
  add_action( 'omgf_settings_tab', [ $this, 'optimize_fonts_tab' ], 0 );
136
  add_action( 'omgf_settings_tab', [ $this, 'detection_settings_tab' ], 1 );
@@ -324,7 +332,7 @@ class OMGF_Admin_Settings extends OMGF_Admin
324
 
325
  do_action( 'omgf_after_settings_form_settings' );
326
 
327
- submit_button( __( 'Save Changes', $this->plugin_text_domain ), 'primary', 'submit', false );
328
  ?>
329
  <a id="omgf-empty" class="omgf-empty button-cancel"><?php _e( 'Empty Cache Directory', $this->plugin_text_domain ); ?></a>
330
  </form>
85
  const OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS = 'omgf_preload_fonts';
86
  const OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS = 'omgf_unload_fonts';
87
  const OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS = 'omgf_unload_stylesheets';
88
+ const OMGF_OPTIMIZE_SETTING_CACHE_KEYS = 'omgf_cache_keys';
89
 
90
  /**
91
  * Detection Settings
116
  /** @var string $plugin_text_domain */
117
  private $plugin_text_domain = 'host-webfonts-local';
118
 
119
+ /** @var string|null */
120
+ private $submit_button_text = null;
121
+
122
  /**
123
  * OMGF_Admin_Settings constructor.
124
  */
135
  return;
136
  }
137
 
138
+ if ($this->active_tab == self::OMGF_SETTINGS_FIELD_OPTIMIZE) {
139
+ $this->submit_button_text = __('Save & Optimize', $this->plugin_text_domain);
140
+ }
141
+
142
  // Tabs
143
  add_action( 'omgf_settings_tab', [ $this, 'optimize_fonts_tab' ], 0 );
144
  add_action( 'omgf_settings_tab', [ $this, 'detection_settings_tab' ], 1 );
332
 
333
  do_action( 'omgf_after_settings_form_settings' );
334
 
335
+ submit_button( $this->submit_button_text, 'primary', 'submit', false );
336
  ?>
337
  <a id="omgf-empty" class="omgf-empty button-cancel"><?php _e( 'Empty Cache Directory', $this->plugin_text_domain ); ?></a>
338
  </form>
includes/admin/settings/class-detection.php CHANGED
@@ -112,7 +112,7 @@ class OMGF_Admin_Settings_Detection extends OMGF_Admin_Settings_Builder
112
  $this->do_checkbox(
113
  __( 'Advanced Processing (Pro)', $this->plugin_text_domain ),
114
  'omgf_pro_advanced_processing',
115
- defined( 'OMGF_PRO_ADVANCED_PROCESSING' ) ? true : false,
116
  __( 'By default, OMGF scans for Google Fonts which are registered/enqueued in the <code>wp_enqueue_scripts()</code> action in WordPress\' header (<code>wp_head()</code>). Advanced Processing will process all Google Fonts throughout the entire document. This setting can be tweaked further under Advanced Settings.', $this->plugin_text_domain ) . ' ' . $this->promo,
117
  true
118
  );
112
  $this->do_checkbox(
113
  __( 'Advanced Processing (Pro)', $this->plugin_text_domain ),
114
  'omgf_pro_advanced_processing',
115
+ defined( 'OMGF_PRO_ADVANCED_PROCESSING' ) ? OMGF_PRO_ADVANCED_PROCESSING : false,
116
  __( 'By default, OMGF scans for Google Fonts which are registered/enqueued in the <code>wp_enqueue_scripts()</code> action in WordPress\' header (<code>wp_head()</code>). Advanced Processing will process all Google Fonts throughout the entire document. This setting can be tweaked further under Advanced Settings.', $this->plugin_text_domain ) . ' ' . $this->promo,
117
  true
118
  );
includes/admin/settings/class-optimize.php CHANGED
@@ -143,64 +143,80 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
143
  */
144
  private function do_optimized_fonts_manager () {
145
  ?>
146
- <?php if ( $this->optimized_fonts ): ?>
147
- <div class="omgf-optimize-fonts-manage">
148
- <p>
149
 
150
- </p>
151
- <table>
152
- <thead>
153
- <tr>
154
- <td>&nbsp;</td>
155
- <th><?= __( 'Style', $this->plugin_text_domain ); ?></th>
156
- <th><?= __( 'Weight', $this->plugin_text_domain ); ?></th>
157
- <th class="preload"><?= __( 'Preload', $this->plugin_text_domain ); ?></th>
158
- <th class="unload"><?= __( 'Do not load', $this->plugin_text_domain ); ?></th>
159
- </tr>
160
- </thead>
161
- <?php foreach ( $this->optimized_fonts as $handle => $fonts ): ?>
162
- <tbody class="stylesheet" id="<?= $handle; ?>">
163
- <?php foreach ( $fonts as $font ): ?>
164
- <th><?= $font->family; ?> <span class="handle">(<?= $handle; ?>)</span></th>
165
- <?php foreach ( $font->variants as $variant ): ?>
166
- <tr>
167
- <td></td>
168
- <?php
169
- $preload = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS )[ $handle ][ $font->id ][ $variant->id ] ?? '';
170
- $unload = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS )[ $handle ][ $font->id ][ $variant->id ] ?? '';
171
- ?>
172
- <td><?= $variant->fontStyle; ?></td>
173
- <td><?= $variant->fontWeight; ?></td>
174
- <td>
175
- <input autocomplete="off" type="checkbox" class="preload" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS; ?>[<?= $handle; ?>][<?= $font->id; ?>][<?= $variant->id; ?>]" value="<?= $variant->id; ?>" <?= $preload ? 'checked="checked"' : ''; ?> />
176
- </td>
177
- <td>
178
- <input autocomplete="off" type="checkbox" class="unload" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS; ?>[<?= $handle; ?>][<?= $font->id; ?>][<?= $variant->id; ?>]" value="<?= $variant->id; ?>" <?= $unload ? 'checked="checked"' : ''; ?> />
179
- </td>
180
- </tr>
181
- <?php endforeach; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  <?php endforeach; ?>
183
- </tbody>
184
  <?php endforeach; ?>
185
- </table>
186
- <div class="omgf-optimize-fonts-tooltip">
187
- <p>
188
- <span class="dashicons-before dashicons-info-outline"></span>
189
- <?php if ( OMGF_OPTIMIZATION_MODE == 'manual' ): ?>
190
- <em><?= sprintf( __( "This list is populated with all Google Fonts captured from <strong>%s</strong>. Optimizations will be applied on every page using these fonts. If you want to optimize additional Google Fonts from other pages, temporarily switch to <strong>Automatic</strong> and visit the pages containing the stylesheets you'd like to optimize. This list will automatically be populated with the captured fonts. When you feel the list is complete, switch back to <strong>Manual</strong>.", $this->plugin_text_domain ), OMGF_MANUAL_OPTIMIZE_URL ); ?></em>
191
- <?php else: ?>
192
- <?php
193
- $no_cache_param = '?omgf_optimize=' . substr( md5( microtime() ), rand( 0, 26 ), 5 );
194
- ?>
195
- <em><?= sprintf( __( "This list is automatically populated with Google Fonts throughout your entire site. Optimizations will be applied on every page using these fonts. <strong>Automatic</strong> mode might not work when a Full Page Cache plugin is activated. If this list is not being populated with Google Fonts, you could try to visit your frontend and append the following parameter to the URL: <strong>%s</strong>", $this->plugin_text_domain ), $no_cache_param ); ?></em>
196
- <?php endif; ?>
197
- </p>
198
- </div>
199
- <input type="hidden" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS; ?>" value="<?= serialize( $this->optimized_fonts ); ?>"/>
200
- <input type="hidden" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL; ?>" value="<?= OMGF_MANUAL_OPTIMIZE_URL; ?>"/>
201
- <input id="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS; ?>" type="hidden" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS; ?>" value="<?= OMGF_UNLOAD_STYLESHEETS; ?>" />
202
  </div>
203
- <?php endif;
 
 
 
 
 
 
 
204
  }
205
 
206
  /**
143
  */
144
  private function do_optimized_fonts_manager () {
145
  ?>
146
+ <div class="omgf-optimize-fonts-manage">
147
+ <p>
 
148
 
149
+ </p>
150
+ <table>
151
+ <thead>
152
+ <tr>
153
+ <td>&nbsp;</td>
154
+ <th><?= __( 'Style', $this->plugin_text_domain ); ?></th>
155
+ <th><?= __( 'Weight', $this->plugin_text_domain ); ?></th>
156
+ <th class="preload"><?= __( 'Preload', $this->plugin_text_domain ); ?></th>
157
+ <th class="unload"><?= __( 'Do not load', $this->plugin_text_domain ); ?></th>
158
+ </tr>
159
+ </thead>
160
+ <?php
161
+ $cache_handles = omgf_init()::cache_keys();
162
+ ?>
163
+ <?php foreach ( $this->optimized_fonts as $handle => $fonts ): ?>
164
+ <?php
165
+ if (!omgf_init()::get_cache_key($handle)) {
166
+ $cache_handles[] = $handle;
167
+ }
168
+ ?>
169
+ <tbody class="stylesheet" id="<?= $handle; ?>">
170
+ <?php foreach ( $fonts as $font ): ?>
171
+ <?php if (count($font->variants) <= 0) continue; ?>
172
+ <th><?= $font->family; ?> <span class="handle">(<?= $handle; ?>)</span></th>
173
+ <?php foreach ( $font->variants as $variant ): ?>
174
+ <tr>
175
+ <td></td>
176
+ <?php
177
+ $preload = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS )[ $handle ][ $font->id ][ $variant->id ] ?? '';
178
+ $unload = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS )[ $handle ][ $font->id ][ $variant->id ] ?? '';
179
+ $class = $handle . '-' . $font->id . '-' . $variant->id;
180
+ ?>
181
+ <td><?= $variant->fontStyle; ?></td>
182
+ <td><?= $variant->fontWeight; ?></td>
183
+ <td class="preload-<?= $class; ?>">
184
+ <input data-handle="<?= $handle; ?>" data-font-id="<?= $font->id; ?>" autocomplete="off" type="checkbox" class="preload"
185
+ name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS; ?>[<?= $handle; ?>][<?= $font->id; ?>][<?= $variant->id; ?>]"
186
+ value="<?= $variant->id; ?>" <?= $preload ? 'checked="checked"' : ''; ?> <?= $unload ? 'disabled' : ''; ?> />
187
+ </td>
188
+ <td class="unload-<?= $class; ?>">
189
+ <input data-handle="<?= $handle; ?>" data-font-id="<?= $font->id; ?>" autocomplete="off" type="checkbox" class="unload"
190
+ name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS; ?>[<?= $handle; ?>][<?= $font->id; ?>][<?= $variant->id; ?>]"
191
+ value="<?= $variant->id; ?>" <?= $unload ? 'checked="checked"' : ''; ?> <?= $preload ? 'disabled' : ''; ?> />
192
+ </td>
193
+ </tr>
194
  <?php endforeach; ?>
 
195
  <?php endforeach; ?>
196
+ </tbody>
197
+ <?php endforeach; ?>
198
+ </table>
199
+ <div class="omgf-optimize-fonts-tooltip">
200
+ <p>
201
+ <span class="dashicons-before dashicons-info-outline"></span>
202
+ <?php if ( OMGF_OPTIMIZATION_MODE == 'manual' ): ?>
203
+ <em><?= sprintf( __( "This list is populated with all Google Fonts captured from <strong>%s</strong>. Optimizations will be applied on every page using these fonts. If you want to optimize additional Google Fonts from other pages, temporarily switch to <strong>Automatic</strong> and visit the pages containing the stylesheets you'd like to optimize. This list will automatically be populated with the captured fonts. When you feel the list is complete, switch back to <strong>Manual</strong>.", $this->plugin_text_domain ), OMGF_MANUAL_OPTIMIZE_URL ); ?></em>
204
+ <?php else: ?>
205
+ <?php
206
+ $no_cache_param = '?omgf_optimize=' . substr( md5( microtime() ), rand( 0, 26 ), 5 );
207
+ ?>
208
+ <em><?= sprintf( __( "This list is automatically populated with Google Fonts throughout your entire site. Optimizations will be applied on every page using these fonts. <strong>Automatic</strong> mode might not work when a Full Page Cache plugin is activated. If this list is not being populated with Google Fonts, you could try to visit your frontend and append the following parameter to the URL: <strong>%s</strong>", $this->plugin_text_domain ), $no_cache_param ); ?></em>
209
+ <?php endif; ?>
210
+ </p>
 
 
211
  </div>
212
+ <input type="hidden" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS; ?>" value="<?= serialize( $this->optimized_fonts ); ?>"/>
213
+ <input type="hidden" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL; ?>" value="<?= OMGF_MANUAL_OPTIMIZE_URL; ?>"/>
214
+ <input id="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS; ?>" type="hidden"
215
+ name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS; ?>" value="<?= OMGF_UNLOAD_STYLESHEETS; ?>"/>
216
+ <input id="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS; ?>" type="hidden"
217
+ name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS; ?>" value="<?= implode(',', $cache_handles); ?>" />
218
+ </div>
219
+ <?php
220
  }
221
 
222
  /**
includes/api/class-download.php CHANGED
@@ -72,11 +72,11 @@ class OMGF_API_Download extends WP_REST_Controller
72
  $this->convert_css2( $request );
73
  }
74
 
75
- $params = $request->get_params();
76
- $this->handle = $params['handle'] ?? '';
77
  $original_handle = $request->get_param( 'original_handle' );
78
 
79
- if ( ! $this->handle || ! $original_handle ) {
80
  wp_send_json_error( 'Handle not provided.', 406 );
81
  }
82
 
@@ -97,7 +97,7 @@ class OMGF_API_Download extends WP_REST_Controller
97
  }
98
 
99
  // Filter out empty element, i.e. failed requests.
100
- $fonts = array_filter($fonts);
101
 
102
  foreach ( $fonts as $font_key => &$font ) {
103
  $font_request = $this->filter_font_families( $font_families, $font );
@@ -135,16 +135,22 @@ class OMGF_API_Download extends WP_REST_Controller
135
 
136
  file_put_contents( $local_file, $stylesheet );
137
 
138
- $optimized_fonts = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS ) ?: [];
139
- $current_font = [ $this->handle => $fonts ];
140
 
141
- /**
142
- * If handle was already detected before, there's no need of saving it to OMGF's options.
143
- */
144
- if ( ! isset( $optimized_fonts[ $original_handle ] ) ) {
145
- update_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS, $optimized_fonts + $current_font );
 
 
 
 
146
  }
147
 
 
 
148
  // After downloading it, serve it.
149
  header( 'Content-Type: text/css' );
150
  header( "Content-Transfer-Encoding: Binary" );
@@ -236,8 +242,8 @@ class OMGF_API_Download extends WP_REST_Controller
236
 
237
  $response_code = $response['response']['code'] ?? '';
238
 
239
- if ( $response_code !== 200) {
240
- $message = sprintf( __( '<strong>%s</strong> could not be found using the current configuration. The API returned the following error: %s', $this->plugin_text_domain ), ucfirst( $family), wp_remote_retrieve_body( $response));
241
 
242
  OMGF_Admin_Notice::set_notice(
243
  $message,
@@ -393,6 +399,34 @@ class OMGF_API_Download extends WP_REST_Controller
393
  return $stylesheet;
394
  }
395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  /**
397
  * @param $sources
398
  * @param string $type
72
  $this->convert_css2( $request );
73
  }
74
 
75
+ $params = $request->get_params();
76
+ $this->handle = $params['handle'] ?? '';
77
  $original_handle = $request->get_param( 'original_handle' );
78
 
79
+ if ( ! $this->handle || ! $original_handle ) {
80
  wp_send_json_error( 'Handle not provided.', 406 );
81
  }
82
 
97
  }
98
 
99
  // Filter out empty element, i.e. failed requests.
100
+ $fonts = array_filter( $fonts );
101
 
102
  foreach ( $fonts as $font_key => &$font ) {
103
  $font_request = $this->filter_font_families( $font_families, $font );
135
 
136
  file_put_contents( $local_file, $stylesheet );
137
 
138
+ $current_font = [ $original_handle => $fonts ];
139
+ $optimized_fonts = omgf_init()::optimized_fonts();
140
 
141
+ // At first run, simply override the optimized_fonts array.
142
+ if ( empty( $optimized_fonts ) ) {
143
+ $optimized_fonts = $current_font;
144
+ // When a new font is detected, add it to the list.
145
+ } elseif ( ! isset( $optimized_fonts[ $original_handle ] ) ) {
146
+ $optimized_fonts = $optimized_fonts + $current_font;
147
+ // Unload is probably used. Let's rewrite the variants still in use.
148
+ } else {
149
+ $optimized_fonts = $this->rewrite_variants( $optimized_fonts, $current_font );
150
  }
151
 
152
+ update_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS, $optimized_fonts );
153
+
154
  // After downloading it, serve it.
155
  header( 'Content-Type: text/css' );
156
  header( "Content-Transfer-Encoding: Binary" );
242
 
243
  $response_code = $response['response']['code'] ?? '';
244
 
245
+ if ( $response_code !== 200 ) {
246
+ $message = sprintf( __( '<strong>%s</strong> could not be found using the current configuration. The API returned the following error: %s', $this->plugin_text_domain ), ucfirst( $family ), wp_remote_retrieve_body( $response ) );
247
 
248
  OMGF_Admin_Notice::set_notice(
249
  $message,
399
  return $stylesheet;
400
  }
401
 
402
+ /**
403
+ * When unload is used, insert the cache key for the variants still in use.
404
+ *
405
+ * @param $stylesheets
406
+ * @param $current_font
407
+ *
408
+ * @return mixed
409
+ */
410
+ private function rewrite_variants ( $stylesheets, $current_font ) {
411
+ foreach ( $stylesheets as $stylesheet => &$fonts ) {
412
+ foreach ( $fonts as $index => &$font ) {
413
+ if ( empty( (array) $font->variants ) ) {
414
+ continue;
415
+ }
416
+
417
+ foreach ( $font->variants as $variant_index => &$variant ) {
418
+ $replace_variant = $current_font[ $stylesheet ][ $index ]->variants[ $variant_index ] ?? (object) [];
419
+
420
+ if ( ! empty( (array) $replace_variant ) ) {
421
+ $variant = $replace_variant;
422
+ }
423
+ }
424
+ }
425
+ }
426
+
427
+ return $stylesheets;
428
+ }
429
+
430
  /**
431
  * @param $sources
432
  * @param string $type
includes/class-admin.php CHANGED
@@ -52,7 +52,7 @@ class OMGF_Admin
52
  $this->do_advanced_settings();
53
 
54
  add_filter( 'pre_update_option_omgf_optimized_fonts', [ $this, 'decode_option' ], 10, 3 );
55
- add_filter( 'pre_update_option_omgf_unload_fonts', [ $this, 'clean_up_cache' ], 10, 3 );
56
  add_filter( 'pre_update_option', [ $this, 'settings_changed' ], 10, 3 );
57
  }
58
 
@@ -115,27 +115,31 @@ class OMGF_Admin
115
  }
116
 
117
  /**
118
- * Triggered when preload settings is changed, cleans up old cache files.
 
 
119
  *
120
  * @param $old_value
121
  * @param $value
122
  * @param $option_name
123
  */
124
- public function clean_up_cache ( $value, $old_value, $option_name ) {
125
- if ( $value == $old_value ) {
126
  return $value;
127
  }
128
 
129
- $uniq_id = '';
130
-
131
- if ( omgf_init()::unloaded_fonts() ) {
132
- $uniq_id = strlen( json_encode( $old_value ) );
133
  }
134
 
135
- $entries = array_filter( (array) glob( OMGF_FONTS_DIR . "/*$uniq_id" ) );
136
 
137
- foreach ( $entries as $entry ) {
138
- OMGF::delete( $entry );
 
 
 
 
139
  }
140
 
141
  return $value;
@@ -155,7 +159,7 @@ class OMGF_Admin
155
  if ( $value != $old_value ) {
156
  global $wp_settings_errors;
157
 
158
- if ( ! empty ($wp_settings_errors ) ) {
159
  $wp_settings_errors = [];
160
  }
161
 
52
  $this->do_advanced_settings();
53
 
54
  add_filter( 'pre_update_option_omgf_optimized_fonts', [ $this, 'decode_option' ], 10, 3 );
55
+ add_filter( 'pre_update_option_omgf_cache_keys', [ $this, 'clean_up_cache' ], 10, 3 );
56
  add_filter( 'pre_update_option', [ $this, 'settings_changed' ], 10, 3 );
57
  }
58
 
115
  }
116
 
117
  /**
118
+ * Triggered when unload settings is changed, cleans up old cache files.
119
+ *
120
+ * TODO: Clean up doesn't work on 2nd run?
121
  *
122
  * @param $old_value
123
  * @param $value
124
  * @param $option_name
125
  */
126
+ public function clean_up_cache ( $value, $old_value ) {
127
+ if ( $old_value == $value ) {
128
  return $value;
129
  }
130
 
131
+ if ( $old_value == null ) {
132
+ return $value;
 
 
133
  }
134
 
135
+ $cache_keys = explode( ',', $old_value );
136
 
137
+ foreach ( $cache_keys as $key ) {
138
+ $entries = array_filter( (array) glob( OMGF_FONTS_DIR . "/*$key" ) );
139
+
140
+ foreach ( $entries as $entry ) {
141
+ OMGF::delete( $entry );
142
+ }
143
  }
144
 
145
  return $value;
159
  if ( $value != $old_value ) {
160
  global $wp_settings_errors;
161
 
162
+ if ( ! empty ( $wp_settings_errors ) ) {
163
  $wp_settings_errors = [];
164
  }
165
 
includes/class-omgf.php CHANGED
@@ -54,28 +54,42 @@ class OMGF
54
  define( 'OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH );
55
  define( 'OMGF_UNINSTALL', esc_attr( get_option( OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL ) ) );
56
  define( 'OMGF_UNLOAD_STYLESHEETS', esc_attr( get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, '' ) ) );
 
57
  }
58
 
59
  /**
60
  * @return array
61
  */
62
  public static function optimized_fonts () {
63
- static $optimized_fonts = null;
64
 
65
- if ( $optimized_fonts === null ) {
66
  $optimized_fonts = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS, [] );
67
  }
68
 
69
  return $optimized_fonts;
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  /**
73
  * @return array
74
  */
75
  public static function unloaded_fonts () {
76
- static $unloaded_fonts = null;
77
 
78
- if ( $unloaded_fonts === null ) {
79
  $unloaded_fonts = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS, [] );
80
  }
81
 
@@ -86,9 +100,9 @@ class OMGF
86
  * @return array
87
  */
88
  public static function unloaded_stylesheets () {
89
- static $unloaded_stylesheets = null;
90
 
91
- if ( $unloaded_stylesheets === null ) {
92
  $unloaded_stylesheets = explode( ',', get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, '' ) );
93
  }
94
 
@@ -98,8 +112,31 @@ class OMGF
98
  /**
99
  * @return array
100
  */
101
- public static function preloaded_fonts () {
102
- return get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS, [] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
 
105
  /**
54
  define( 'OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH );
55
  define( 'OMGF_UNINSTALL', esc_attr( get_option( OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL ) ) );
56
  define( 'OMGF_UNLOAD_STYLESHEETS', esc_attr( get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, '' ) ) );
57
+ define( 'OMGF_CACHE_KEYS', esc_attr( get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS, '' ) ) );
58
  }
59
 
60
  /**
61
  * @return array
62
  */
63
  public static function optimized_fonts () {
64
+ static $optimized_fonts = [];
65
 
66
+ if ( empty ( $optimized_fonts ) ) {
67
  $optimized_fonts = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS, [] );
68
  }
69
 
70
  return $optimized_fonts;
71
  }
72
 
73
+ /**
74
+ * @return array
75
+ */
76
+ public static function preloaded_fonts () {
77
+ static $preloaded_fonts = [];
78
+
79
+ if ( empty( $preloaded_fonts ) ) {
80
+ $preloaded_fonts = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS, [] );
81
+ }
82
+
83
+ return $preloaded_fonts;
84
+ }
85
+
86
  /**
87
  * @return array
88
  */
89
  public static function unloaded_fonts () {
90
+ static $unloaded_fonts = [];
91
 
92
+ if ( empty( $unloaded_fonts ) ) {
93
  $unloaded_fonts = get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS, [] );
94
  }
95
 
100
  * @return array
101
  */
102
  public static function unloaded_stylesheets () {
103
+ static $unloaded_stylesheets = [];
104
 
105
+ if ( empty( $unloaded_stylesheets ) ) {
106
  $unloaded_stylesheets = explode( ',', get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, '' ) );
107
  }
108
 
112
  /**
113
  * @return array
114
  */
115
+ public static function cache_keys () {
116
+ static $cache_keys = [];
117
+
118
+ if ( empty( $cache_keys ) ) {
119
+ $cache_keys = explode( ',', get_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS, '' ) );
120
+ }
121
+
122
+ return array_filter( $cache_keys );
123
+ }
124
+
125
+ /**
126
+ * @param $handle
127
+ *
128
+ * @return string
129
+ */
130
+ public static function get_cache_key ($handle) {
131
+ $cache_keys = self::cache_keys();
132
+
133
+ foreach ($cache_keys as $index => $key) {
134
+ if (strpos($key, $handle) !== false) {
135
+ return $key;
136
+ }
137
+ }
138
+
139
+ return '';
140
  }
141
 
142
  /**
includes/class-optimize.php CHANGED
@@ -39,6 +39,7 @@ class OMGF_Optimize
39
  // Will die when it fails.
40
  check_admin_referer( 'omgf-optimize-settings-options' );
41
 
 
42
  update_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS, $_POST[ OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS ] );
43
  update_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS, $_POST[ OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS ] );
44
  update_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, $_POST[ OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS ] );
@@ -105,6 +106,13 @@ class OMGF_Optimize
105
  */
106
  private function optimization_succeeded () {
107
  add_settings_error( 'general', 'omgf_optimization_success', __( 'Optimization completed successfully.' ), 'success' );
 
 
 
 
 
 
 
108
  }
109
 
110
  /**
@@ -133,7 +141,7 @@ class OMGF_Optimize
133
  */
134
  private function run_auto () {
135
  OMGF_Admin_Notice::set_notice(
136
- __( 'OMGF Optimization is silently running in the background. After visiting a few pages, return here to manage the captured Google Fonts.' ),
137
  'omgf-auto-running',
138
  false
139
  );
39
  // Will die when it fails.
40
  check_admin_referer( 'omgf-optimize-settings-options' );
41
 
42
+ update_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS, $_POST[ OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS ] );
43
  update_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS, $_POST[ OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS ] );
44
  update_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS, $_POST[ OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS ] );
45
  update_option( OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, $_POST[ OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS ] );
106
  */
107
  private function optimization_succeeded () {
108
  add_settings_error( 'general', 'omgf_optimization_success', __( 'Optimization completed successfully.' ), 'success' );
109
+
110
+ OMGF_Admin_Notice::set_notice(
111
+ __('If you\'re using any 3rd party optimization plugins (e.g. WP Rocket, Autoptimize, W3 Total Cache, etc.) make sure to flush their caches for OMGF\'s optimizations to take effect.', $this->plugin_text_domain),
112
+ 'omgf-cache-notice',
113
+ false,
114
+ 'warning'
115
+ );
116
  }
117
 
118
  /**
141
  */
142
  private function run_auto () {
143
  OMGF_Admin_Notice::set_notice(
144
+ __( 'OMGF Optimization is silently running in the background. After visiting a few pages, return here to manage the captured Google Fonts.', $this->plugin_text_domain ),
145
  'omgf-auto-running',
146
  false
147
  );
includes/frontend/class-functions.php CHANGED
@@ -82,7 +82,8 @@ class OMGF_Frontend_Functions
82
  }
83
 
84
  /**
85
- *
 
86
  */
87
  public function add_preloads () {
88
  $preloaded_fonts = omgf_init()::preloaded_fonts();
@@ -125,11 +126,11 @@ class OMGF_Frontend_Functions
125
  return;
126
  }
127
 
128
- if ( apply_filters( 'omgf_pro_advanced_processing_enabled', false ) ) {
129
  return;
130
  }
131
 
132
- if ( is_admin() ) {
133
  return;
134
  }
135
 
@@ -165,6 +166,7 @@ class OMGF_Frontend_Functions
165
  $registered = $wp_styles->registered;
166
  $fonts = apply_filters( 'omgf_auto_replace', $this->detect_registered_google_fonts( $registered ) );
167
  $unloaded_stylesheets = omgf_init()::unloaded_stylesheets();
 
168
 
169
  foreach ( $fonts as $handle => $font ) {
170
  // If this stylesheet has been marked for unload, empty the src and skip out early.
@@ -176,8 +178,8 @@ class OMGF_Frontend_Functions
176
 
177
  $updated_handle = $handle;
178
 
179
- if ( $unloaded_fonts = omgf_init()::unloaded_fonts() ) {
180
- $updated_handle = $handle . '-' . strlen( json_encode( $unloaded_fonts ) );
181
  }
182
 
183
  $cached_file = OMGF_CACHE_PATH . '/' . $updated_handle . "/$updated_handle.css";
82
  }
83
 
84
  /**
85
+ * TODO: When setting all preloads at once (different stylesheet handles) combined with unloads, not all URLs are rewritten with their cache keys properly.
86
+ * When configured handle by handle, it works fine. PHP multi-threading issues?
87
  */
88
  public function add_preloads () {
89
  $preloaded_fonts = omgf_init()::preloaded_fonts();
126
  return;
127
  }
128
 
129
+ if ( is_admin() ) {
130
  return;
131
  }
132
 
133
+ if ( apply_filters( 'omgf_pro_advanced_processing_enabled', false ) ) {
134
  return;
135
  }
136
 
166
  $registered = $wp_styles->registered;
167
  $fonts = apply_filters( 'omgf_auto_replace', $this->detect_registered_google_fonts( $registered ) );
168
  $unloaded_stylesheets = omgf_init()::unloaded_stylesheets();
169
+ $unloaded_fonts = omgf_init()::unloaded_fonts();
170
 
171
  foreach ( $fonts as $handle => $font ) {
172
  // If this stylesheet has been marked for unload, empty the src and skip out early.
178
 
179
  $updated_handle = $handle;
180
 
181
+ if ( $unloaded_fonts ) {
182
+ $updated_handle = omgf_init()::get_cache_key($handle);
183
  }
184
 
185
  $cached_file = OMGF_CACHE_PATH . '/' . $updated_handle . "/$updated_handle.css";
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.5
6
- Stable tag: 4.2.3
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -122,6 +122,14 @@ No, not yet. But I will definitely try to make it compatible in the future!
122
 
123
  == Changelog ==
124
 
 
 
 
 
 
 
 
 
125
  = 4.2.3 =
126
  * Fixed invalid preload header,
127
  * Fixed warning: `array_keys() expects parameter 1 to be array, null given` when multiple stylesheets are loaded, but preloads are only enabled for one of them.
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.5
6
+ Stable tag: 4.2.4
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
122
 
123
  == Changelog ==
124
 
125
+ = 4.2.4 | December 8th, 2020 =
126
+ * Cache keys are now fixed values instead of dynamically generated. This fixes the bug where preloads wouldn't load properly when combined with unloaded fonts of the same stylesheet.
127
+ * **IMPORTANT**: To fix any bugs with preloads/unloads, emptying the cache directory is required.
128
+ * Cleaned up the sidebar and added a notification to reassure people that no features were moved from Free to Pro after upgrading to v4.
129
+ * Advanced Processing can now be disabled even when OMGF Pro is active. Before it was always on (accidentally).
130
+ * When preload is enabled for a font style, its associated unload checkbox is disabled and vice versa.
131
+ * Minor fixes, increased usability and optimizations.
132
+
133
  = 4.2.3 =
134
  * Fixed invalid preload header,
135
  * Fixed warning: `array_keys() expects parameter 1 to be array, null given` when multiple stylesheets are loaded, but preloads are only enabled for one of them.
templates/admin/block-welcome.phtml CHANGED
@@ -22,38 +22,11 @@ $tweetUrl = 'https://twitter.com/intent/tweet?text=I+just+optimized+my
22
  ?>
23
  <div class="welcome-panel-content">
24
  <div class="welcome-panel-column-container">
25
- <?php if (apply_filters('apply_omgf_pro_promo', true)): ?>
26
- <div class="welcome-panel-column" style="width: 100%; margin-right: 15px;">
27
- <h2><?php _e('Why upgrade to OMGF Pro?', $plugin_text_domain); ?></h2>
28
- <ul>
29
- <li class="welcome-icon dashicons-before dashicons-yes">
30
- <?= __('Automatically Replace/Remove Google Fonts throughout the entire document.', $plugin_text_domain); ?>
31
- </li>
32
- <li class="welcome-icon dashicons-before dashicons-yes">
33
- <?= __('Combine and de-duplicate Google Fonts into one request.', $plugin_text_domain); ?>
34
- </li>
35
- <li class="welcome-icon dashicons-before dashicons-yes">
36
- <?= __('Performance Fine Tuning', $plugin_text_domain); ?>
37
- </li>
38
- <li class="welcome-icon dashicons-before dashicons-yes">
39
- <?= __('Automatically remove Resource Hints pointing to Google\'s Servers.', $plugin_text_domain); ?>
40
- </li>
41
- <li class="welcome-icon dashicons-before dashicons-yes">
42
- <?= __('Reduce Page Size and Load Time using Subset Forcing.', $plugin_text_domain); ?>
43
- </li>
44
- </ul>
45
- <p>
46
- <a class="button button-hero button-primary" href="https://ffwp.dev/wordpress/omgf-pro"><span class="dashicons-before dashicons-cart"> <?= __('Buy now'); ?></span></a>
47
- <span><?= __('Starting at € 29,-', $plugin_text_domain); ?></span>
48
- </p>
49
- <hr/>
50
- </div>
51
- <?php endif; ?>
52
- <div class="welcome-panel-column welcome-panel-last" style="width: 100%;">
53
  <?php if (apply_filters('apply_omgf_pro_promo', true)): ?>
54
- <h3>
55
  <?php _e('Support OMGF by Spreading the Word!', $plugin_text_domain); ?>
56
- </h3>
57
  <p>
58
  <?= __('Just because this plugin\'s free, doesn\'t mean there\'s nothing you can do to support me! :)', $plugin_text_domain); ?>
59
  </p>
@@ -64,7 +37,7 @@ $tweetUrl = 'https://twitter.com/intent/tweet?text=I+just+optimized+my
64
  <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', $plugin_text_domain); ?></span></a>
65
  <a target="_blank" class="button button-secondary button-hero" href="<?= $tweetUrl; ?>"><span class="dashicons-before dashicons-twitter"> <?php _e('Tweet', $plugin_text_domain); ?></span></a>
66
  </p>
67
- <?php else:; ?>
68
  <h2>
69
  <?= __('Do you <span class="dashicons dashicons-heart ffwp-heart"></span> OMGF Pro?', $plugin_text_domain) ;?>
70
  </h2>
@@ -77,6 +50,19 @@ $tweetUrl = 'https://twitter.com/intent/tweet?text=I+just+optimized+my
77
  </p>
78
  <?php endif; ?>
79
  <hr/>
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  <h3>
81
  <?php _e('Need Help?', $plugin_text_domain); ?>
82
  </h3>
@@ -84,7 +70,7 @@ $tweetUrl = 'https://twitter.com/intent/tweet?text=I+just+optimized+my
84
  <li><a target="_blank" href="<?= apply_filters('omgf_settings_sidebar_quick_start', 'https://ffwp.dev/docs/omgf-pro/quick-start/'); ?>"><?= __('Quick Start Guide', $plugin_text_domain); ?></a></li>
85
  <li><a target="_blank" href="<?= apply_filters('omgf_settings_sidebar_user_manual', 'https://ffwp.dev/docs/omgf-pro/user-manual/'); ?>"><?= __('User Manual', $plugin_text_domain); ?></a></li>
86
  <li><a target="_blank" href="<?= apply_filters('omgf_settings_sidebar_faq_link', 'https://wordpress.org/plugins/host-webfonts-local/#description'); ?>"><?= __('FAQ', $plugin_text_domain); ?></a></li>
87
- <li><a target="_blank" href="<?= apply_filters('omgf_settings_sidebar_get_support_link', 'https://wordpress.org/support/plugin/host-webfonts-local'); ?>"><?= __('Get Support', $plugin_text_domain); ?></a></li>
88
  </ul>
89
  <hr />
90
  <h4 class="signature"><?= sprintf(__('Coded with %s in The Netherlands.', $plugin_text_domain), '<span class="dashicons dashicons-heart ffwp-heart"></span>'); ?></h4>
22
  ?>
23
  <div class="welcome-panel-content">
24
  <div class="welcome-panel-column-container">
25
+ <div class="welcome-panel-column" style="width: 100%;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  <?php if (apply_filters('apply_omgf_pro_promo', true)): ?>
27
+ <h2>
28
  <?php _e('Support OMGF by Spreading the Word!', $plugin_text_domain); ?>
29
+ </h2>
30
  <p>
31
  <?= __('Just because this plugin\'s free, doesn\'t mean there\'s nothing you can do to support me! :)', $plugin_text_domain); ?>
32
  </p>
37
  <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', $plugin_text_domain); ?></span></a>
38
  <a target="_blank" class="button button-secondary button-hero" href="<?= $tweetUrl; ?>"><span class="dashicons-before dashicons-twitter"> <?php _e('Tweet', $plugin_text_domain); ?></span></a>
39
  </p>
40
+ <?php else: ?>
41
  <h2>
42
  <?= __('Do you <span class="dashicons dashicons-heart ffwp-heart"></span> OMGF Pro?', $plugin_text_domain) ;?>
43
  </h2>
50
  </p>
51
  <?php endif; ?>
52
  <hr/>
53
+ <h3>
54
+ <?= __('Did you upgrade from OMGF v3 to v4?', $plugin_text_domain); ?>
55
+ </h3>
56
+ <p>
57
+ <?= __('First off, thank you! :)', $plugin_text_domain); ?>
58
+ </p>
59
+ <p>
60
+ <?= __('No features were moved from Free to Pro during this upgrade.', $plugin_text_domain); ?>
61
+ </p>
62
+ <p>
63
+ <?= sprintf(__('However, if you find anything that broke after the upgrade. Please send me a <a target="_blank" href="%s">support ticket</a>.', $plugin_text_domain), 'https://wordpress.org/support/plugin/host-webfonts-local/#new-post'); ?>
64
+ </p>
65
+ <hr/>
66
  <h3>
67
  <?php _e('Need Help?', $plugin_text_domain); ?>
68
  </h3>
70
  <li><a target="_blank" href="<?= apply_filters('omgf_settings_sidebar_quick_start', 'https://ffwp.dev/docs/omgf-pro/quick-start/'); ?>"><?= __('Quick Start Guide', $plugin_text_domain); ?></a></li>
71
  <li><a target="_blank" href="<?= apply_filters('omgf_settings_sidebar_user_manual', 'https://ffwp.dev/docs/omgf-pro/user-manual/'); ?>"><?= __('User Manual', $plugin_text_domain); ?></a></li>
72
  <li><a target="_blank" href="<?= apply_filters('omgf_settings_sidebar_faq_link', 'https://wordpress.org/plugins/host-webfonts-local/#description'); ?>"><?= __('FAQ', $plugin_text_domain); ?></a></li>
73
+ <li><a target="_blank" href="<?= apply_filters('omgf_settings_sidebar_get_support_link', 'https://wordpress.org/support/plugin/host-webfonts-local/#new-post'); ?>"><?= __('Get Support', $plugin_text_domain); ?></a></li>
74
  </ul>
75
  <hr />
76
  <h4 class="signature"><?= sprintf(__('Coded with %s in The Netherlands.', $plugin_text_domain), '<span class="dashicons dashicons-heart ffwp-heart"></span>'); ?></h4>