Version Description
| March 17th, 2021 = * [FEAT] Renamed fonts will now be captured using their new name (e.g. Mulish), but remain in the stylesheet with their old name (e.g. Muli) to prevent manual changes to the stylesheet after optimization. * [FEAT] Added Load WOFF2 Only option. * Small code optimizations in Download API's code.
Download this release
Release Info
Developer | DaanvandenBergh |
Plugin | OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy. |
Version | 4.3.0 |
Comparing to | |
See all releases |
Code changes from version 4.2.8 to 4.3.0
- host-webfonts-local.php +1 -1
- includes/admin/class-settings.php +1 -0
- includes/admin/settings/class-optimize.php +21 -2
- includes/api/class-download.php +56 -17
- includes/class-admin.php +5 -0
- includes/class-omgf.php +1 -0
- readme.txt +6 -1
host-webfonts-local.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Plugin Name: OMGF
|
6 |
* Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
|
7 |
* Description: Minimize DNS requests, leverage browser cache and speed up WordPress by saving Google Fonts to your server and removing external Google Fonts requests.
|
8 |
-
* Version: 4.
|
9 |
* Author: Daan from FFW.Press
|
10 |
* Author URI: https://ffw.press
|
11 |
* License: GPL2v2 or later
|
5 |
* Plugin Name: OMGF
|
6 |
* Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
|
7 |
* Description: Minimize DNS requests, leverage browser cache and speed up WordPress by saving Google Fonts to your server and removing external Google Fonts requests.
|
8 |
+
* Version: 4.3.0
|
9 |
* Author: Daan from FFW.Press
|
10 |
* Author URI: https://ffw.press
|
11 |
* License: GPL2v2 or later
|
includes/admin/class-settings.php
CHANGED
@@ -78,6 +78,7 @@ class OMGF_Admin_Settings extends OMGF_Admin
|
|
78 |
* Optimize Fonts
|
79 |
*/
|
80 |
const OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION = 'omgf_display_option';
|
|
|
81 |
const OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL = 'omgf_manual_optimize_url';
|
82 |
const OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE = 'omgf_optimization_mode';
|
83 |
const OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS = 'omgf_optimized_fonts';
|
78 |
* Optimize Fonts
|
79 |
*/
|
80 |
const OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION = 'omgf_display_option';
|
81 |
+
const OMGF_OPTIMIZE_SETTING_WOFF2_ONLY = 'omgf_woff2_only';
|
82 |
const OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL = 'omgf_manual_optimize_url';
|
83 |
const OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE = 'omgf_optimization_mode';
|
84 |
const OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS = 'omgf_optimized_fonts';
|
includes/admin/settings/class-optimize.php
CHANGED
@@ -37,7 +37,8 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
|
|
37 |
add_filter('omgf_optimize_settings_content', [$this, 'do_optimization_mode'], 30);
|
38 |
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_combine_requests'], 40);
|
39 |
add_filter('omgf_optimize_settings_content', [$this, 'do_display_option'], 50);
|
40 |
-
add_filter('omgf_optimize_settings_content', [$this, '
|
|
|
41 |
add_filter('omgf_optimize_settings_content', [$this, 'do_after'], 100);
|
42 |
|
43 |
add_filter('omgf_optimize_settings_content', [$this, 'do_optimize_fonts_container'], 200);
|
@@ -100,6 +101,21 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
|
|
100 |
);
|
101 |
}
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
/**
|
104 |
*
|
105 |
*/
|
@@ -178,7 +194,10 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
|
|
178 |
<tbody class="stylesheet" id="<?= $handle; ?>">
|
179 |
<?php foreach ($fonts as $font) : ?>
|
180 |
<?php if (count((array) $font->variants) <= 0) continue; ?>
|
181 |
-
|
|
|
|
|
|
|
182 |
<?php foreach ($font->variants as $variant) : ?>
|
183 |
<tr>
|
184 |
<td></td>
|
37 |
add_filter('omgf_optimize_settings_content', [$this, 'do_optimization_mode'], 30);
|
38 |
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_combine_requests'], 40);
|
39 |
add_filter('omgf_optimize_settings_content', [$this, 'do_display_option'], 50);
|
40 |
+
add_filter('omgf_optimize_settings_content', [$this, 'do_woff2_only'], 60);
|
41 |
+
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_force_subsets'], 70);
|
42 |
add_filter('omgf_optimize_settings_content', [$this, 'do_after'], 100);
|
43 |
|
44 |
add_filter('omgf_optimize_settings_content', [$this, 'do_optimize_fonts_container'], 200);
|
101 |
);
|
102 |
}
|
103 |
|
104 |
+
/**
|
105 |
+
* Display WOFF2 Only
|
106 |
+
*
|
107 |
+
* @return void
|
108 |
+
*/
|
109 |
+
public function do_woff2_only()
|
110 |
+
{
|
111 |
+
$this->do_checkbox(
|
112 |
+
__('Load <code>.woff2</code> Only', $this->plugin_text_domain),
|
113 |
+
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_WOFF2_ONLY,
|
114 |
+
OMGF_WOFF2_ONLY,
|
115 |
+
__('Loading <code>.woff2</code> files only will result in a smaller stylesheet, but will make the stylesheet slightly less Cross Browser compatible. <code>.woff2</code> is supported by ~95% of browsers used by internet users globally.', $this->plugin_text_domain)
|
116 |
+
);
|
117 |
+
}
|
118 |
+
|
119 |
/**
|
120 |
*
|
121 |
*/
|
194 |
<tbody class="stylesheet" id="<?= $handle; ?>">
|
195 |
<?php foreach ($fonts as $font) : ?>
|
196 |
<?php if (count((array) $font->variants) <= 0) continue; ?>
|
197 |
+
<?php
|
198 |
+
$aka = in_array($font->id, OMGF_API_Download::OMGF_RENAMED_GOOGLE_FONTS) ? array_search($font->id, OMGF_API_Download::OMGF_RENAMED_GOOGLE_FONTS) : '';
|
199 |
+
?>
|
200 |
+
<th><?= $font->family; ?> <span class="handle">(<em><?= $aka ? sprintf(__('previously known as <strong>%s</strong>', $this->plugin_text_domain), ucfirst($aka)) . ' -- ' : ''; ?><?= __('Stylesheet handle', $this->plugin_text_domain); ?>: <strong><?= $handle; ?></strong></em>)</span></th>
|
201 |
<?php foreach ($font->variants as $variant) : ?>
|
202 |
<tr>
|
203 |
<td></td>
|
includes/api/class-download.php
CHANGED
@@ -20,6 +20,15 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
20 |
{
|
21 |
const OMGF_GOOGLE_FONTS_API_URL = 'https://google-webfonts-helper.herokuapp.com';
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
private $plugin_text_domain = 'host-webfonts-local';
|
24 |
|
25 |
/** @var array */
|
@@ -83,16 +92,10 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
83 |
wp_die(__('Handle not provided.', $this->plugin_text_domain), 406);
|
84 |
}
|
85 |
|
86 |
-
$this->path
|
87 |
-
$font_families
|
88 |
-
|
89 |
-
|
90 |
-
$query['subsets'] = implode(',', OMGF_PRO_FORCE_SUBSETS);
|
91 |
-
} else {
|
92 |
-
$query['subsets'] = $params['subset'] ?? 'latin,latin-ext';
|
93 |
-
}
|
94 |
-
|
95 |
-
$fonts = [];
|
96 |
|
97 |
foreach ($font_families as $font_family) {
|
98 |
$fonts[] = $this->grab_font_family($font_family, $query);
|
@@ -122,11 +125,20 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
122 |
}
|
123 |
|
124 |
foreach ($fonts as &$font) {
|
|
|
|
|
125 |
foreach ($font->variants as &$variant) {
|
126 |
-
$
|
127 |
-
$filename = strtolower(str_replace(' ', '-', $font_family) . '-' . $variant->fontStyle . '-' . $variant->fontWeight);
|
128 |
-
$variant->woff = $this->download($variant->woff, $filename);
|
129 |
$variant->woff2 = $this->download($variant->woff2, $filename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
$variant->eot = $this->download($variant->eot, $filename);
|
131 |
$variant->ttf = $this->download($variant->ttf, $filename);
|
132 |
}
|
@@ -266,6 +278,13 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
266 |
$query_string = '?' . http_build_query($query);
|
267 |
}
|
268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
$response = wp_remote_get(
|
270 |
sprintf($url, $family) . $query_string
|
271 |
);
|
@@ -420,8 +439,16 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
420 |
$font_display = OMGF_DISPLAY_OPTION;
|
421 |
|
422 |
foreach ($fonts as $font) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
423 |
foreach ($font->variants as $variant) {
|
424 |
-
$font_family = $variant->fontFamily;
|
425 |
$font_style = $variant->fontStyle;
|
426 |
$font_weight = $variant->fontWeight;
|
427 |
$stylesheet .= "@font-face {\n";
|
@@ -429,7 +456,13 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
429 |
$stylesheet .= " font-style: $font_style;\n";
|
430 |
$stylesheet .= " font-weight: $font_weight;\n";
|
431 |
$stylesheet .= " font-display: $font_display;\n";
|
432 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
433 |
|
434 |
$local_src = '';
|
435 |
|
@@ -442,8 +475,14 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
442 |
$stylesheet .= " src: $local_src\n";
|
443 |
|
444 |
$font_src_url = isset($variant->woff2) ? ['woff2' => $variant->woff2] : [];
|
445 |
-
|
446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
|
448 |
$stylesheet .= $this->build_source_string($font_src_url);
|
449 |
$stylesheet .= "}\n";
|
20 |
{
|
21 |
const OMGF_GOOGLE_FONTS_API_URL = 'https://google-webfonts-helper.herokuapp.com';
|
22 |
|
23 |
+
/**
|
24 |
+
* If a font changed names recently, this array will map the old name (key) to the new name (value).
|
25 |
+
*
|
26 |
+
* The key of an element should be dashed (no spaces) if necessary, e.g. open-sans.
|
27 |
+
*/
|
28 |
+
const OMGF_RENAMED_GOOGLE_FONTS = [
|
29 |
+
'muli' => 'mulish'
|
30 |
+
];
|
31 |
+
|
32 |
private $plugin_text_domain = 'host-webfonts-local';
|
33 |
|
34 |
/** @var array */
|
92 |
wp_die(__('Handle not provided.', $this->plugin_text_domain), 406);
|
93 |
}
|
94 |
|
95 |
+
$this->path = WP_CONTENT_DIR . OMGF_CACHE_PATH . '/' . $this->handle;
|
96 |
+
$font_families = explode('|', $params['family']);
|
97 |
+
$query['subsets'] = $params['subset'] ?? 'latin,latin-ext';
|
98 |
+
$fonts = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
foreach ($font_families as $font_family) {
|
101 |
$fonts[] = $this->grab_font_family($font_family, $query);
|
125 |
}
|
126 |
|
127 |
foreach ($fonts as &$font) {
|
128 |
+
$font_id = $font->id;
|
129 |
+
|
130 |
foreach ($font->variants as &$variant) {
|
131 |
+
$filename = strtolower($font_id . '-' . $variant->fontStyle . '-' . $variant->fontWeight);
|
|
|
|
|
132 |
$variant->woff2 = $this->download($variant->woff2, $filename);
|
133 |
+
|
134 |
+
/**
|
135 |
+
* If Load .woff2 only is enabled, there's no need to continue here.
|
136 |
+
*/
|
137 |
+
if (OMGF_WOFF2_ONLY) {
|
138 |
+
continue;
|
139 |
+
}
|
140 |
+
|
141 |
+
$variant->woff = $this->download($variant->woff, $filename);
|
142 |
$variant->eot = $this->download($variant->eot, $filename);
|
143 |
$variant->ttf = $this->download($variant->ttf, $filename);
|
144 |
}
|
278 |
$query_string = '?' . http_build_query($query);
|
279 |
}
|
280 |
|
281 |
+
/**
|
282 |
+
* If a font changed names recently, map their old name to the new name, before triggering the API request.
|
283 |
+
*/
|
284 |
+
if (in_array($family, array_keys(self::OMGF_RENAMED_GOOGLE_FONTS))) {
|
285 |
+
$family = self::OMGF_RENAMED_GOOGLE_FONTS[$family];
|
286 |
+
}
|
287 |
+
|
288 |
$response = wp_remote_get(
|
289 |
sprintf($url, $family) . $query_string
|
290 |
);
|
439 |
$font_display = OMGF_DISPLAY_OPTION;
|
440 |
|
441 |
foreach ($fonts as $font) {
|
442 |
+
/**
|
443 |
+
* If Font Family's name was recently renamed, the old name should be used so no manual changes have to be made
|
444 |
+
* to the stylesheet after processing.
|
445 |
+
*/
|
446 |
+
$renamed_font_family = in_array($font->id, self::OMGF_RENAMED_GOOGLE_FONTS)
|
447 |
+
? array_search($font->id, self::OMGF_RENAMED_GOOGLE_FONTS)
|
448 |
+
: '';
|
449 |
+
|
450 |
foreach ($font->variants as $variant) {
|
451 |
+
$font_family = $renamed_font_family ? '\'' . ucfirst($renamed_font_family) . '\'' : $variant->fontFamily;
|
452 |
$font_style = $variant->fontStyle;
|
453 |
$font_weight = $variant->fontWeight;
|
454 |
$stylesheet .= "@font-face {\n";
|
456 |
$stylesheet .= " font-style: $font_style;\n";
|
457 |
$stylesheet .= " font-weight: $font_weight;\n";
|
458 |
$stylesheet .= " font-display: $font_display;\n";
|
459 |
+
|
460 |
+
/**
|
461 |
+
* If WOFF2 Only is disabled, add EOT to the stylesheet for IE compatibility.
|
462 |
+
*/
|
463 |
+
if (!OMGF_WOFF2_ONLY) {
|
464 |
+
$stylesheet .= " src: url('" . $variant->eot . "');\n";
|
465 |
+
}
|
466 |
|
467 |
$local_src = '';
|
468 |
|
475 |
$stylesheet .= " src: $local_src\n";
|
476 |
|
477 |
$font_src_url = isset($variant->woff2) ? ['woff2' => $variant->woff2] : [];
|
478 |
+
|
479 |
+
/**
|
480 |
+
* If WOFF2 only is disabled, add WOFF and TTF to the source stack.
|
481 |
+
*/
|
482 |
+
if (!OMGF_WOFF2_ONLY) {
|
483 |
+
$font_src_url = $font_src_url + (isset($variant->woff) ? ['woff' => $variant->woff] : []);
|
484 |
+
$font_src_url = $font_src_url + (isset($variant->ttf) ? ['ttf' => $variant->ttf] : []);
|
485 |
+
}
|
486 |
|
487 |
$stylesheet .= $this->build_source_string($font_src_url);
|
488 |
$stylesheet .= "}\n";
|
includes/class-admin.php
CHANGED
@@ -38,6 +38,7 @@ class OMGF_Admin
|
|
38 |
$this->show_notice = apply_filters(
|
39 |
'omgf_admin_options_show_notice',
|
40 |
[
|
|
|
41 |
OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH,
|
42 |
OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI,
|
43 |
OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL,
|
@@ -157,8 +158,12 @@ class OMGF_Admin
|
|
157 |
}
|
158 |
|
159 |
/**
|
|
|
|
|
160 |
* @param $new_value
|
161 |
* @param $old_settings
|
|
|
|
|
162 |
*
|
163 |
* @return mixed
|
164 |
*/
|
38 |
$this->show_notice = apply_filters(
|
39 |
'omgf_admin_options_show_notice',
|
40 |
[
|
41 |
+
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_WOFF2_ONLY,
|
42 |
OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH,
|
43 |
OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI,
|
44 |
OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL,
|
158 |
}
|
159 |
|
160 |
/**
|
161 |
+
* Shows notice if $option_name is in $show_notice array.
|
162 |
+
*
|
163 |
* @param $new_value
|
164 |
* @param $old_settings
|
165 |
+
*
|
166 |
+
* @see $show_notice
|
167 |
*
|
168 |
* @return mixed
|
169 |
*/
|
includes/class-omgf.php
CHANGED
@@ -49,6 +49,7 @@ class OMGF
|
|
49 |
define('OMGF_MANUAL_OPTIMIZE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL, site_url())));
|
50 |
define('OMGF_FONT_PROCESSING', esc_attr(get_option(OMGF_Admin_Settings::OMGF_DETECTION_SETTING_FONT_PROCESSING, 'replace')));
|
51 |
define('OMGF_DISPLAY_OPTION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION, 'swap')) ?: 'swap');
|
|
|
52 |
define('OMGF_OPTIMIZE_EDIT_ROLES', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZE_EDIT_ROLES, 'on')));
|
53 |
define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH)) ?: '/uploads/omgf');
|
54 |
define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI)) ?: '');
|
49 |
define('OMGF_MANUAL_OPTIMIZE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL, site_url())));
|
50 |
define('OMGF_FONT_PROCESSING', esc_attr(get_option(OMGF_Admin_Settings::OMGF_DETECTION_SETTING_FONT_PROCESSING, 'replace')));
|
51 |
define('OMGF_DISPLAY_OPTION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION, 'swap')) ?: 'swap');
|
52 |
+
define('OMGF_WOFF2_ONLY', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_WOFF2_ONLY)));
|
53 |
define('OMGF_OPTIMIZE_EDIT_ROLES', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZE_EDIT_ROLES, 'on')));
|
54 |
define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH)) ?: '/uploads/omgf');
|
55 |
define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI)) ?: '');
|
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.7
|
6 |
-
Stable tag: 4.
|
7 |
Requires PHP: 7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -123,6 +123,11 @@ No, not yet. But I will definitely try to make it compatible in the future!
|
|
123 |
|
124 |
== Changelog ==
|
125 |
|
|
|
|
|
|
|
|
|
|
|
126 |
= 4.2.8 | March 12th, 2021 =
|
127 |
* [FIX] Strings with a + instead of a space would returned errors in the API.
|
128 |
|
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.7
|
6 |
+
Stable tag: 4.3.0
|
7 |
Requires PHP: 7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
123 |
|
124 |
== Changelog ==
|
125 |
|
126 |
+
= 4.3.0 | March 17th, 2021 =
|
127 |
+
* [FEAT] Renamed fonts will now be captured using their new name (e.g. Mulish), but remain in the stylesheet with their old name (e.g. Muli) to prevent manual changes to the stylesheet after optimization.
|
128 |
+
* [FEAT] Added Load WOFF2 Only option.
|
129 |
+
* Small code optimizations in Download API's code.
|
130 |
+
|
131 |
= 4.2.8 | March 12th, 2021 =
|
132 |
* [FIX] Strings with a + instead of a space would returned errors in the API.
|
133 |
|