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

Version Description

Fixed bug where a few strings couldn't be translated. Improved responsiveness of settings-screen. Minor re-factor for better structure.

Download this release

Release Info

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

Code changes from version 1.8.3 to 1.9.11

css/hwl-admin.css CHANGED
@@ -1,10 +1,42 @@
1
  /**
2
- * @package: CAOS for Webfonts
3
  * @author: Daan van den Bergh
4
  * @copyright: (c) 2019 Daan van den Bergh
5
  * @url: https://daan.dev
6
  */
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  #search-field {
9
  line-height: 38px;
10
  width: 360px;
1
  /**
2
+ * @package: OMGF
3
  * @author: Daan van den Bergh
4
  * @copyright: (c) 2019 Daan van den Bergh
5
  * @url: https://daan.dev
6
  */
7
 
8
+ /**
9
+ * Responsiveness
10
+ */
11
+
12
+ .settings-column {
13
+ float: left;
14
+ }
15
+
16
+ .settings-column.left {
17
+ width: 60%;
18
+ }
19
+
20
+ .settings-column.right {
21
+ width: 39%
22
+ }
23
+
24
+ @media only screen and (max-width: 940px) {
25
+ .settings-column {
26
+ display: block;
27
+ float: none;
28
+ }
29
+
30
+ .settings-column.left,
31
+ .settings-column.right {
32
+ width: 100%;
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Generate Stylesheet-form
38
+ */
39
+
40
  #search-field {
41
  line-height: 38px;
42
  width: 360px;
css/hwl-admin.min.css CHANGED
@@ -1 +1 @@
1
- #search-field{line-height:38px;width:360px;font-size:20px;padding:3px 10px}#hwl-results .spinner{visibility:visible !important;float:none}#hwl-results{position:relative}tr.loading td{position:absolute;width:100%;height:100%;left:0;right:0;text-align:center;background-color:rgba(255,255,255,0.5)}.hwl-remove{cursor:pointer}.button-cancel{color:#a00;text-decoration:none;border-color:transparent;box-shadow:none;background:0;border-radius:3px;white-space:nowrap;padding:6px 10px !important}.button-cancel:hover{cursor:pointer;background:#d54e21;color:#fff;border-color:#d54e21}.caos-status-total-bar{height:30px;border-radius:6px;padding:4px 4px 0;background:rgba(0,0,0,0.25);box-shadow:inset 0 1px 2px rgba(0,0,0,0.25),0 1px rgba(255,255,255,0.08)}#caos-status-progress-bar{height:26px;color:#fff;border-radius:4px;white-space:nowrap;line-height:25px;text-align:center;transition:width 1s;-webkit-transition:width 1s;background-color:#0daadb;background-image:linear-gradient(to bottom,rgba(255,255,255,0.3),rgba(255,255,255,0.05));box-shadow:0 0 1px 1px rgba(0,0,0,0.25),inset 0 1px rgba(255,255,255,0.1)}
1
+ .settings-column{float:left}.settings-column.left{width:60%}.settings-column.right{width:39%}@media only screen and (max-width:940px){.settings-column{display:block;float:none}.settings-column.left,.settings-column.right{width:100%}}#search-field{line-height:38px;width:360px;font-size:20px;padding:3px 10px}#hwl-results .spinner{visibility:visible !important;float:none}#hwl-results{position:relative}tr.loading td{position:absolute;width:100%;height:100%;left:0;right:0;text-align:center;background-color:rgba(255,255,255,0.5)}.hwl-remove{cursor:pointer}.button-cancel{color:#a00;text-decoration:none;border-color:transparent;box-shadow:none;background:0;border-radius:3px;white-space:nowrap;padding:6px 10px !important}.button-cancel:hover{cursor:pointer;background:#d54e21;color:#fff;border-color:#d54e21}.caos-status-total-bar{height:30px;border-radius:6px;padding:4px 4px 0;background:rgba(0,0,0,0.25);box-shadow:inset 0 1px 2px rgba(0,0,0,0.25),0 1px rgba(255,255,255,0.08)}#caos-status-progress-bar{height:26px;color:#fff;border-radius:4px;white-space:nowrap;line-height:25px;text-align:center;transition:width 1s;-webkit-transition:width 1s;background-color:#0daadb;background-image:linear-gradient(to bottom,rgba(255,255,255,0.3),rgba(255,255,255,0.05));box-shadow:0 0 1px 1px rgba(0,0,0,0.25),inset 0 1px rgba(255,255,255,0.1)}
host-webfonts-local.php CHANGED
@@ -1,19 +1,20 @@
1
  <?php
2
  /**
3
  * @formatter:off
4
- * Plugin Name: CAOS for Webfonts
5
  * Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
6
- * Description: Automagically save the fonts you want to use inside your content-folder, generate a stylesheet for them and enqueue it in your theme's header.
7
- * Version: 1.8.3
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
 
11
  * @formatter:on
12
  */
13
 
14
  // Exit if accessed directly
15
  if (!defined('ABSPATH')) {
16
- exit;
17
  }
18
 
19
  global $wpdb;
@@ -22,56 +23,62 @@ global $wpdb;
22
  * Define constants.
23
  */
24
  define('CAOS_WEBFONTS_DB_VERSION', '1.8.3');
25
- define('CAOS_WEBFONTS_STATIC_VERSION', '1.7.6');
26
  define('CAOS_WEBFONTS_SITE_URL', 'https://daan.dev');
27
  define('CAOS_WEBFONTS_DB_TABLENAME', $wpdb->prefix . 'caos_webfonts');
28
  define('CAOS_WEBFONTS_DB_CHARSET', $wpdb->get_charset_collate());
29
  define('CAOS_WEBFONTS_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
30
  define('CAOS_WEBFONTS_FILENAME', 'fonts.css');
31
- define('CAOS_WEBFONTS_CACHE_DIR', esc_attr(get_option('caos_webfonts_cache_dir')) ?: '/cache/caos-webfonts');
32
  define('CAOS_WEBFONTS_CDN_URL', esc_attr(get_option('caos_webfonts_cdn_url')));
33
  define('CAOS_WEBFONTS_REMOVE_VERSION', esc_attr(get_option('caos_webfonts_remove_version')));
34
  define('CAOS_WEBFONTS_CURRENT_BLOG_ID', get_current_blog_id());
35
  define('CAOS_WEBFONTS_UPLOAD_DIR', WP_CONTENT_DIR . CAOS_WEBFONTS_CACHE_DIR);
36
  define('CAOS_WEBFONTS_UPLOAD_URL', hwlGetUploadUrl());
37
  define('CAOS_WEBFONTS_DISPLAY_OPTION', esc_attr(get_option('caos_webfonts_display_option')) ?: 'auto');
 
38
  define('CAOS_WEBFONTS_PRELOAD', esc_attr(get_option('caos_webfonts_preload')));
39
 
40
  /**
41
  * Register settings
42
  */
43
- function hwlRegisterSettings() {
44
- register_setting('caos-webfonts-basic-settings',
45
- 'caos_webfonts_cache_dir'
46
- );
47
- register_setting('caos-webfonts-basic-settings',
 
48
  'caos_webfonts_cdn_url'
49
  );
50
  register_setting('caos-webfonts-basic-settings',
51
  'caos_webfonts_remove_version'
52
  );
53
- register_setting('caos-webfonts-basic-settings',
54
- 'caos_webfonts_display_option'
55
- );
56
- register_setting('caos-webfonts-basic-settings',
57
- 'caos_webfonts_preload'
58
- );
 
 
 
59
  }
60
 
61
  /**
62
  * Create the Admin menu-item
63
  */
64
- function hwlCreateMenu() {
65
- add_options_page(
66
- 'CAOS for Webfonts',
67
- 'Optimize Webfonts',
68
- 'manage_options',
69
- 'optimize-webfonts',
70
- 'hwlSettingsPage'
71
- );
72
- add_action('admin_init',
73
- 'hwlRegisterSettings'
74
- );
 
75
  }
76
  add_action('admin_menu', 'hwlCreateMenu');
77
 
@@ -80,16 +87,18 @@ add_action('admin_menu', 'hwlCreateMenu');
80
  *
81
  * @return mixed
82
  */
83
- function hwlGetContentDirName() {
84
- preg_match('/[^\/]+$/u', WP_CONTENT_DIR, $match);
 
85
 
86
- return $match[0];
87
  }
88
 
89
  /**
90
- * @return string
91
  */
92
- function hwlGetUploadUrl() {
 
93
  if (CAOS_WEBFONTS_CDN_URL) {
94
  $uploadUrl = '//' . CAOS_WEBFONTS_CDN_URL . '/' . hwlGetContentDirName() . CAOS_WEBFONTS_CACHE_DIR;
95
  } else {
@@ -102,8 +111,9 @@ function hwlGetUploadUrl() {
102
  /**
103
  * Create table to store downloaded fonts in version 1.6.1.
104
  */
105
- function hwlCreateWebfontsTable() {
106
- global $wpdb;
 
107
  $sql = "CREATE TABLE IF NOT EXISTS " . CAOS_WEBFONTS_DB_TABLENAME . " (
108
  font_id varchar(191) NOT NULL,
109
  font_family varchar(191) NOT NULL,
@@ -116,15 +126,16 @@ function hwlCreateWebfontsTable() {
116
  url_eot varchar(191) NULL,
117
  UNIQUE KEY (font_id)
118
  ) " . CAOS_WEBFONTS_DB_CHARSET . ";";
119
- $wpdb->query($sql);
120
 
121
- add_option('caos_webfonts_db_version', '1.6.1');
122
  }
123
 
124
  /**
125
  * Create table to store selected subsets in version 1.7.0.
126
  */
127
- function hwlCreateSubsetsTable() {
 
128
  global $wpdb;
129
  $sql = "CREATE TABLE IF NOT EXISTS " . CAOS_WEBFONTS_DB_TABLENAME . '_subsets' . " (
130
  subset_font varchar(32) NOT NULL,
@@ -141,7 +152,8 @@ function hwlCreateSubsetsTable() {
141
  /**
142
  * Adds the 'local' column in version 1.8.3
143
  */
144
- function hwlAddLocalColumn() {
 
145
  global $wpdb;
146
 
147
  $sql = "ALTER TABLE " . CAOS_WEBFONTS_DB_TABLENAME . " " .
@@ -154,15 +166,16 @@ function hwlAddLocalColumn() {
154
  /**
155
  * Check current version and execute required db updates.
156
  */
157
- function hwlRunDbUpdates() {
158
- $currentVersion = get_site_option('caos_webfonts_db_version') ?: '1.0.0';
159
- if (version_compare($currentVersion, '1.6.1') < 0) {
160
- hwlCreateWebfontsTable();
161
- }
162
- if (version_compare($currentVersion, '1.7.0') < 0) {
163
- hwlCreateSubsetsTable();
 
164
  }
165
- if (version_compare($currentVersion, CAOS_WEBFONTS_DB_VERSION) < 0) {
166
  hwlAddLocalColumn();
167
  }
168
  }
@@ -173,12 +186,13 @@ add_action('plugins_loaded', 'hwlRunDbUpdates');
173
  *
174
  * @return mixed
175
  */
176
- function hwlSettingsLink($links) {
177
- $adminUrl = admin_url() . 'options-general.php?page=optimize-webfonts';
178
- $settingsLink = "<a href='$adminUrl'>" . __('Settings') . "</a>";
179
- array_push($links, $settingsLink);
 
180
 
181
- return $links;
182
  }
183
  $caosLink = plugin_basename(__FILE__);
184
 
@@ -187,104 +201,110 @@ add_filter("plugin_action_links_$caosLink", 'hwlSettingsLink');
187
  /**
188
  * Render the settings page.
189
  */
190
- function hwlSettingsPage() {
191
- if (!current_user_can('manage_options')) {
192
- wp_die(__("You're not cool enough to access this page."));
193
- }
194
- ?>
 
195
  <div class="wrap">
196
- <h1><?php _e('CAOS for Webfonts', 'host-webfonts-local'); ?></h1>
197
  <p>
198
- <?php _e('Developed by: ', 'host-webfonts-local'); ?>
199
  <a title="Buy me a beer!" href="<?php echo CAOS_WEBFONTS_SITE_URL; ?>/donate/">
200
  Daan van den Bergh</a>.
201
  </p>
202
 
203
  <div id="hwl-admin-notices"></div>
204
 
205
- <?php require_once(plugin_dir_path(__FILE__) . 'includes/welcome-panel.php'); ?>
206
 
207
- <form id="hwl-options-form" name="hwl-options-form" method="post" style="float: left; width: 60%;">
208
  <div class="">
209
- <?php
210
 
211
- include(plugin_dir_path(__FILE__) . 'includes/caos-webfonts-style-generation.php');
212
 
213
- ?>
214
  </div>
215
  </form>
216
 
217
- <form id="hwl-settings-form" name="hwl-settings-form" method="post" action="options.php" style="float: left; width: 39%;">
218
- <?php
219
- settings_fields('caos-webfonts-basic-settings');
220
- do_settings_sections('caos-webfonts-basic-settings');
221
 
222
- include(plugin_dir_path(__FILE__) . 'includes/caos-webfonts-basic-settings.php');
223
 
224
- do_action('hwl_after_settings_form_settings');
225
 
226
  submit_button();
227
  ?>
228
  </form>
229
  </div>
230
- <?php
231
  }
232
 
233
  /**
234
  * @return array|\Exception
235
  */
236
- function hwlGetTotalFonts() {
237
- global $wpdb;
 
238
 
239
- try {
240
- return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME);
241
- } catch (\Exception $e) {
242
- return $e;
243
- }
244
  }
245
 
246
  /**
247
  * @return array|\Exception
248
  */
249
- function hwlGetDownloadedFonts() {
250
- global $wpdb;
 
251
 
252
- try {
253
- return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . " WHERE downloaded = 1");
254
- } catch (\Exception $e) {
255
- return $e;
256
- }
257
  }
258
 
259
  /**
260
  * @return array
261
  */
262
- function hwlGetDownloadStatus() {
263
- return array(
264
- "downloaded" => count(hwlGetDownloadedFonts()),
265
- "total" => count(hwlGetTotalFonts())
266
- );
 
267
  }
268
 
269
  /**
270
- * @return array|\Exception|null|object
271
  */
272
- function hwlGetSubsets() {
 
273
  global $wpdb;
274
 
275
  try {
276
  return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . "_subsets");
277
- } catch(\Exception $e) {
278
  return $e;
279
  }
280
  }
281
 
282
- function hwlGetFontsByFamily($family) {
 
283
  global $wpdb;
284
 
285
  try {
286
  return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . " WHERE font_family = '$family'");
287
- } catch(\Exception $e) {
288
  return $e;
289
  }
290
  }
@@ -292,34 +312,37 @@ function hwlGetFontsByFamily($family) {
292
  /**
293
  * @return \Exception|false|int
294
  */
295
- function hwlCleanQueue() {
296
- global $wpdb;
 
297
 
298
- try {
299
- $wpdb->query("TRUNCATE TABLE " . CAOS_WEBFONTS_DB_TABLENAME);
300
- $wpdb->query("TRUNCATE TABLE " . CAOS_WEBFONTS_DB_TABLENAME . "_subsets");
301
- } catch (\Exception $e) {
302
- return $e;
303
- }
304
  }
305
 
306
  /**
307
  * AJAX-wrapper for hwlGetDownloadStatus()
308
  */
309
- function hwlAjaxGetDownloadStatus() {
310
- return wp_die(
311
- json_encode(
312
- hwlGetDownloadStatus()
313
- )
314
- );
 
315
  }
316
  add_action('wp_ajax_hwlAjaxGetDownloadStatus', 'hwlAjaxGetDownloadStatus');
317
 
318
  /**
319
  * AJAX-wrapper for hwlCleanQueue()
320
  */
321
- function hwlAjaxCleanQueue() {
322
- return wp_die(hwlCleanQueue());
 
323
  }
324
  add_action('wp_ajax_hwlAjaxCleanQueue', 'hwlAjaxCleanQueue');
325
 
@@ -328,15 +351,17 @@ add_action('wp_ajax_hwlAjaxCleanQueue', 'hwlAjaxCleanQueue');
328
  *
329
  * @return array
330
  */
331
- function hwlAjaxEmptyDir() {
332
- return array_map('unlink', array_filter((array) glob(CAOS_WEBFONTS_UPLOAD_DIR . '/*')));
 
333
  }
334
  add_action('wp_ajax_hwlAjaxEmptyDir', 'hwlAjaxEmptyDir');
335
 
336
  /**
337
- * Search Subsets in Google Webfonts Helper
338
  */
339
- function hwlAjaxSearchFontSubsets() {
 
340
  try {
341
  $searchQueries = explode(',', sanitize_text_field($_POST['search_query']));
342
 
@@ -347,11 +372,11 @@ function hwlAjaxSearchFontSubsets() {
347
  $result = curl_exec($request);
348
  curl_close($request);
349
 
350
- $result = json_decode($result);
351
  $response[] = array(
352
- 'family' => $result->family,
353
- 'id' => $result->id,
354
- 'subsets' => $result->subsets
355
  );
356
  }
357
  wp_die(json_encode($response));
@@ -364,112 +389,164 @@ add_action('wp_ajax_hwlAjaxSearchFontSubsets', 'hwlAjaxSearchFontSubsets');
364
  /**
365
  * Search Fonts in Google Webfonts Helper
366
  */
367
- function hwlAjaxSearchGoogleFonts() {
368
- try {
369
- $request = curl_init();
370
- $searchQuery = sanitize_text_field($_POST['search_query']);
371
- $subsets = implode($_POST['search_subsets'], ',');
 
372
 
373
- curl_setopt($request, CURLOPT_URL, CAOS_WEBFONTS_HELPER_URL . $searchQuery . '?subsets=' . $subsets);
374
- curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
375
 
376
- $result = curl_exec($request);
377
 
378
- curl_close($request);
379
- wp_die($result);
380
- } catch (\Exception $e) {
381
- wp_die($e);
382
- }
383
  }
384
  add_action('wp_ajax_hwlAjaxSearchGoogleFonts', 'hwlAjaxSearchGoogleFonts');
385
 
386
  /**
387
  * Create cache dir upon plugin (re-)activation.
388
  */
389
- function hwlCreateCacheDir() {
390
- $uploadDir = CAOS_WEBFONTS_UPLOAD_DIR;
391
- if (!is_dir($uploadDir)) {
392
- wp_mkdir_p($uploadDir);
393
- }
 
394
  }
395
  register_activation_hook(__FILE__, 'hwlCreateCacheDir');
396
 
397
  /**
398
  * @return array
399
  */
400
- function hwlFontDisplayOptions() {
401
- $fontDisplay = array(
402
- 'Auto (default)' => 'auto',
403
- 'Block' => 'block',
404
- 'Swap' => 'swap',
405
- 'Fallback' => 'fallback',
406
- 'Optional' => 'optional'
407
- );
 
408
 
409
- return $fontDisplay;
410
  }
411
 
412
  /**
413
  * The function for generating the stylesheet and saving it to the upload-dir.
414
  */
415
- function hwlAjaxGenerateStyles() {
416
- require_once(plugin_dir_path(__FILE__) . 'includes/ajax/generate-stylesheet.php');
 
417
  }
418
  add_action('wp_ajax_hwlAjaxGenerateStyles', 'hwlAjaxGenerateStyles');
419
 
420
  /**
421
  * Saves the chosen webfonts to the database for further processing.
422
  */
423
- function hwlAjaxDownloadFonts() {
424
- require_once(plugin_dir_path(__FILE__) . 'includes/ajax/download-fonts.php');
 
425
  }
426
  add_action('wp_ajax_hwlAjaxDownloadFonts', 'hwlAjaxDownloadFonts');
427
 
428
  /**
429
  * Once the stylesheet is generated. We can enqueue it.
430
  */
431
- function hwlEnqueueStylesheet() {
432
- wp_enqueue_style('hwl-style', CAOS_WEBFONTS_UPLOAD_URL . '/' . CAOS_WEBFONTS_FILENAME, array(), (CAOS_WEBFONTS_REMOVE_VERSION) ? null : CAOS_WEBFONTS_STATIC_VERSION);
 
433
  }
434
  add_action('wp_enqueue_scripts', 'hwlEnqueueStylesheet');
435
 
436
  /**
437
  * Stylesheet and Javascript needed in Admin
438
  */
439
- function hwlEnqueueAdminJs($hook) {
440
- if ($hook == 'settings_page_optimize-webfonts') {
441
- wp_enqueue_script('hwl-admin-js', plugin_dir_url(__FILE__) . 'js/hwl-admin.js', array('jquery'), CAOS_WEBFONTS_STATIC_VERSION, true);
442
- wp_enqueue_style('hwl-admin-css', plugin_dir_url(__FILE__) . 'css/hwl-admin.css', array(), CAOS_WEBFONTS_STATIC_VERSION);
443
- }
 
444
  }
445
  add_action('admin_enqueue_scripts', 'hwlEnqueueAdminJs');
446
 
447
  /**
448
  * When plugin is deactivated. Remove all CSS and JS.
449
  */
450
- function hwlDequeueJsCss() {
451
- wp_dequeue_script('hwl-admin-js');
452
- wp_dequeue_style('hwl-admin-css');
453
- wp_dequeue_style('hwl-style');
 
454
  }
455
  register_deactivation_hook(__FILE__, 'hwlDequeueJsCss');
456
 
457
  /**
458
  * Prioritize the loading of fonts by adding a resource hint to the document head.
459
  */
460
- function hwlAddLinkPreload() {
461
- global $wp_styles;
 
462
 
463
- $handle = 'hwl-style';
464
- $sstyle = $wp_styles->registered[$handle];
465
 
466
- $source = $sstyle->src . ($sstyle->ver ? "?ver={$sstyle->ver}" : "");
467
- echo "<link rel='preload' href='{$source}' as='style' />\n";
 
 
 
468
  }
469
 
470
- function hwlIsPreloadEnabled() {
471
- if (CAOS_WEBFONTS_PRELOAD == 'on') {
472
- add_action('wp_head', 'hwlAddLinkPreload', 1);
473
- }
 
474
  }
475
  add_action('init', 'hwlIsPreloadEnabled');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
  * @formatter:off
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: 1.9.11
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
11
+ * Text Domain: host-webfonts-local
12
  * @formatter:on
13
  */
14
 
15
  // Exit if accessed directly
16
  if (!defined('ABSPATH')) {
17
+ exit;
18
  }
19
 
20
  global $wpdb;
23
  * Define constants.
24
  */
25
  define('CAOS_WEBFONTS_DB_VERSION', '1.8.3');
26
+ define('CAOS_WEBFONTS_STATIC_VERSION', '1.9.11');
27
  define('CAOS_WEBFONTS_SITE_URL', 'https://daan.dev');
28
  define('CAOS_WEBFONTS_DB_TABLENAME', $wpdb->prefix . 'caos_webfonts');
29
  define('CAOS_WEBFONTS_DB_CHARSET', $wpdb->get_charset_collate());
30
  define('CAOS_WEBFONTS_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
31
  define('CAOS_WEBFONTS_FILENAME', 'fonts.css');
32
+ define('CAOS_WEBFONTS_CACHE_DIR', esc_attr(get_option('caos_webfonts_cache_dir')) ?: '/cache/omgf-webfonts');
33
  define('CAOS_WEBFONTS_CDN_URL', esc_attr(get_option('caos_webfonts_cdn_url')));
34
  define('CAOS_WEBFONTS_REMOVE_VERSION', esc_attr(get_option('caos_webfonts_remove_version')));
35
  define('CAOS_WEBFONTS_CURRENT_BLOG_ID', get_current_blog_id());
36
  define('CAOS_WEBFONTS_UPLOAD_DIR', WP_CONTENT_DIR . CAOS_WEBFONTS_CACHE_DIR);
37
  define('CAOS_WEBFONTS_UPLOAD_URL', hwlGetUploadUrl());
38
  define('CAOS_WEBFONTS_DISPLAY_OPTION', esc_attr(get_option('caos_webfonts_display_option')) ?: 'auto');
39
+ define('CAOS_WEBFONTS_REMOVE_GFONTS', esc_attr(get_option('caos_webfonts_remove_gfonts')));
40
  define('CAOS_WEBFONTS_PRELOAD', esc_attr(get_option('caos_webfonts_preload')));
41
 
42
  /**
43
  * Register settings
44
  */
45
+ function hwlRegisterSettings()
46
+ {
47
+ register_setting('caos-webfonts-basic-settings',
48
+ 'caos_webfonts_cache_dir'
49
+ );
50
+ register_setting('caos-webfonts-basic-settings',
51
  'caos_webfonts_cdn_url'
52
  );
53
  register_setting('caos-webfonts-basic-settings',
54
  'caos_webfonts_remove_version'
55
  );
56
+ register_setting('caos-webfonts-basic-settings',
57
+ 'caos_webfonts_display_option'
58
+ );
59
+ register_setting('caos-webfonts-basic-settings',
60
+ 'caos_webfonts_remove_gfonts'
61
+ );
62
+ register_setting('caos-webfonts-basic-settings',
63
+ 'caos_webfonts_preload'
64
+ );
65
  }
66
 
67
  /**
68
  * Create the Admin menu-item
69
  */
70
+ function hwlCreateMenu()
71
+ {
72
+ add_options_page(
73
+ 'OMGF',
74
+ 'Optimize Webfonts',
75
+ 'manage_options',
76
+ 'optimize-webfonts',
77
+ 'hwlSettingsPage'
78
+ );
79
+ add_action('admin_init',
80
+ 'hwlRegisterSettings'
81
+ );
82
  }
83
  add_action('admin_menu', 'hwlCreateMenu');
84
 
87
  *
88
  * @return mixed
89
  */
90
+ function hwlGetContentDirName()
91
+ {
92
+ preg_match('/[^\/]+$/u', WP_CONTENT_DIR, $match);
93
 
94
+ return $match[0];
95
  }
96
 
97
  /**
98
+ * @return string
99
  */
100
+ function hwlGetUploadUrl()
101
+ {
102
  if (CAOS_WEBFONTS_CDN_URL) {
103
  $uploadUrl = '//' . CAOS_WEBFONTS_CDN_URL . '/' . hwlGetContentDirName() . CAOS_WEBFONTS_CACHE_DIR;
104
  } else {
111
  /**
112
  * Create table to store downloaded fonts in version 1.6.1.
113
  */
114
+ function hwlCreateWebfontsTable()
115
+ {
116
+ global $wpdb;
117
  $sql = "CREATE TABLE IF NOT EXISTS " . CAOS_WEBFONTS_DB_TABLENAME . " (
118
  font_id varchar(191) NOT NULL,
119
  font_family varchar(191) NOT NULL,
126
  url_eot varchar(191) NULL,
127
  UNIQUE KEY (font_id)
128
  ) " . CAOS_WEBFONTS_DB_CHARSET . ";";
129
+ $wpdb->query($sql);
130
 
131
+ add_option('caos_webfonts_db_version', '1.6.1');
132
  }
133
 
134
  /**
135
  * Create table to store selected subsets in version 1.7.0.
136
  */
137
+ function hwlCreateSubsetsTable()
138
+ {
139
  global $wpdb;
140
  $sql = "CREATE TABLE IF NOT EXISTS " . CAOS_WEBFONTS_DB_TABLENAME . '_subsets' . " (
141
  subset_font varchar(32) NOT NULL,
152
  /**
153
  * Adds the 'local' column in version 1.8.3
154
  */
155
+ function hwlAddLocalColumn()
156
+ {
157
  global $wpdb;
158
 
159
  $sql = "ALTER TABLE " . CAOS_WEBFONTS_DB_TABLENAME . " " .
166
  /**
167
  * Check current version and execute required db updates.
168
  */
169
+ function hwlRunDbUpdates()
170
+ {
171
+ $currentVersion = get_option('caos_webfonts_db_version') ?: '1.0.0';
172
+ if (version_compare($currentVersion, '1.6.1') < 0) {
173
+ hwlCreateWebfontsTable();
174
+ }
175
+ if (version_compare($currentVersion, '1.7.0') < 0) {
176
+ hwlCreateSubsetsTable();
177
  }
178
+ if (version_compare($currentVersion, CAOS_WEBFONTS_DB_VERSION) < 0) {
179
  hwlAddLocalColumn();
180
  }
181
  }
186
  *
187
  * @return mixed
188
  */
189
+ function hwlSettingsLink($links)
190
+ {
191
+ $adminUrl = admin_url() . 'options-general.php?page=optimize-webfonts';
192
+ $settingsLink = "<a href='$adminUrl'>" . __('Settings') . "</a>";
193
+ array_push($links, $settingsLink);
194
 
195
+ return $links;
196
  }
197
  $caosLink = plugin_basename(__FILE__);
198
 
201
  /**
202
  * Render the settings page.
203
  */
204
+ function hwlSettingsPage()
205
+ {
206
+ if (!current_user_can('manage_options')) {
207
+ wp_die(__("You're not cool enough to access this page."));
208
+ }
209
+ ?>
210
  <div class="wrap">
211
+ <h1><?php _e('OMGF | Optimize My Google Fonts', 'host-webfonts-local'); ?></h1>
212
  <p>
213
+ <?php _e('Developed by: ', 'host-webfonts-local'); ?>
214
  <a title="Buy me a beer!" href="<?php echo CAOS_WEBFONTS_SITE_URL; ?>/donate/">
215
  Daan van den Bergh</a>.
216
  </p>
217
 
218
  <div id="hwl-admin-notices"></div>
219
 
220
+ <?php require_once(dirname(__FILE__) . '/includes/templates/settings-welcome.php'); ?>
221
 
222
+ <form id="hwl-options-form" class="settings-column left" name="hwl-options-form" method="post">
223
  <div class="">
224
+ <?php
225
 
226
+ require_once(dirname(__FILE__) . '/includes/templates/settings-generate-stylesheet.php');
227
 
228
+ ?>
229
  </div>
230
  </form>
231
 
232
+ <form id="hwl-settings-form" class="settings-column right" name="hwl-settings-form" method="post" action="options.php">
233
+ <?php
234
+ settings_fields('caos-webfonts-basic-settings');
235
+ do_settings_sections('caos-webfonts-basic-settings');
236
 
237
+ require_once(dirname(__FILE__) . '/includes/templates/settings-basic-settings.php');
238
 
239
+ do_action('hwl_after_settings_form_settings');
240
 
241
  submit_button();
242
  ?>
243
  </form>
244
  </div>
245
+ <?php
246
  }
247
 
248
  /**
249
  * @return array|\Exception
250
  */
251
+ function hwlGetTotalFonts()
252
+ {
253
+ global $wpdb;
254
 
255
+ try {
256
+ return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME);
257
+ } catch (\Exception $e) {
258
+ return $e;
259
+ }
260
  }
261
 
262
  /**
263
  * @return array|\Exception
264
  */
265
+ function hwlGetDownloadedFonts()
266
+ {
267
+ global $wpdb;
268
 
269
+ try {
270
+ return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . " WHERE downloaded = 1");
271
+ } catch (\Exception $e) {
272
+ return $e;
273
+ }
274
  }
275
 
276
  /**
277
  * @return array
278
  */
279
+ function hwlGetDownloadStatus()
280
+ {
281
+ return array(
282
+ "downloaded" => count(hwlGetDownloadedFonts()),
283
+ "total" => count(hwlGetTotalFonts())
284
+ );
285
  }
286
 
287
  /**
288
+ * @return array|\Exception|null|object
289
  */
290
+ function hwlGetSubsets()
291
+ {
292
  global $wpdb;
293
 
294
  try {
295
  return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . "_subsets");
296
+ } catch (\Exception $e) {
297
  return $e;
298
  }
299
  }
300
 
301
+ function hwlGetFontsByFamily($family)
302
+ {
303
  global $wpdb;
304
 
305
  try {
306
  return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . " WHERE font_family = '$family'");
307
+ } catch (\Exception $e) {
308
  return $e;
309
  }
310
  }
312
  /**
313
  * @return \Exception|false|int
314
  */
315
+ function hwlCleanQueue()
316
+ {
317
+ global $wpdb;
318
 
319
+ try {
320
+ $wpdb->query("TRUNCATE TABLE " . CAOS_WEBFONTS_DB_TABLENAME);
321
+ $wpdb->query("TRUNCATE TABLE " . CAOS_WEBFONTS_DB_TABLENAME . "_subsets");
322
+ } catch (\Exception $e) {
323
+ return $e;
324
+ }
325
  }
326
 
327
  /**
328
  * AJAX-wrapper for hwlGetDownloadStatus()
329
  */
330
+ function hwlAjaxGetDownloadStatus()
331
+ {
332
+ return wp_die(
333
+ json_encode(
334
+ hwlGetDownloadStatus()
335
+ )
336
+ );
337
  }
338
  add_action('wp_ajax_hwlAjaxGetDownloadStatus', 'hwlAjaxGetDownloadStatus');
339
 
340
  /**
341
  * AJAX-wrapper for hwlCleanQueue()
342
  */
343
+ function hwlAjaxCleanQueue()
344
+ {
345
+ return wp_die(hwlCleanQueue());
346
  }
347
  add_action('wp_ajax_hwlAjaxCleanQueue', 'hwlAjaxCleanQueue');
348
 
351
  *
352
  * @return array
353
  */
354
+ function hwlAjaxEmptyDir()
355
+ {
356
+ return array_map('unlink', array_filter((array) glob(CAOS_WEBFONTS_UPLOAD_DIR . '/*')));
357
  }
358
  add_action('wp_ajax_hwlAjaxEmptyDir', 'hwlAjaxEmptyDir');
359
 
360
  /**
361
+ * Search Subsets in Google Webfonts Helper
362
  */
363
+ function hwlAjaxSearchFontSubsets()
364
+ {
365
  try {
366
  $searchQueries = explode(',', sanitize_text_field($_POST['search_query']));
367
 
372
  $result = curl_exec($request);
373
  curl_close($request);
374
 
375
+ $result = json_decode($result);
376
  $response[] = array(
377
+ 'family' => $result->family,
378
+ 'id' => $result->id,
379
+ 'subsets' => $result->subsets
380
  );
381
  }
382
  wp_die(json_encode($response));
389
  /**
390
  * Search Fonts in Google Webfonts Helper
391
  */
392
+ function hwlAjaxSearchGoogleFonts()
393
+ {
394
+ try {
395
+ $request = curl_init();
396
+ $searchQuery = sanitize_text_field($_POST['search_query']);
397
+ $subsets = implode($_POST['search_subsets'], ',');
398
 
399
+ curl_setopt($request, CURLOPT_URL, CAOS_WEBFONTS_HELPER_URL . $searchQuery . '?subsets=' . $subsets);
400
+ curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
401
 
402
+ $result = curl_exec($request);
403
 
404
+ curl_close($request);
405
+ wp_die($result);
406
+ } catch (\Exception $e) {
407
+ wp_die($e);
408
+ }
409
  }
410
  add_action('wp_ajax_hwlAjaxSearchGoogleFonts', 'hwlAjaxSearchGoogleFonts');
411
 
412
  /**
413
  * Create cache dir upon plugin (re-)activation.
414
  */
415
+ function hwlCreateCacheDir()
416
+ {
417
+ $uploadDir = CAOS_WEBFONTS_UPLOAD_DIR;
418
+ if (!is_dir($uploadDir)) {
419
+ wp_mkdir_p($uploadDir);
420
+ }
421
  }
422
  register_activation_hook(__FILE__, 'hwlCreateCacheDir');
423
 
424
  /**
425
  * @return array
426
  */
427
+ function hwlFontDisplayOptions()
428
+ {
429
+ $fontDisplay = array(
430
+ __('Auto (default)', 'host-webfonts-local') => 'auto',
431
+ __('Block', 'host-webfonts-local') => 'block',
432
+ __('Swap', 'host-webfonts-local') => 'swap',
433
+ __('Fallback', 'host-webfonts-local') => 'fallback',
434
+ __('Optional', 'host-webfonts-local') => 'optional'
435
+ );
436
 
437
+ return $fontDisplay;
438
  }
439
 
440
  /**
441
  * The function for generating the stylesheet and saving it to the upload-dir.
442
  */
443
+ function hwlAjaxGenerateStyles()
444
+ {
445
+ require_once(plugin_dir_path(__FILE__) . 'includes/ajax/generate-stylesheet.php');
446
  }
447
  add_action('wp_ajax_hwlAjaxGenerateStyles', 'hwlAjaxGenerateStyles');
448
 
449
  /**
450
  * Saves the chosen webfonts to the database for further processing.
451
  */
452
+ function hwlAjaxDownloadFonts()
453
+ {
454
+ require_once(plugin_dir_path(__FILE__) . 'includes/ajax/download-fonts.php');
455
  }
456
  add_action('wp_ajax_hwlAjaxDownloadFonts', 'hwlAjaxDownloadFonts');
457
 
458
  /**
459
  * Once the stylesheet is generated. We can enqueue it.
460
  */
461
+ function hwlEnqueueStylesheet()
462
+ {
463
+ wp_enqueue_style('omgf-fonts', CAOS_WEBFONTS_UPLOAD_URL . '/' . CAOS_WEBFONTS_FILENAME, array(), (CAOS_WEBFONTS_REMOVE_VERSION) ? null : CAOS_WEBFONTS_STATIC_VERSION);
464
  }
465
  add_action('wp_enqueue_scripts', 'hwlEnqueueStylesheet');
466
 
467
  /**
468
  * Stylesheet and Javascript needed in Admin
469
  */
470
+ function hwlEnqueueAdminJs($hook)
471
+ {
472
+ if ($hook == 'settings_page_optimize-webfonts') {
473
+ wp_enqueue_script('hwl-admin-js', plugin_dir_url(__FILE__) . 'js/hwl-admin.js', array('jquery'), CAOS_WEBFONTS_STATIC_VERSION, true);
474
+ wp_enqueue_style('hwl-admin-css', plugin_dir_url(__FILE__) . 'css/hwl-admin.css', array(), CAOS_WEBFONTS_STATIC_VERSION);
475
+ }
476
  }
477
  add_action('admin_enqueue_scripts', 'hwlEnqueueAdminJs');
478
 
479
  /**
480
  * When plugin is deactivated. Remove all CSS and JS.
481
  */
482
+ function hwlDequeueJsCss()
483
+ {
484
+ wp_dequeue_script('hwl-admin-js');
485
+ wp_dequeue_style('hwl-admin-css');
486
+ wp_dequeue_style('omgf-fonts');
487
  }
488
  register_deactivation_hook(__FILE__, 'hwlDequeueJsCss');
489
 
490
  /**
491
  * Prioritize the loading of fonts by adding a resource hint to the document head.
492
  */
493
+ function hwlAddLinkPreload()
494
+ {
495
+ global $wp_styles;
496
 
497
+ $handle = 'omgf-fonts';
498
+ $style = $wp_styles->registered[$handle];
499
 
500
+ /** Do not add 'preload' if Minification plugins are enabled. */
501
+ if ($style) {
502
+ $source = $style->src . ($style->ver ? "?ver={$style->ver}" : "");
503
+ echo "<link rel='preload' href='{$source}' as='style' />\n";
504
+ }
505
  }
506
 
507
+ function hwlIsPreloadEnabled()
508
+ {
509
+ if (CAOS_WEBFONTS_PRELOAD == 'on') {
510
+ add_action('wp_head', 'hwlAddLinkPreload', 1);
511
+ }
512
  }
513
  add_action('init', 'hwlIsPreloadEnabled');
514
+
515
+ /**
516
+ * Automatically dequeues any stylesheets loaded from fonts.gstatic.com or
517
+ * fonts.googleapis.com. Also checks for stylesheets dependant on Google Fonts and
518
+ * re-enqueues and registers them.
519
+ */
520
+ function hwlRemoveGoogleFonts()
521
+ {
522
+ global $wp_styles;
523
+
524
+ $registered = $wp_styles->registered;
525
+
526
+ $fonts = array_filter($registered, function ($contents) {
527
+ return strpos($contents->src, 'fonts.googleapis.com') !== false
528
+ || strpos($contents->src, 'fonts.gstatic.com') !== false;
529
+ });
530
+
531
+ $dependencies = array_filter($registered, function ($contents) use ($fonts) {
532
+ return !empty(array_intersect(array_keys($fonts), $contents->deps));
533
+ });
534
+
535
+ foreach ($fonts as $font) {
536
+ wp_deregister_style($font->handle);
537
+ wp_dequeue_style($font->handle);
538
+ }
539
+
540
+ foreach ($dependencies as $dependency) {
541
+ wp_register_style('omgf-dep-' . $dependency->handle, $dependency->src);
542
+ wp_enqueue_style('omgf-dep-' . $dependency->handle, $dependency->src);
543
+ }
544
+ }
545
+
546
+ function hwlIsRemoveGoogleFontsEnabled()
547
+ {
548
+ if (CAOS_WEBFONTS_REMOVE_GFONTS == 'on' && !is_admin()) {
549
+ add_action('wp_print_styles', 'hwlRemoveGoogleFonts', PHP_INT_MAX);
550
+ }
551
+ }
552
+ add_action('init', 'hwlIsRemoveGoogleFontsEnabled');
includes/ajax/download-fonts.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * @package: CAOS for Webfonts
4
  * @author: Daan van den Bergh
5
  * @copyright: (c) 2019 Daan van den Bergh
6
  * @url: https://daan.dev
1
  <?php
2
  /**
3
+ * @package: OMGF
4
  * @author: Daan van den Bergh
5
  * @copyright: (c) 2019 Daan van den Bergh
6
  * @url: https://daan.dev
includes/ajax/generate-stylesheet.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * @package: CAOS for Webfonts
4
  * @author: Daan van den Bergh
5
  * @copyright: (c) 2019 Daan van den Bergh
6
  * @url: https://daan.dev
@@ -26,7 +26,7 @@ if (!current_user_can('manage_options'))
26
  * Insert promotional material :)
27
  */
28
  $fonts[] = "
29
- /** This file is automagically generated by CAOS for Webfonts
30
  *
31
  * @author: Daan van den Bergh
32
  * @copyright: (c) 2019 Daan van den Bergh
1
  <?php
2
  /**
3
+ * @package: OMGF
4
  * @author: Daan van den Bergh
5
  * @copyright: (c) 2019 Daan van den Bergh
6
  * @url: https://daan.dev
26
  * Insert promotional material :)
27
  */
28
  $fonts[] = "
29
+ /** This file is automagically generated by OMGF
30
  *
31
  * @author: Daan van den Bergh
32
  * @copyright: (c) 2019 Daan van den Bergh
includes/{caos-webfonts-basic-settings.php → templates/settings-basic-settings.php} RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * @package: CAOS for Webfonts
4
  * @author: Daan van den Bergh
5
  * @copyright: (c) 2019 Daan van den Bergh
6
  * @url: https://daan.dev
@@ -10,7 +10,7 @@
10
  if (!defined( 'ABSPATH')) exit;
11
  ?>
12
  <div class="">
13
- <h3><?php _e('Basic Settings'); ?></h3>
14
  <p class="description">
15
  <?php _e('Do not forget to re-generate the stylesheet after changing settings.', 'host-webfonts-local'); ?>
16
  </p>
@@ -25,9 +25,9 @@ if (!defined( 'ABSPATH')) exit;
25
  </label>
26
  </th>
27
  <td>
28
- <input id="caos_webfonts_cache_dir" 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; ?>" />
29
  <p class="description">
30
- <?php _e("Changes the path where webfonts are cached inside WordPress' content directory (usually <code>wp-content</code>). Defaults to <code>/cache/caos-webfonts</code>.*", 'host-webfonts-local'); ?>
31
  </p>
32
  </td>
33
  </tr>
@@ -38,7 +38,7 @@ if (!defined( 'ABSPATH')) exit;
38
  </label>
39
  </th>
40
  <td>
41
- <input id="caos_webfonts_cdn_url" class="caos_webfonts_cdn_url" type="text" name="caos_webfonts_cdn_url" placeholder="e.g. cdn.mydomain.com" value="<?= CAOS_WEBFONTS_CDN_URL; ?>" />
42
  <p class="description">
43
  <?php _e("Are you using a CDN? Then enter the URL here.*", 'host-webfonts-local'); ?>
44
  </p>
@@ -67,7 +67,7 @@ if (!defined( 'ABSPATH')) exit;
67
  <?php $fontDisplay = hwlFontDisplayOptions(); ?>
68
  <select id="caos_webfonts_display_option" name="caos_webfonts_display_option">
69
  <?php foreach ($fontDisplay as $label => $value): ?>
70
- <option value="<?php echo $value; ?>" <?php echo $value == CAOS_WEBFONTS_DISPLAY_OPTION ? 'selected' : ''; ?>><?php _e($label, 'host-webfonts-local'); ?></option>
71
  <?php endforeach; ?>
72
  </select>
73
  <br/>
@@ -77,6 +77,19 @@ if (!defined( 'ABSPATH')) exit;
77
  </p>
78
  </td>
79
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  <tr valign="top">
81
  <th scope="row">
82
  <label for="caos_webfonts_preload">
@@ -84,9 +97,9 @@ if (!defined( 'ABSPATH')) exit;
84
  </label>
85
  </th>
86
  <td>
87
- <input class="caos_webfonts_preload" id="caos_webfonts_preload" type="checkbox" name="caos_webfonts_preload" <?php echo CAOS_WEBFONTS_PRELOAD == 'on' ? 'checked = "checked"' : ''; ?> />
88
  <p class="description">
89
- <?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>
90
  </p>
91
  </td>
92
  </tr>
1
  <?php
2
  /**
3
+ * @package: OMGF
4
  * @author: Daan van den Bergh
5
  * @copyright: (c) 2019 Daan van den Bergh
6
  * @url: https://daan.dev
10
  if (!defined( 'ABSPATH')) exit;
11
  ?>
12
  <div class="">
13
+ <h3><?php _e('Basic Settings', 'host-webfonts-local'); ?></h3>
14
  <p class="description">
15
  <?php _e('Do not forget to re-generate the stylesheet after changing settings.', 'host-webfonts-local'); ?>
16
  </p>
25
  </label>
26
  </th>
27
  <td>
28
+ <input id="caos_webfonts_cache_dir" class="caos_webfonts_cache_dir" type="text" name="caos_webfonts_cache_dir" placeholder="<?= __('e.g. /cache/omgf-webfonts', 'host-webfonts-local'); ?>" value="<?= CAOS_WEBFONTS_CACHE_DIR; ?>" />
29
  <p class="description">
30
+ <?php _e("Changes the path where webfonts are cached inside WordPress' content directory (usually <code>wp-content</code>). If you're using Multisite, give each site a unique cache directory path. Defaults to <code>/cache/caos-webfonts</code>.*", 'host-webfonts-local'); ?>
31
  </p>
32
  </td>
33
  </tr>
38
  </label>
39
  </th>
40
  <td>
41
+ <input id="caos_webfonts_cdn_url" class="caos_webfonts_cdn_url" type="text" name="caos_webfonts_cdn_url" placeholder="<?= __('e.g. cdn.mydomain.com', 'host-webfonts-local'); ?>" value="<?= CAOS_WEBFONTS_CDN_URL; ?>" />
42
  <p class="description">
43
  <?php _e("Are you using a CDN? Then enter the URL here.*", 'host-webfonts-local'); ?>
44
  </p>
67
  <?php $fontDisplay = hwlFontDisplayOptions(); ?>
68
  <select id="caos_webfonts_display_option" name="caos_webfonts_display_option">
69
  <?php foreach ($fontDisplay as $label => $value): ?>
70
+ <option value="<?= $value; ?>" <?= $value == CAOS_WEBFONTS_DISPLAY_OPTION ? 'selected' : ''; ?>><?php _e($label, 'host-webfonts-local'); ?></option>
71
  <?php endforeach; ?>
72
  </select>
73
  <br/>
77
  </p>
78
  </td>
79
  </tr>
80
+ <tr valign="top">
81
+ <th scope="row">
82
+ <label for="caos_webfonts_remove_gfonts">
83
+ <?php _e('Remove Google Fonts (experimental)', 'host-webfonts-local'); ?>
84
+ </label>
85
+ </th>
86
+ <td>
87
+ <input class="caos_webfonts_remove_gfonts" id="caos_webfonts_remove_gfonts" type="checkbox" name="caos_webfonts_remove_gfonts" <?= CAOS_WEBFONTS_REMOVE_GFONTS == 'on' ? 'checked = "checked"' : ''; ?> />
88
+ <p class="description">
89
+ <?= sprintf(__('Enabling this option will attempt to remove any externally hosted Google Fonts-stylesheets from your WordPress-blog. If it doesn\'t work for you, click %shere%s for a more comprehensive guide.', 'host-webfonts-local'), '<a target="_blank" href="' . CAOS_WEBFONTS_SITE_URL . '/how-to/remove-google-fonts-wordpress">', '</a>'); ?>
90
+ </p>
91
+ </td>
92
+ </tr>
93
  <tr valign="top">
94
  <th scope="row">
95
  <label for="caos_webfonts_preload">
97
  </label>
98
  </th>
99
  <td>
100
+ <input class="caos_webfonts_preload" id="caos_webfonts_preload" type="checkbox" name="caos_webfonts_preload" <?= CAOS_WEBFONTS_PRELOAD == 'on' ? 'checked = "checked"' : ''; ?> />
101
  <p class="description">
102
+ <?php _e('Leave this disabled if you\'re using a CSS minification plugin, such as Autoptimize or W3 Total Cache.', '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>
103
  </p>
104
  </td>
105
  </tr>
includes/{caos-webfonts-style-generation.php → templates/settings-generate-stylesheet.php} RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * @package : CAOS for Webfonts
4
  * @author : Daan van den Bergh
5
  * @copyright: (c) 2019 Daan van den Bergh
6
  * @url : https://daan.dev
@@ -12,7 +12,7 @@ if (!defined('ABSPATH')) {
12
  }
13
  ?>
14
  <div class="">
15
- <h3><?php _e('Generate Stylesheet'); ?></h3>
16
  <p class="description">
17
  <?php _e('Search for fonts using a comma-separated list (e.g. Open Sans,Roboto,Poppins) and click \'Search\'.', 'host-webfonts-local'); ?>
18
  </p>
@@ -58,7 +58,7 @@ if (!defined('ABSPATH')) {
58
  </table>
59
  <table>
60
  <tr valign="top">
61
- <th align="left" colspan="3">Available fonts</th>
62
  </tr>
63
  </table>
64
  <table align="left" id="hwl-results">
@@ -94,7 +94,7 @@ if (!defined('ABSPATH')) {
94
  <input type="hidden" value="<?= $font->url_eot; ?>" name="<?= $arrayPath; ?>[url][eot]"/>
95
  <div class="hwl-remove">
96
  <a onclick="hwlRemoveRow('row-<?= $fontId; ?>')">
97
- <small>remove</small>
98
  </a>
99
  </div>
100
  </td>
@@ -110,7 +110,7 @@ if (!defined('ABSPATH')) {
110
  </td>
111
  </tr>
112
  <tr class="error" style="display: none;">
113
- <td colspan="3" align="center">No fonts available.</td>
114
  </tr>
115
  </tbody>
116
  </table>
@@ -120,19 +120,19 @@ if (!defined('ABSPATH')) {
120
  <tr valign="center" align="center">
121
  <td>
122
  <input type="button" onclick="hwlDownloadFonts()" name="save-btn"
123
- id="save-btn" class="button-primary" value="Download Fonts"/>
124
  </td>
125
  <td>
126
  <input type="button" onclick="hwlGenerateStylesheet()" name="generate-btn"
127
- id="generate-btn" class="button-secondary" value="Generate Stylesheet"/>
128
  </td>
129
  <td>
130
  <a onclick="hwlCleanQueue()" name="clean-btn"
131
- id="clean-btn" class="button-cancel">Clean Queue</a>
132
  </td>
133
  <td>
134
  <a onclick="hwlEmptyDir()" name="empty-btn"
135
- id="empty-btn" class="button-cancel">Empty Cache Directory</a>
136
  </td>
137
  <td width="20%"></td>
138
  </tr>
1
  <?php
2
  /**
3
+ * @package : OMGF
4
  * @author : Daan van den Bergh
5
  * @copyright: (c) 2019 Daan van den Bergh
6
  * @url : https://daan.dev
12
  }
13
  ?>
14
  <div class="">
15
+ <h3><?php _e('Generate Stylesheet', 'host-webfonts-local'); ?></h3>
16
  <p class="description">
17
  <?php _e('Search for fonts using a comma-separated list (e.g. Open Sans,Roboto,Poppins) and click \'Search\'.', 'host-webfonts-local'); ?>
18
  </p>
58
  </table>
59
  <table>
60
  <tr valign="top">
61
+ <th align="left" colspan="3"><?php _e('Available fonts', 'host-webfonts-local'); ?></th>
62
  </tr>
63
  </table>
64
  <table align="left" id="hwl-results">
94
  <input type="hidden" value="<?= $font->url_eot; ?>" name="<?= $arrayPath; ?>[url][eot]"/>
95
  <div class="hwl-remove">
96
  <a onclick="hwlRemoveRow('row-<?= $fontId; ?>')">
97
+ <small><?php _e('remove', 'host-webfonts-local'); ?></small>
98
  </a>
99
  </div>
100
  </td>
110
  </td>
111
  </tr>
112
  <tr class="error" style="display: none;">
113
+ <td colspan="3" align="center"><?php _e('No fonts available.', 'host-webfonts-local'); ?></td>
114
  </tr>
115
  </tbody>
116
  </table>
120
  <tr valign="center" align="center">
121
  <td>
122
  <input type="button" onclick="hwlDownloadFonts()" name="save-btn"
123
+ id="save-btn" class="button-primary" value="<?php _e('Download Fonts', 'host-webfonts-local'); ?>"/>
124
  </td>
125
  <td>
126
  <input type="button" onclick="hwlGenerateStylesheet()" name="generate-btn"
127
+ id="generate-btn" class="button-secondary" value="<?php _e('Generate Stylesheet', 'host-webfonts-local'); ?>"/>
128
  </td>
129
  <td>
130
  <a onclick="hwlCleanQueue()" name="clean-btn"
131
+ id="clean-btn" class="button-cancel"><?php _e('Clean Queue', 'host-webfonts-local'); ?></a>
132
  </td>
133
  <td>
134
  <a onclick="hwlEmptyDir()" name="empty-btn"
135
+ id="empty-btn" class="button-cancel"><?php _e('Empty Cache Directory', 'host-webfonts-local'); ?></a>
136
  </td>
137
  <td width="20%"></td>
138
  </tr>
includes/templates/settings-welcome.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package : OMGF
4
+ * @author : Daan van den Bergh
5
+ * @copyright: (c) 2019 Daan van den Bergh
6
+ * @url : https://daan.dev
7
+ */
8
+
9
+ // Exit if accessed directly
10
+ if (!defined('ABSPATH')) {
11
+ exit;
12
+ }
13
+ ?>
14
+ <div id="welcome-panel" class="welcome-panel">
15
+ <div class="welcome-panel-content">
16
+ <h2><?php _e('Thank you for using OMGF!', 'host-webfonts-local'); ?></h2>
17
+ <p class="about-description">
18
+ <?php _e(
19
+ 'OMGF automagically downloads and saves the fonts you want to use inside Wordpress\' content-folder, generates a stylesheet for them and enqueues it in your theme\'s header. This will decrease your pageload times, leverage your browser cache, minimize external requests and effectively bring you a perfect score on Pagespeed Insights and Pingdom.',
20
+ 'host-webfonts-local'
21
+ ); ?>
22
+ </p>
23
+ <div class="welcome-panel-column-container">
24
+ <div class="welcome-panel-column" style="width: 32%;">
25
+ <h3><?php _e( 'Quickstart', 'host-webfonts-local') ;?></h3>
26
+ <ul>
27
+ <li class="welcome-icon dashicons-before dashicons-editor-bold"><?= sprintf(__('For all available fonts, check out %sGoogle Fonts%s', 'host-webfonts-local'), '<a href="https://fonts.google.com/" target="_blank">','</a>'); ?></li>
28
+ <li class="welcome-icon dashicons-before dashicons-cloud"><?php _e('Search for for your fonts', 'host-webfonts-local'); ?></li>
29
+ <li class="welcome-icon dashicons-before dashicons-admin-settings"><?php _e('Select the subsets you need', 'host-webfonts-local'); ?></li>
30
+ <li class="welcome-icon dashicons-before dashicons-admin-tools"><?php _e('Modify the list by removing the fonts you don\'t use', '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>
36
+ </ul>
37
+ <p>
38
+ <?= sprintf(__('%sClick here%s for a more comprehensive guide.', 'host-webfonts-local'), '<a target="_blank" href="' . CAOS_WEBFONTS_SITE_URL . '/wordpress/host-google-fonts-locally/">', '</a>'); ?>
39
+ </p>
40
+ </div>
41
+ <div class="welcome-panel-column" style="width: 32%;">
42
+ <h3><?php _e('Get a Perfect Score on Pagespeed & Pingdom!', 'host-webfonts-local'); ?></h3>
43
+ <p><?= sprintf(__('%sLeverage your browser cache%s and
44
+ %slower pageload times%s by hosting analytics.js locally with
45
+ %sCAOS%s.', 'host-webfonts-local'), '<strong>', '</strong>', '<strong>', '</strong>', '<a href="' . CAOS_WEBFONTS_SITE_URL . '/wordpress-plugins/optimize-analytics-wordpress/" target="_blank">', '</a>'); ?>
46
+ </p>
47
+ <p>
48
+ <a target="_blank" href="https://wordpress.org/plugins/host-analyticsjs-local"><?php _e('Download now', 'host-webfonts-local'); ?></a>
49
+ </p>
50
+ <h3><?php _e('Want to Host other Files Locally?', 'host-webfonts-local'); ?></h3>
51
+ <p><?php _e('Unleash your site\'s true potential by locally hosting as many files as possible.', 'host-webfonts-local'); ?></p>
52
+ <p>
53
+ <a target="_blank" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/how-to/host-js-locally-crontab/"><?php _e('Read more', 'host-webfonts-local'); ?></a>
54
+ </p>
55
+ </div>
56
+ <div class="welcome-panel-column welcome-panel-last" style="width: 34%;">
57
+ <h3>
58
+ <?php _e('Need Help?', 'host-webfonts-local'); ?>
59
+ </h3>
60
+ <p>
61
+ <?php _e('Thank you for using OMGF.', 'host-webfonts-local'); ?>
62
+ </p>
63
+ <p>
64
+ <?= 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="' . CAOS_WEBFONTS_SITE_URL . '/how-to/" target="_blank">', '</a>'); ?>
65
+ </p>
66
+ <p>
67
+ <?= 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="' . CAOS_WEBFONTS_SITE_URL . '/donate" target="_blank">', '</a>', '<a target="_blank" href="https://wordpress.org/support/plugin/host-analyticsjs-local/reviews/?rate=5#new-post">', '</a>'); ?>
68
+ </p>
69
+ <p>
70
+
71
+ <?= 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="' . CAOS_WEBFONTS_SITE_URL . '/wordpress/host-google-fonts-locally/" 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>'); ?>
72
+ </p>
73
+ <p>
74
+ <a target="_blank" class="button button-primary button-hero" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/donate/"><span class="dashicons-before dashicons-heart"> <?php _e('Donate', 'host-webfonts-local'); ?></span></a>
75
+ <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>
76
+ <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>
77
+ </p>
78
+ </div>
79
+ </div>
80
+ </div>
81
+ </div>
includes/welcome-panel.php DELETED
@@ -1,67 +0,0 @@
1
- <?php
2
- /**
3
- * @package: CAOS for Webfonts
4
- * @author: Daan van den Bergh
5
- * @copyright: (c) 2019 Daan van den Bergh
6
- * @url: https://daan.dev
7
- */
8
-
9
- // Exit if accessed directly
10
- if (!defined('ABSPATH')) exit;
11
- ?>
12
- <div id="welcome-panel" class="welcome-panel">
13
- <div class="welcome-panel-content">
14
- <h2>Thank you for using CAOS for Webfonts!</h2>
15
- <p class="about-description">
16
- CAOS for Webfonts automagically downloads and saves the fonts you want to use inside Wordpress' content-folder, generates a stylesheet for them and enqueues it in your theme's header.
17
- This will decrease your pageload times, leverage your browser cache, minimize external requests and effectively bring you a perfect score on Pagespeed Insights and Pingdom.
18
- </p>
19
- <div class="welcome-panel-column-container">
20
- <div class="welcome-panel-column" style="width: 32%;">
21
- <h3>Quickstart</h3>
22
- <ul>
23
- <li class="welcome-icon dashicons-before dashicons-editor-bold">For all available fonts, check out <a href="https://fonts.google.com/" target="_blank">Google Fonts</a></li>
24
- <li class="welcome-icon dashicons-before dashicons-cloud">Search for for your fonts</li>
25
- <li class="welcome-icon dashicons-before dashicons-admin-settings">Select the subsets you need</li>
26
- <li class="welcome-icon dashicons-before dashicons-admin-tools">Modify the list by removing the fonts you don't need/want</li>
27
- <li class="welcome-icon dashicons-before dashicons-update">Click 'Download Fonts' and wait for the download to complete</li>
28
- <li class="welcome-icon dashicons-before dashicons-art">Click 'Generate Stylesheet' and wait for the process to complete</li>
29
- <li class="welcome-icon dashicons-before dashicons-media-text">The stylesheet is generated and added to your theme's header</li>
30
- <li class="welcome-icon dashicons-before dashicons-editor-removeformatting">To <i>remove externally hosted Google Fonts</i>, read <a target="_blank" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/how-to/remove-google-fonts-wordpress">this</a>.</li>
31
- <li class="welcome-icon dashicons-before dashicons-smiley">Done!</li>
32
- </ul>
33
- <p><a target="_blank" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/wordpress/host-google-fonts-locally/">Click here</a> for a more comprehensive guide.</p>
34
- </div>
35
- <div class="welcome-panel-column" style="width: 32%;">
36
- <h3>Get a Perfect Score on Pagespeed & Pingdom!</h3>
37
- <p><strong>Leverage your browser cache</strong> and <strong>lower pageload times</strong> by hosting analytics.js locally with <a href="<?= CAOS_WEBFONTS_SITE_URL; ?>/wordpress-plugins/optimize-analytics-wordpress/" target="_blank">CAOS for Analytics</a>.</p>
38
- <p><a target="_blank" href="https://wordpress.org/plugins/host-analyticsjs-local">Download now</a></p>
39
- <h3>Want to Host other Files Locally?</h3>
40
- <p>Unleash your site's true potential by locally hosting as many files as possible.</p>
41
- <p><a target="_blank" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/how-to/host-js-locally-crontab/">Read more</a></p>
42
- </div>
43
- <div class="welcome-panel-column welcome-panel-last" style="width: 34%;">
44
- <h3>
45
- <?php _e('Need Help?', 'host-webfonts-local'); ?>
46
- </h3>
47
- <p>
48
- <?php _e('Thank you for using CAOS for Webfonts.', 'host-webfonts-local'); ?>
49
- </p>
50
- <p>
51
- <?php _e('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 <a href="' . CAOS_WEBFONTS_SITE_URL . '/how-to/" target="_blank">tutorials</a> on my blog.', 'host-webfonts-local'); ?>
52
- </p>
53
- <p>
54
- <?php _e("However, my time is just as valuable as yours. Consider supporting me by either <a href='" . CAOS_WEBFONTS_SITE_URL . "/donate' target='_blank'>donating</a> or leaving a <a target='_blank' href='https://wordpress.org/support/plugin/host-analyticsjs-local/reviews/?rate=5#new-post'>5-star review</a> on Wordpress.org.", 'host-webfonts-local'); ?>
55
- </p>
56
- <p>
57
- <?php _e('If you\'re running into any issues, please make sure you\'ve read <a href="' . CAOS_WEBFONTS_SITE_URL . '/wordpress-plugins/optimize-analytics-wordpress/" target="_blank">the manual</a> thoroughly. Visit the <a href="https://wordpress.org/plugins/host-analyticsjs-local/#description" target="_blank">FAQ</a> and <a href="https://wordpress.org/support/plugin/host-analyticsjs-local">Support Forum</a> to see if your question has already been answered. If not, ask a question on the Support Forum.', 'host-webfonts-local'); ?>
58
- </p>
59
- <p>
60
- <a target="_blank" class="button button-primary button-hero" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/donate/"><span class="dashicons-before dashicons-heart"> <?php _e('Donate', 'host-webfonts-local'); ?></span></a>
61
- <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>
62
- <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>
63
- </p>
64
- </div>
65
- </div>
66
- </div>
67
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/hwl-admin.js CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * @package: CAOS for Webfonts
3
  * @author: Daan van den Bergh
4
  * @copyright: (c) 2019 Daan van den Bergh
5
  * @url: https://daan.dev
1
  /**
2
+ * @package: OMGF
3
  * @author: Daan van den Bergh
4
  * @copyright: (c) 2019 Daan van den Bergh
5
  * @url: https://daan.dev
readme.md CHANGED
@@ -1,12 +1,12 @@
1
- # CAOS for Webfonts | Host Google Fonts Locally
2
 
3
- With only 2 clicks of a button, CAOS for Webfonts automagically downloads your Google Fonts you want to WordPress' content-folder, generates a stylesheet for it and enqueues it in your theme's header.
4
 
5
  ## Description
6
 
7
- CAOS for Webfonts is written with performance in mind. Other plugins make repeated requests to your Blog's database to replace/remove requests to external Webfonts source (e.g. Google Fonts) on-the-fly. This might be user-friendly, but it's a performance killer, because locally hosting your Google Webfonts should be a set-and-forget feature. The source of your webfonts should be replaced once and kept that way.
8
 
9
- That's why I kept CAOS for Webfonts small and useful. It uses the Google Fonts Helper API to automagically download the fonts you want to WordPress' contents folder and generate a stylesheet for it. The stylesheet is automatically included to your site's header and 100% compatible with plugins like Autoptimize or W3 Total Cache. After that, all you need to do is remove any mention of requests to external webfont sources (using e.g. a child theme) and you're done!
10
 
11
  This will *decrease your pageload times*, *leverage browser cache*, *minimize DNS requests* and effectively bring you a perfect score on *Pagespeed Insights* and *Pingdom*, without taking toll on the performance of your webserver.
12
 
@@ -21,7 +21,7 @@ This will *decrease your pageload times*, *leverage browser cache*, *minimize DN
21
 
22
  1. From your WordPress administrator area, go to *Plugins > Add New*
23
  1. Search for 'Daan van den Bergh'
24
- 1. Click the 'Install' button next to *CAOS for Webfonts | Host Google Fonts Locally*
25
  1. Click 'Activate'
26
 
27
  ## Frequently Asked Questions
1
+ # OMGF | Host Google Fonts Locally
2
 
3
+ With only 2 clicks of a button, OMGF automagically downloads your Google Fonts you want to WordPress' content-folder, generates a stylesheet for it and enqueues it in your theme's header.
4
 
5
  ## Description
6
 
7
+ OMGF (Optimize My Google Fonts) is written with performance in mind. Other plugins make repeated requests to your Blog's database to replace/remove requests to external Webfonts source (e.g. Google Fonts) on-the-fly. This might be user-friendly, but it's a performance killer, because locally hosting your Google Webfonts should be a set-and-forget feature. The source of your webfonts should be replaced once and kept that way.
8
 
9
+ That's why I kept OMGF small and useful. It uses the Google Fonts Helper API to automagically download the fonts you want to WordPress' contents folder and generate a stylesheet for it. The stylesheet is automatically included to your site's header and 100% compatible with plugins like Autoptimize or W3 Total Cache. After that, all you need to do is remove any mention of requests to external webfont sources (using e.g. a child theme) and you're done!
10
 
11
  This will *decrease your pageload times*, *leverage browser cache*, *minimize DNS requests* and effectively bring you a perfect score on *Pagespeed Insights* and *Pingdom*, without taking toll on the performance of your webserver.
12
 
21
 
22
  1. From your WordPress administrator area, go to *Plugins > Add New*
23
  1. Search for 'Daan van den Bergh'
24
+ 1. Click the 'Install' button next to *OMGF | Host Google Fonts Locally*
25
  1. Click 'Activate'
26
 
27
  ## Frequently Asked Questions
readme.txt CHANGED
@@ -1,31 +1,36 @@
1
- === CAOS for Webfonts | Host Google Fonts Locally ===
2
  Contributors: DaanvandenBergh
3
  Donate link: https://daan.dev/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.2
7
- Stable tag: 1.8.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- With only 2 clicks of a button, CAOS for Webfonts automagically downloads your Google Fonts you want to WordPress' content-folder, generates a stylesheet for it and enqueues it in your theme's header.
12
 
13
  == Description ==
14
 
15
- CAOS for Webfonts is written with performance in mind. Other plugins make repeated requests to your Blog's database to replace/remove requests to external Webfonts source (e.g. Google Fonts) on-the-fly. This might be user-friendly, but it's a performance killer, because locally hosting your Google Webfonts should be a set-and-forget feature. The source of your webfonts should be replaced once and kept that way.
16
 
17
- That's why I kept CAOS for Webfonts small and useful. It uses the Google Fonts Helper API to automagically download the fonts you want to WordPress' contents folder and generate a stylesheet for it. The stylesheet is automatically included to your site's header and 100% compatible with plugins like Autoptimize or W3 Total Cache. After that, all you need to do is remove any mention of requests to external webfont sources (using e.g. a child theme or a plugin such as Autoptimize) and you're done!
 
 
18
 
19
  This will *decrease your pageload times*, *leverage browser cache*, *minimize DNS requests* and effectively bring you a perfect score on *Pagespeed Insights* and *Pingdom*, without taking toll on the performance of your webserver.
20
 
21
  = Features =
22
  - Easily find and download your fonts in multiple subsets,
23
  - Generate a stylesheet, which is automatically added to your header using WordPress' wp_head()-function,
24
- - Change the caching path (where the fonts and stylesheet are saved) for increased compatibility with Caching- and Security-plugins, such as WP Super Cache, Autoptimize and WordFence,
25
  - Control font performance by adding font-display property,
26
  - Auto-generates the local source for webfonts,
 
27
  - Prioritize fonts with rel='preload'.
28
 
 
 
29
  == Installation ==
30
 
31
  1. Upload the plugin files to the `/wp-content/plugins/host-webfonts-local` directory, or install the plugin through the WordPress plugins screen directly.
@@ -38,22 +43,26 @@ For a more comprehensive guide for configuration, click [here](https://daan.dev/
38
 
39
  = I don't know what I'm doing! Can you help? =
40
 
41
- Of course :) But first calm down and read this [comprehensive guide on how to configure CAOS for Webfonts](https://daan.dev/wordpress/host-google-fonts-locally/). If you have any questions afterwards, visit the [Support Forum](https://wordpress.org/support/plugin/host-webfonts-local).
42
 
43
  = I have another file I want to host locally. Could you make a plugin? =
44
 
45
- Maintaining two plugins besides my daily 9-to-5 job is a handful, so no. If you're looking for a way to host analytics.js locally; please install [CAOS for Analytics](https://wordpress.org/plugins/host-analyticsjs-local/). For anything else, please follow the steps in [this how-to](https://daan.dev/how-to/host-js-locally-crontab/).
46
 
47
- = How come my font isn't available in CAOS for Webfonts? =
48
 
49
  This could be for several reasons:
50
  1. Have you checked if your font is available on Google Fonts?
51
- 1. Is your font listed as an open source font, or is it a premium font? For obvious reasons, CAOS for Webfonts only has access to open source fonts.
52
 
53
  = Can I serve the fonts from my CDN? =
54
 
55
  Yes, you can. Enter the url of your CDN and re-download and re-generate the stylesheet. Then the fonts will be saved to and served from your CDN.
56
 
 
 
 
 
57
  = Does this plugin edit template files? =
58
 
59
  No, it does not. It creates a CSS Stylesheet which will be automatically added to your theme's header using a built-in WordPress queueing system.
@@ -66,11 +75,20 @@ If the issue still persists and you're using any caching plugins, such as Autopt
66
 
67
  = The stylesheet isn't loaded? What's going on? =
68
 
69
- CAOS for Webfonts enqueues the stylesheet into WordPress' head. If the stylesheet isn't loaded, this probably means your theme isn't implementing the wp_head() function into it's header section.
 
 
70
 
71
- = Does this plugin support Multi Site? =
72
 
73
- Yes, it does!
 
 
 
 
 
 
 
74
 
75
  = Can I buy you a beer? =
76
 
@@ -82,6 +100,39 @@ N/A
82
 
83
  == Changelog ==
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  = 1.8.3 =
86
  Extended support for local source attribute.
87
 
@@ -150,7 +201,7 @@ Added a download counter, clean queue-button and improved allround UX. Fixed a f
150
  Fixed a bug where sometimes the fonts weren't downloaded yet when the stylesheet was generated.
151
 
152
  = 1.5.0 =
153
- CAOS for Webfonts now remembers which fonts you use, to make it easier to edit your stylesheet.
154
 
155
  = 1.4.1 =
156
  Added option to change font-display strategy.
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.2
7
+ Stable tag: 1.9.11
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ With only 2 clicks of a button, OMGF automagically downloads your Google Fonts you want to WordPress' content-folder, generates a stylesheet for it and enqueues it in your theme's header.
12
 
13
  == Description ==
14
 
15
+ Leverage Browser Cache and Minimize DNS requests with OMGF (Optimize My Google Fonts, formerly known as CAOS for Webfonts).
16
 
17
+ OMGF is written with performance and user-friendliness in mind. It uses the Google Fonts Helper API to automagically download the fonts you want to WordPress' contents folder and generate a stylesheet for it. The stylesheet is automatically included to your site's header and 100% compatible with CSS and JS optimizing/minification plugins like Autoptimize or W3 Total Cache. OMGF can efficiently remove any requests to external Google Fonts (loaded from fonts.gstatic.com or fonts.googleapies.com).
18
+
19
+ That's it. You're done!
20
 
21
  This will *decrease your pageload times*, *leverage browser cache*, *minimize DNS requests* and effectively bring you a perfect score on *Pagespeed Insights* and *Pingdom*, without taking toll on the performance of your webserver.
22
 
23
  = Features =
24
  - Easily find and download your fonts in multiple subsets,
25
  - Generate a stylesheet, which is automatically added to your header using WordPress' wp_head()-function,
26
+ - 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,
27
  - Control font performance by adding font-display property,
28
  - Auto-generates the local source for webfonts,
29
+ - Automatically remove any fonts loaded from fonts.gstatic.com or fonts.googleapis.com,
30
  - Prioritize fonts with rel='preload'.
31
 
32
+ 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.
33
+
34
  == Installation ==
35
 
36
  1. Upload the plugin files to the `/wp-content/plugins/host-webfonts-local` directory, or install the plugin through the WordPress plugins screen directly.
43
 
44
  = I don't know what I'm doing! Can you help? =
45
 
46
+ Of course :) But first calm down and read this [comprehensive guide on how to configure OMGF](https://daan.dev/wordpress/host-google-fonts-locally/). If you have any questions afterwards, visit the [Support Forum](https://wordpress.org/support/plugin/host-webfonts-local).
47
 
48
  = I have another file I want to host locally. Could you make a plugin? =
49
 
50
+ Maintaining two plugins besides my daily 9-to-5 job is a handful, so no. If you're looking for a way to host analytics.js locally; please install [CAOS](https://wordpress.org/plugins/host-analyticsjs-local/). For anything else, please follow the steps in [this how-to](https://daan.dev/how-to/host-js-locally-crontab/).
51
 
52
+ = How come my font isn't available in OMGF? =
53
 
54
  This could be for several reasons:
55
  1. Have you checked if your font is available on Google Fonts?
56
+ 1. Is your font listed as an open source font, or is it a premium font? For obvious reasons, OMGF only has access to open source fonts.
57
 
58
  = Can I serve the fonts from my CDN? =
59
 
60
  Yes, you can. Enter the url of your CDN and re-download and re-generate the stylesheet. Then the fonts will be saved to and served from your CDN.
61
 
62
+ = I'm getting a 'Load resources from a consistent URL' after installing and configuring this plugin. What's going on? =
63
+
64
+ This must be, because you're still loading the externally hosted Google Fonts, besides the fonts you downloaded using OMGF. Try checking the option 'Remove Google Fonts' and see if that helps. If it doesn't consider using a child theme to 'dequeue' any external requests. If you don't know how to do that, consider using a plugin such as Autoptimize to optimize your CSS and remove the fonts.
65
+
66
  = Does this plugin edit template files? =
67
 
68
  No, it does not. It creates a CSS Stylesheet which will be automatically added to your theme's header using a built-in WordPress queueing system.
75
 
76
  = The stylesheet isn't loaded? What's going on? =
77
 
78
+ OMGF enqueues the stylesheet into WordPress' head. If the stylesheet isn't loaded, this probably means your theme isn't implementing the wp_head() function into it's header section.
79
+
80
+ = Does this plugin support Multi Site? I'm getting CORS errors! =
81
 
82
+ Yes, it does. When using subdomains, however, you might run into CORS related issues. To get around this, you should configure each site separately. Do the following:
83
 
84
+ - Go to the site's own dashboard,
85
+ - Change OMGF's cache directory (*Save webfonts to...*) to something unique, e.g. `/cache/site1/omgf`,
86
+ - Click 'Save Changes',
87
+ - If you haven't already, find the fonts you want to use,
88
+ - Click 'Download Fonts' and wait for the process to finish,
89
+ - Click 'Generate stylesheet'.
90
+
91
+ Repeat this for every site you want to use with OMGF. A new stylesheet, using the corresponding site's Home-URL and cache directory for each font, has been generated. Bypassing any Cross-Origin Resource Sharing (CORS) issues you might run into.
92
 
93
  = Can I buy you a beer? =
94
 
100
 
101
  == Changelog ==
102
 
103
+ = 1.9.11 =
104
+ Fixed bug where a few strings couldn't be translated. Improved responsiveness of settings-screen. Minor re-factor for better structure.
105
+
106
+ = 1.9.10 =
107
+ [Urgent] Errors in some translation strings.
108
+
109
+ = 1.9.9 =
110
+ Fixed 'duplicate column'-error when WP_DEBUG was enabled. Fixed bug which broke preload. Preload is now automatically skipped if you have any CSS optimization plugins enabled.
111
+
112
+ = 1.9.8 =
113
+ Updated Multisite documentation.
114
+
115
+ = 1.9.7 =
116
+ Updated documentation.
117
+
118
+ = 1.9.6 =
119
+ Fixed bug where preload would cause issues.
120
+
121
+ = 1.9.5 =
122
+ 'Remove Google Fonts'-options now re-enqueues styles that were dependent on removed Fonts.
123
+
124
+ = 1.9.4 =
125
+ Small improvement to 'Remove Google Fonts'-option.
126
+
127
+ = 1.9.2 =
128
+ Made all strings translatable.
129
+
130
+ = 1.9.1 =
131
+ Changed name to OMGF, because it's hilarious?
132
+
133
+ = 1.9.0 =
134
+ New feature! OMGF can now remove fonts from fonts.googleapis.com or fonts.gstatic.com automatically.
135
+
136
  = 1.8.3 =
137
  Extended support for local source attribute.
138
 
201
  Fixed a bug where sometimes the fonts weren't downloaded yet when the stylesheet was generated.
202
 
203
  = 1.5.0 =
204
+ OMGF now remembers which fonts you use, to make it easier to edit your stylesheet.
205
 
206
  = 1.4.1 =
207
  Added option to change font-display strategy.