Version Description
- Added 'Downloaded' indicator in 'Generate Stylesheet' tab.
- Added 'Also optimize fonts for logged in users?' option. This means that all users with editor capabilities will (from now on) only view the optimizations when this option is checked, or when they view the frontend of the website in a private/incognito browser session.
Download this release
Release Info
Developer | DaanvandenBergh |
Plugin | OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy. |
Version | 3.4.0 |
Comparing to | |
See all releases |
Code changes from version 3.3.6 to 3.4.0
- host-webfonts-local.php +3 -3
- includes/admin/class-settings.php +1 -0
- includes/ajax/class-download.php +1 -1
- includes/class-omgf.php +1 -0
- includes/frontend/class-functions.php +33 -0
- readme.txt +7 -1
- templates/admin/block-advanced-settings.phtml +13 -0
- templates/admin/block-generate-stylesheet.phtml +5 -1
host-webfonts-local.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: OMGF
|
5 |
* Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
|
6 |
* Description: Minimize DNS requests and leverage browser cache by easily saving Google Fonts to your server and removing the external Google Fonts.
|
7 |
-
* Version: 3.
|
8 |
* Author: Daan van den Bergh
|
9 |
* Author URI: https://daan.dev
|
10 |
* License: GPL2v2 or later
|
@@ -20,7 +20,7 @@ defined('ABSPATH') || exit;
|
|
20 |
define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
21 |
define('OMGF_PLUGIN_FILE', __FILE__);
|
22 |
define('OMGF_DB_VERSION', '3.0.0');
|
23 |
-
define('OMGF_STATIC_VERSION', '3.
|
24 |
define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
|
25 |
|
26 |
/**
|
@@ -81,4 +81,4 @@ function omgf_init()
|
|
81 |
return $omgf;
|
82 |
}
|
83 |
|
84 |
-
omgf_init
|
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: 3.4.0
|
8 |
* Author: Daan van den Bergh
|
9 |
* Author URI: https://daan.dev
|
10 |
* License: GPL2v2 or later
|
20 |
define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
21 |
define('OMGF_PLUGIN_FILE', __FILE__);
|
22 |
define('OMGF_DB_VERSION', '3.0.0');
|
23 |
+
define('OMGF_STATIC_VERSION', '3.4.0');
|
24 |
define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
|
25 |
|
26 |
/**
|
81 |
return $omgf;
|
82 |
}
|
83 |
|
84 |
+
add_action('plugins_loaded', 'omgf_init');
|
includes/admin/class-settings.php
CHANGED
@@ -54,6 +54,7 @@ class OMGF_Admin_Settings extends OMGF_Admin
|
|
54 |
const OMGF_ADV_SETTING_DISPLAY_OPTION = 'omgf_display_option';
|
55 |
const OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS = 'omgf_remove_gfonts';
|
56 |
const OMGF_ADV_SETTING_ENABLE_PRELOAD = 'omgf_preload';
|
|
|
57 |
const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
|
58 |
const OMGF_ADV_SETTING_ENQUEUE_ORDER = 'omgf_enqueue_order';
|
59 |
const OMGF_ADV_SETTING_RELATIVE_URL = 'omgf_relative_url';
|
54 |
const OMGF_ADV_SETTING_DISPLAY_OPTION = 'omgf_display_option';
|
55 |
const OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS = 'omgf_remove_gfonts';
|
56 |
const OMGF_ADV_SETTING_ENABLE_PRELOAD = 'omgf_preload';
|
57 |
+
const OMGF_ADV_SETTING_OPTIMIZE_EDIT_ROLES = 'omgf_optimize_edit_roles';
|
58 |
const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
|
59 |
const OMGF_ADV_SETTING_ENQUEUE_ORDER = 'omgf_enqueue_order';
|
60 |
const OMGF_ADV_SETTING_RELATIVE_URL = 'omgf_relative_url';
|
includes/ajax/class-download.php
CHANGED
@@ -115,7 +115,7 @@ class OMGF_AJAX_Download extends OMGF_AJAX
|
|
115 |
*/
|
116 |
private function download_file($localFile, $remoteFile)
|
117 |
{
|
118 |
-
$file = wp_remote_get($remoteFile
|
119 |
|
120 |
if (is_wp_error($file)) {
|
121 |
OMGF_Admin_Notice::set_notice($file->get_error_message(), true, 'error', $file->get_error_code());
|
115 |
*/
|
116 |
private function download_file($localFile, $remoteFile)
|
117 |
{
|
118 |
+
$file = wp_remote_get($remoteFile);
|
119 |
|
120 |
if (is_wp_error($file)) {
|
121 |
OMGF_Admin_Notice::set_notice($file->get_error_message(), true, 'error', $file->get_error_code());
|
includes/class-omgf.php
CHANGED
@@ -68,6 +68,7 @@ class OMGF
|
|
68 |
define('OMGF_REMOVE_GFONTS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS)));
|
69 |
define('OMGF_PRELOAD', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_ENABLE_PRELOAD)));
|
70 |
define('OMGF_ENQUEUE_ORDER', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_ENQUEUE_ORDER, 10)));
|
|
|
71 |
define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
|
72 |
}
|
73 |
|
68 |
define('OMGF_REMOVE_GFONTS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS)));
|
69 |
define('OMGF_PRELOAD', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_ENABLE_PRELOAD)));
|
70 |
define('OMGF_ENQUEUE_ORDER', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_ENQUEUE_ORDER, 10)));
|
71 |
+
define('OMGF_OPTIMIZE_EDIT_ROLES', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_OPTIMIZE_EDIT_ROLES)));
|
72 |
define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
|
73 |
}
|
74 |
|
includes/frontend/class-functions.php
CHANGED
@@ -29,6 +29,8 @@ class OMGF_Frontend_Functions
|
|
29 |
/** @var string */
|
30 |
private $stylesheet_url;
|
31 |
|
|
|
|
|
32 |
/**
|
33 |
* OMGF_Frontend_Functions constructor.
|
34 |
*/
|
@@ -36,6 +38,7 @@ class OMGF_Frontend_Functions
|
|
36 |
{
|
37 |
$this->stylesheet_file = OMGF_FONTS_DIR . '/' . OMGF_FILENAME;
|
38 |
$this->stylesheet_url = OMGF_FONTS_URL . '/' . OMGF_FILENAME;
|
|
|
39 |
|
40 |
// @formatter:off
|
41 |
add_action('wp_print_styles', array($this, 'is_remove_google_fonts_enabled'), PHP_INT_MAX - 1000);
|
@@ -63,6 +66,10 @@ class OMGF_Frontend_Functions
|
|
63 |
*/
|
64 |
public function is_remove_google_fonts_enabled()
|
65 |
{
|
|
|
|
|
|
|
|
|
66 |
if (OMGF_REMOVE_GFONTS == 'on' && !is_admin()) {
|
67 |
// @formatter:off
|
68 |
add_action('wp_print_styles', array($this, 'remove_google_fonts'), PHP_INT_MAX - 500);
|
@@ -72,6 +79,20 @@ class OMGF_Frontend_Functions
|
|
72 |
}
|
73 |
}
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
/**
|
76 |
* Automatically dequeues any stylesheets loaded from fonts.gstatic.com or
|
77 |
* fonts.googleapis.com. Also checks for stylesheets dependant on Google Fonts and
|
@@ -124,6 +145,10 @@ class OMGF_Frontend_Functions
|
|
124 |
*/
|
125 |
public function enqueue_stylesheet()
|
126 |
{
|
|
|
|
|
|
|
|
|
127 |
if (OMGF_WEB_FONT_LOADER) {
|
128 |
$this->get_template('web-font-loader');
|
129 |
} else {
|
@@ -144,6 +169,10 @@ class OMGF_Frontend_Functions
|
|
144 |
*/
|
145 |
public function is_preload_enabled()
|
146 |
{
|
|
|
|
|
|
|
|
|
147 |
if (OMGF_PRELOAD == 'on') {
|
148 |
// @formatter:off
|
149 |
add_action('wp_enqueue_scripts', array($this, 'add_stylesheet_preload'), 0);
|
@@ -192,6 +221,10 @@ class OMGF_Frontend_Functions
|
|
192 |
*/
|
193 |
public function preload_fonts()
|
194 |
{
|
|
|
|
|
|
|
|
|
195 |
$preload_fonts = $this->db->get_preload_fonts();
|
196 |
|
197 |
if (!$preload_fonts) {
|
29 |
/** @var string */
|
30 |
private $stylesheet_url;
|
31 |
|
32 |
+
private $do_optimize;
|
33 |
+
|
34 |
/**
|
35 |
* OMGF_Frontend_Functions constructor.
|
36 |
*/
|
38 |
{
|
39 |
$this->stylesheet_file = OMGF_FONTS_DIR . '/' . OMGF_FILENAME;
|
40 |
$this->stylesheet_url = OMGF_FONTS_URL . '/' . OMGF_FILENAME;
|
41 |
+
$this->do_optimize = $this->maybe_optimize_fonts();
|
42 |
|
43 |
// @formatter:off
|
44 |
add_action('wp_print_styles', array($this, 'is_remove_google_fonts_enabled'), PHP_INT_MAX - 1000);
|
66 |
*/
|
67 |
public function is_remove_google_fonts_enabled()
|
68 |
{
|
69 |
+
if (!$this->do_optimize) {
|
70 |
+
return;
|
71 |
+
}
|
72 |
+
|
73 |
if (OMGF_REMOVE_GFONTS == 'on' && !is_admin()) {
|
74 |
// @formatter:off
|
75 |
add_action('wp_print_styles', array($this, 'remove_google_fonts'), PHP_INT_MAX - 500);
|
79 |
}
|
80 |
}
|
81 |
|
82 |
+
/**
|
83 |
+
* Should we optimize for logged in editors/administrators?
|
84 |
+
*
|
85 |
+
* @return bool
|
86 |
+
*/
|
87 |
+
private function maybe_optimize_fonts()
|
88 |
+
{
|
89 |
+
if (!OMGF_OPTIMIZE_EDIT_ROLES && current_user_can('edit_pages')) {
|
90 |
+
return false;
|
91 |
+
}
|
92 |
+
|
93 |
+
return true;
|
94 |
+
}
|
95 |
+
|
96 |
/**
|
97 |
* Automatically dequeues any stylesheets loaded from fonts.gstatic.com or
|
98 |
* fonts.googleapis.com. Also checks for stylesheets dependant on Google Fonts and
|
145 |
*/
|
146 |
public function enqueue_stylesheet()
|
147 |
{
|
148 |
+
if (!$this->do_optimize) {
|
149 |
+
return;
|
150 |
+
}
|
151 |
+
|
152 |
if (OMGF_WEB_FONT_LOADER) {
|
153 |
$this->get_template('web-font-loader');
|
154 |
} else {
|
169 |
*/
|
170 |
public function is_preload_enabled()
|
171 |
{
|
172 |
+
if (!$this->do_optimize) {
|
173 |
+
return;
|
174 |
+
}
|
175 |
+
|
176 |
if (OMGF_PRELOAD == 'on') {
|
177 |
// @formatter:off
|
178 |
add_action('wp_enqueue_scripts', array($this, 'add_stylesheet_preload'), 0);
|
221 |
*/
|
222 |
public function preload_fonts()
|
223 |
{
|
224 |
+
if (!$this->do_optimize) {
|
225 |
+
return;
|
226 |
+
}
|
227 |
+
|
228 |
$preload_fonts = $this->db->get_preload_fonts();
|
229 |
|
230 |
if (!$preload_fonts) {
|
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.4
|
6 |
-
Stable tag: 3.
|
7 |
Requires PHP: 7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -108,6 +108,12 @@ N/A
|
|
108 |
|
109 |
== Changelog ==
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
= 3.3.6 =
|
112 |
* Modified preload feature to comply with Mozilla's regulations for the crossorigin attribute.
|
113 |
|
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.4
|
6 |
+
Stable tag: 3.4.0
|
7 |
Requires PHP: 7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
108 |
|
109 |
== Changelog ==
|
110 |
|
111 |
+
= 3.4.0 =
|
112 |
+
* Added 'Downloaded' indicator in 'Generate Stylesheet' tab.
|
113 |
+
* Added 'Also optimize fonts for logged in users?' option. This means that all users with editor
|
114 |
+
capabilities will (from now on) only view the optimizations when this option is checked, or when
|
115 |
+
they view the frontend of the website in a private/incognito browser session.
|
116 |
+
|
117 |
= 3.3.6 =
|
118 |
* Modified preload feature to comply with Mozilla's regulations for the crossorigin attribute.
|
119 |
|
templates/admin/block-advanced-settings.phtml
CHANGED
@@ -162,6 +162,19 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
|
|
162 |
</p>
|
163 |
</td>
|
164 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
<tr valign="top">
|
166 |
<th scope="row">
|
167 |
<label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL ?>">
|
162 |
</p>
|
163 |
</td>
|
164 |
</tr>
|
165 |
+
<tr valign="top">
|
166 |
+
<th scope="row">
|
167 |
+
<label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_OPTIMIZE_EDIT_ROLES ?>">
|
168 |
+
<?php _e('Optimize fonts for logged in editors/administrators?', 'host-webfonts-local'); ?>
|
169 |
+
</label>
|
170 |
+
</th>
|
171 |
+
<td>
|
172 |
+
<input class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_OPTIMIZE_EDIT_ROLES ?>" id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_OPTIMIZE_EDIT_ROLES ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_OPTIMIZE_EDIT_ROLES ?>" <?= OMGF_OPTIMIZE_EDIT_ROLES == 'on' ? 'checked = "checked"' : '' ?> />
|
173 |
+
<p class="description">
|
174 |
+
<?php _e('Should only be used for debugging/testing purposes. Leave disabled when e.g. using a page builder or switching themes.', 'host-webfonts-local'); ?>
|
175 |
+
</p>
|
176 |
+
</td>
|
177 |
+
</tr>
|
178 |
<tr valign="top">
|
179 |
<th scope="row">
|
180 |
<label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL ?>">
|
templates/admin/block-generate-stylesheet.phtml
CHANGED
@@ -78,6 +78,7 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
|
|
78 |
?>
|
79 |
<?php if ($savedFonts && $subsetFonts): ?>
|
80 |
<thead align="center">
|
|
|
81 |
<th>
|
82 |
<?= __('Font Family', 'host-webfonts-local'); ?>
|
83 |
</th>
|
@@ -97,6 +98,9 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
|
|
97 |
$fontId = $font['font_id'];
|
98 |
?>
|
99 |
<tr class="omgf-font-style" data-font-id="<?= $fontId; ?>" id="row-<?= $fontId; ?>">
|
|
|
|
|
|
|
100 |
<td style="width: 195px;">
|
101 |
<input readonly type="text" value="<?= $font['font_family']; ?>" />
|
102 |
</td>
|
@@ -122,7 +126,7 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
|
|
122 |
<?php endforeach; ?>
|
123 |
<!-- The navbar at the bottom of the table. -->
|
124 |
<tr id="font-styles-nav" class="sticky bottom">
|
125 |
-
<td colspan="
|
126 |
<span class="omgf-apply help font-styles" style="display: none;"><strong><?= __('Apply Changes', 'host-webfonts-local'); ?></strong></span>
|
127 |
</td>
|
128 |
<td colspan="2" style="width: 100px">
|
78 |
?>
|
79 |
<?php if ($savedFonts && $subsetFonts): ?>
|
80 |
<thead align="center">
|
81 |
+
<th></th>
|
82 |
<th>
|
83 |
<?= __('Font Family', 'host-webfonts-local'); ?>
|
84 |
</th>
|
98 |
$fontId = $font['font_id'];
|
99 |
?>
|
100 |
<tr class="omgf-font-style" data-font-id="<?= $fontId; ?>" id="row-<?= $fontId; ?>">
|
101 |
+
<td align="center" style="width: 20px;">
|
102 |
+
<span class="omgf-font-downloaded dashicons-before <?= isset($font['downloaded']) && $font['downloaded'] == 1 ? 'dashicons-yes' : ''; ?>"></span>
|
103 |
+
</td>
|
104 |
<td style="width: 195px;">
|
105 |
<input readonly type="text" value="<?= $font['font_family']; ?>" />
|
106 |
</td>
|
126 |
<?php endforeach; ?>
|
127 |
<!-- The navbar at the bottom of the table. -->
|
128 |
<tr id="font-styles-nav" class="sticky bottom">
|
129 |
+
<td colspan="4" align="right">
|
130 |
<span class="omgf-apply help font-styles" style="display: none;"><strong><?= __('Apply Changes', 'host-webfonts-local'); ?></strong></span>
|
131 |
</td>
|
132 |
<td colspan="2" style="width: 100px">
|