Version Description
| July 28th, 2021 = * [Removed] WOFF2 only option is superseded by Include File Types option, only available in OMGF Pro. * [Removed] CDN URL, Cache URI and Relative URL options are combined into Fonts Source URL option, only available in OMGF Pro. * [Removed] Optimization Mode > Automatic is only available in OMGF Pro. * Tested with WordPress 5.8 * Several code optimizations.
Download this release
Release Info
Developer | DaanvandenBergh |
Plugin | OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy. |
Version | 4.5.0 |
Comparing to | |
See all releases |
Code changes from version 4.4.4 to 4.5.0
- assets/js/omgf-admin.js +24 -0
- host-webfonts-local.php +2 -2
- includes/admin/class-settings.php +84 -9
- includes/admin/settings/class-advanced.php +29 -39
- includes/admin/settings/class-builder.php +2 -2
- includes/admin/settings/class-detection.php +2 -2
- includes/admin/settings/class-optimize.php +16 -9
- includes/api/class-download.php +39 -33
- includes/class-admin.php +0 -4
- includes/class-omgf.php +6 -45
- includes/class-optimize.php +3 -17
- includes/frontend/class-functions.php +1 -1
- readme.txt +23 -9
assets/js/omgf-admin.js
CHANGED
@@ -15,6 +15,8 @@
|
|
15 |
|
16 |
jQuery(document).ready(function ($) {
|
17 |
var omgf_admin = {
|
|
|
|
|
18 |
empty_cache_directory_xhr: false,
|
19 |
optimize_xhr: false,
|
20 |
cache_prefix: '-ul-',
|
@@ -36,6 +38,28 @@ jQuery(document).ready(function ($) {
|
|
36 |
// Buttons
|
37 |
$('.omgf-empty').on('click', this.empty_cache_directory);
|
38 |
$('#omgf-optimize-settings-form').submit(this.show_loader_before_submit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
},
|
40 |
|
41 |
/**
|
15 |
|
16 |
jQuery(document).ready(function ($) {
|
17 |
var omgf_admin = {
|
18 |
+
ticker_items: document.querySelectorAll('.ticker-item'),
|
19 |
+
ticker_index: 0,
|
20 |
empty_cache_directory_xhr: false,
|
21 |
optimize_xhr: false,
|
22 |
cache_prefix: '-ul-',
|
38 |
// Buttons
|
39 |
$('.omgf-empty').on('click', this.empty_cache_directory);
|
40 |
$('#omgf-optimize-settings-form').submit(this.show_loader_before_submit);
|
41 |
+
|
42 |
+
// Ticker
|
43 |
+
setInterval(this.loop_ticker_items, 4000);
|
44 |
+
},
|
45 |
+
|
46 |
+
/**
|
47 |
+
*
|
48 |
+
*/
|
49 |
+
loop_ticker_items: function () {
|
50 |
+
omgf_admin.ticker_items.forEach(function (item, index) {
|
51 |
+
if (index == omgf_admin.ticker_index) {
|
52 |
+
$(item).delay(110).fadeIn(500);
|
53 |
+
} else {
|
54 |
+
$(item).fadeOut(100);
|
55 |
+
}
|
56 |
+
});
|
57 |
+
|
58 |
+
omgf_admin.ticker_index++;
|
59 |
+
|
60 |
+
if (omgf_admin.ticker_index == omgf_admin.ticker_items.length) {
|
61 |
+
omgf_admin.ticker_index = 0;
|
62 |
+
}
|
63 |
},
|
64 |
|
65 |
/**
|
host-webfonts-local.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: OMGF
|
5 |
* Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
|
6 |
* Description: Minimize DNS requests, leverage browser cache and speed up WordPress by saving Google Fonts to your server and removing external Google Fonts requests.
|
7 |
-
* Version: 4.
|
8 |
* Author: Daan from FFW.Press
|
9 |
* Author URI: https://ffw.press
|
10 |
* License: GPL2v2 or later
|
@@ -19,7 +19,7 @@ defined('ABSPATH') || exit;
|
|
19 |
define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
20 |
define('OMGF_PLUGIN_FILE', __FILE__);
|
21 |
define('OMGF_PLUGIN_BASENAME', plugin_basename(OMGF_PLUGIN_FILE));
|
22 |
-
define('OMGF_STATIC_VERSION', '4.
|
23 |
|
24 |
/**
|
25 |
* Takes care of loading classes on demand.
|
4 |
* Plugin Name: OMGF
|
5 |
* Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
|
6 |
* Description: Minimize DNS requests, leverage browser cache and speed up WordPress by saving Google Fonts to your server and removing external Google Fonts requests.
|
7 |
+
* Version: 4.5.0
|
8 |
* Author: Daan from FFW.Press
|
9 |
* Author URI: https://ffw.press
|
10 |
* License: GPL2v2 or later
|
19 |
define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
20 |
define('OMGF_PLUGIN_FILE', __FILE__);
|
21 |
define('OMGF_PLUGIN_BASENAME', plugin_basename(OMGF_PLUGIN_FILE));
|
22 |
+
define('OMGF_STATIC_VERSION', '4.5.0');
|
23 |
|
24 |
/**
|
25 |
* Takes care of loading classes on demand.
|
includes/admin/class-settings.php
CHANGED
@@ -19,6 +19,7 @@ defined('ABSPATH') || exit;
|
|
19 |
class OMGF_Admin_Settings extends OMGF_Admin
|
20 |
{
|
21 |
const OMGF_ADMIN_PAGE = 'optimize-webfonts';
|
|
|
22 |
|
23 |
/**
|
24 |
* Settings Fields
|
@@ -33,7 +34,7 @@ class OMGF_Admin_Settings extends OMGF_Admin
|
|
33 |
*/
|
34 |
const OMGF_OPTIMIZATION_MODE = [
|
35 |
'manual' => 'Manual (default)',
|
36 |
-
'auto' => 'Automatic'
|
37 |
];
|
38 |
const OMGF_FONT_PROCESSING_OPTIONS = [
|
39 |
'replace' => 'Replace (default)',
|
@@ -46,6 +47,13 @@ class OMGF_Admin_Settings extends OMGF_Admin
|
|
46 |
'fallback' => 'Fallback',
|
47 |
'optional' => 'Optional'
|
48 |
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
const OMGF_FORCE_SUBSETS_OPTIONS = [
|
50 |
'arabic' => 'Arabic',
|
51 |
'bengali' => 'Bengali',
|
@@ -76,12 +84,15 @@ class OMGF_Admin_Settings extends OMGF_Admin
|
|
76 |
'tibetan' => 'Tibetan',
|
77 |
'vietnamese' => 'Vietnamese'
|
78 |
];
|
|
|
|
|
|
|
|
|
79 |
|
80 |
/**
|
81 |
* Optimize Fonts
|
82 |
*/
|
83 |
const OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION = 'omgf_display_option';
|
84 |
-
const OMGF_OPTIMIZE_SETTING_WOFF2_ONLY = 'omgf_woff2_only';
|
85 |
const OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL = 'omgf_manual_optimize_url';
|
86 |
const OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE = 'omgf_optimization_mode';
|
87 |
const OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS = 'omgf_optimized_fonts';
|
@@ -99,11 +110,10 @@ class OMGF_Admin_Settings extends OMGF_Admin
|
|
99 |
/**
|
100 |
* Advanced Settings
|
101 |
*/
|
|
|
102 |
const OMGF_ADV_SETTING_CACHE_PATH = 'omgf_cache_dir';
|
103 |
-
const
|
104 |
-
const OMGF_ADV_SETTING_CDN_URL = 'omgf_cdn_url';
|
105 |
const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
|
106 |
-
const OMGF_ADV_SETTING_RELATIVE_URL = 'omgf_relative_url';
|
107 |
|
108 |
/**
|
109 |
* Miscellaneous
|
@@ -146,6 +156,7 @@ class OMGF_Admin_Settings extends OMGF_Admin
|
|
146 |
|
147 |
// Footer Text
|
148 |
add_filter('admin_footer_text', [$this, 'footer_text_left']);
|
|
|
149 |
|
150 |
// Tabs
|
151 |
add_action('omgf_settings_tab', [$this, 'optimize_fonts_tab'], 0);
|
@@ -399,10 +410,74 @@ class OMGF_Admin_Settings extends OMGF_Admin
|
|
399 |
*/
|
400 |
public function footer_text_left()
|
401 |
{
|
402 |
-
$
|
403 |
-
|
404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
-
return
|
407 |
}
|
408 |
}
|
19 |
class OMGF_Admin_Settings extends OMGF_Admin
|
20 |
{
|
21 |
const OMGF_ADMIN_PAGE = 'optimize-webfonts';
|
22 |
+
const OMGF_NEWS_REEL = 'omgf_news_reel';
|
23 |
|
24 |
/**
|
25 |
* Settings Fields
|
34 |
*/
|
35 |
const OMGF_OPTIMIZATION_MODE = [
|
36 |
'manual' => 'Manual (default)',
|
37 |
+
'auto' => 'Automatic (Pro)'
|
38 |
];
|
39 |
const OMGF_FONT_PROCESSING_OPTIONS = [
|
40 |
'replace' => 'Replace (default)',
|
47 |
'fallback' => 'Fallback',
|
48 |
'optional' => 'Optional'
|
49 |
];
|
50 |
+
const OMGF_FILE_TYPES_OPTIONS = [
|
51 |
+
'woff2' => 'Web Open Font Format 2.0 (WOFF2)',
|
52 |
+
'woff' => 'Web Open Font Format (WOFF)',
|
53 |
+
'eot' => 'Embedded OpenType (EOT)',
|
54 |
+
'ttf' => 'TrueType Font (TTF)',
|
55 |
+
'svg' => 'Scalable Vector Graphics (SVG)'
|
56 |
+
];
|
57 |
const OMGF_FORCE_SUBSETS_OPTIONS = [
|
58 |
'arabic' => 'Arabic',
|
59 |
'bengali' => 'Bengali',
|
84 |
'tibetan' => 'Tibetan',
|
85 |
'vietnamese' => 'Vietnamese'
|
86 |
];
|
87 |
+
const OMGF_AMP_HANDLING_OPTIONS = [
|
88 |
+
'fallback' => 'Fallback (default)',
|
89 |
+
'disable' => 'Disable'
|
90 |
+
];
|
91 |
|
92 |
/**
|
93 |
* Optimize Fonts
|
94 |
*/
|
95 |
const OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION = 'omgf_display_option';
|
|
|
96 |
const OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL = 'omgf_manual_optimize_url';
|
97 |
const OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE = 'omgf_optimization_mode';
|
98 |
const OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS = 'omgf_optimized_fonts';
|
110 |
/**
|
111 |
* Advanced Settings
|
112 |
*/
|
113 |
+
const OMGF_ADV_SETTING_AMP_HANDLING = 'omgf_amp_handling';
|
114 |
const OMGF_ADV_SETTING_CACHE_PATH = 'omgf_cache_dir';
|
115 |
+
const OMGF_ADV_SETTING_SOURCE_URL = 'omgf_fonts_url';
|
|
|
116 |
const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
|
|
|
117 |
|
118 |
/**
|
119 |
* Miscellaneous
|
156 |
|
157 |
// Footer Text
|
158 |
add_filter('admin_footer_text', [$this, 'footer_text_left']);
|
159 |
+
add_filter('update_footer', [$this, 'footer_text_right'], 11);
|
160 |
|
161 |
// Tabs
|
162 |
add_action('omgf_settings_tab', [$this, 'optimize_fonts_tab'], 0);
|
410 |
*/
|
411 |
public function footer_text_left()
|
412 |
{
|
413 |
+
$text = sprintf(__('Coded with %s in The Netherlands @ <strong>FFW.Press</strong>.', $this->plugin_text_domain), '<span class="dashicons dashicons-heart ffwp-heart"></span>');
|
414 |
+
|
415 |
+
return '<span id="footer-thankyou">' . $text . '</span>';
|
416 |
+
}
|
417 |
+
|
418 |
+
/**
|
419 |
+
* All logic to generate the news reel in the bottom right of the footer on all of OMGF's settings pages.
|
420 |
+
*
|
421 |
+
* Includes multiple checks to make sure the reel is only shown if a recent post is available.
|
422 |
+
*
|
423 |
+
* @param mixed $text
|
424 |
+
* @return mixed
|
425 |
+
*/
|
426 |
+
public function footer_text_right($text)
|
427 |
+
{
|
428 |
+
if (!extension_loaded('simplexml')) {
|
429 |
+
return $text;
|
430 |
+
}
|
431 |
+
|
432 |
+
/**
|
433 |
+
* If a WordPress update is available, show the original text.
|
434 |
+
*/
|
435 |
+
if (strpos($text, 'Get Version') !== false) {
|
436 |
+
return $text;
|
437 |
+
}
|
438 |
+
|
439 |
+
// Prevents bashing the API.
|
440 |
+
$xml = get_transient(self::OMGF_NEWS_REEL);
|
441 |
+
|
442 |
+
if (!$xml) {
|
443 |
+
$response = wp_remote_get('https://daan.dev/tag/omgf/feed');
|
444 |
+
|
445 |
+
if (!is_wp_error($response)) {
|
446 |
+
$xml = wp_remote_retrieve_body($response);
|
447 |
+
|
448 |
+
// Refresh the feed once a day to prevent bashing of the API.
|
449 |
+
set_transient(self::OMGF_NEWS_REEL, $xml, DAY_IN_SECONDS);
|
450 |
+
}
|
451 |
+
}
|
452 |
+
|
453 |
+
if (!$xml) {
|
454 |
+
return $text;
|
455 |
+
}
|
456 |
+
|
457 |
+
$xml = simplexml_load_string($xml);
|
458 |
+
|
459 |
+
if (!$xml) {
|
460 |
+
return $text;
|
461 |
+
}
|
462 |
+
|
463 |
+
$items = $xml->channel->item ?? [];
|
464 |
+
|
465 |
+
if (empty($items)) {
|
466 |
+
return $text;
|
467 |
+
}
|
468 |
+
|
469 |
+
$text = sprintf(__('Recently tagged <a target="_blank" href="%s"><strong>#OMGF</strong></a> on my blog:', $this->plugin_text_domain), 'https://daan.dev/tag/omgf') . ' ';
|
470 |
+
$text .= '<span id="omgf-ticker-wrap">';
|
471 |
+
$i = 0;
|
472 |
+
|
473 |
+
foreach ($items as $item) {
|
474 |
+
$hide = $i > 0 ? 'style="display: none;"' : '';
|
475 |
+
$text .= "<span class='ticker-item' $hide>" . sprintf('<a target="_blank" href="%s"><em>%s</em></a>', $item->link, $item->title) . '</span>';
|
476 |
+
$i++;
|
477 |
+
}
|
478 |
+
|
479 |
+
$text .= "</span>";
|
480 |
|
481 |
+
return $text;
|
482 |
}
|
483 |
}
|
includes/admin/settings/class-advanced.php
CHANGED
@@ -33,11 +33,10 @@ class OMGF_Admin_Settings_Advanced extends OMGF_Admin_Settings_Builder
|
|
33 |
add_filter('omgf_advanced_settings_content', [$this, 'do_before'], 20);
|
34 |
|
35 |
// Settings
|
36 |
-
add_filter('omgf_advanced_settings_content', [$this, '
|
|
|
37 |
add_filter('omgf_advanced_settings_content', [$this, 'do_cache_dir'], 70);
|
38 |
-
add_filter('omgf_advanced_settings_content', [$this, '
|
39 |
-
add_filter('omgf_advanced_settings_content', [$this, 'do_cache_uri'], 90);
|
40 |
-
add_filter('omgf_advanced_settings_content', [$this, 'do_relative_url'], 100);
|
41 |
add_filter('omgf_advanced_settings_content', [$this, 'do_uninstall'], 110);
|
42 |
|
43 |
// Close
|
@@ -56,19 +55,32 @@ class OMGF_Admin_Settings_Advanced extends OMGF_Admin_Settings_Builder
|
|
56 |
<?php
|
57 |
}
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
/**
|
60 |
* Excluded Post/Page IDs (Pro)
|
61 |
*
|
62 |
* @return void
|
63 |
*/
|
64 |
-
public function
|
65 |
{
|
66 |
$this->do_text(
|
67 |
__('Excluded Post/Page IDs (Pro)', $this->plugin_text_domain),
|
68 |
'omgf_pro_excluded_ids',
|
69 |
__('e.g. 1,2,5,21,443'),
|
70 |
defined('OMGF_PRO_EXCLUDED_IDS') ? OMGF_PRO_EXCLUDED_IDS : '',
|
71 |
-
__('A comma separated list of post/page IDs where OMGF Pro shouldn\'t run.', $this->plugin_text_domain),
|
72 |
true
|
73 |
);
|
74 |
}
|
@@ -90,41 +102,19 @@ class OMGF_Admin_Settings_Advanced extends OMGF_Admin_Settings_Builder
|
|
90 |
/**
|
91 |
*
|
92 |
*/
|
93 |
-
public function
|
94 |
-
{
|
95 |
-
$this->do_text(
|
96 |
-
__('CDN URL', $this->plugin_text_domain),
|
97 |
-
OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL,
|
98 |
-
__('e.g. https://cdn.mydomain.com', $this->plugin_text_domain),
|
99 |
-
OMGF_CDN_URL,
|
100 |
-
__("If you're using a CDN, enter the URL here incl. protocol (e.g. <code>https://</code>.) Leave empty when using CloudFlare.", $this->plugin_text_domain)
|
101 |
-
);
|
102 |
-
}
|
103 |
-
|
104 |
-
/**
|
105 |
-
*
|
106 |
-
*/
|
107 |
-
public function do_cache_uri()
|
108 |
{
|
109 |
$this->do_text(
|
110 |
-
__('
|
111 |
-
|
112 |
-
__('e.g. /
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
*/
|
121 |
-
public function do_relative_url()
|
122 |
-
{
|
123 |
-
$this->do_checkbox(
|
124 |
-
__('Use Relative URLs', $this->plugin_text_domain),
|
125 |
-
OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL,
|
126 |
-
OMGF_RELATIVE_URL,
|
127 |
-
__('Use relative instead of absolute (full) URLs to generate the stylesheet. <em><strong>Warning!</strong> This will disable the CDN URL.</em>', $this->plugin_text_domain)
|
128 |
);
|
129 |
}
|
130 |
|
33 |
add_filter('omgf_advanced_settings_content', [$this, 'do_before'], 20);
|
34 |
|
35 |
// Settings
|
36 |
+
add_filter('omgf_advanced_settings_content', [$this, 'do_promo_amp_handling'], 40);
|
37 |
+
add_filter('omgf_advanced_settings_content', [$this, 'do_promo_exclude_posts'], 50);
|
38 |
add_filter('omgf_advanced_settings_content', [$this, 'do_cache_dir'], 70);
|
39 |
+
add_filter('omgf_advanced_settings_content', [$this, 'do_promo_fonts_source_url'], 80);
|
|
|
|
|
40 |
add_filter('omgf_advanced_settings_content', [$this, 'do_uninstall'], 110);
|
41 |
|
42 |
// Close
|
55 |
<?php
|
56 |
}
|
57 |
|
58 |
+
public function do_promo_amp_handling()
|
59 |
+
{
|
60 |
+
$this->do_select(
|
61 |
+
__('AMP handling (Pro)', $this->plugin_text_domain),
|
62 |
+
'omgf_pro_amp_handling',
|
63 |
+
OMGF_Admin_Settings::OMGF_AMP_HANDLING_OPTIONS,
|
64 |
+
defined('OMGF_PRO_AMP_HANDLING') ? OMGF_PRO_AMP_HANDLING : '',
|
65 |
+
sprintf(__("Decide how OMGF Pro should behave on AMP pages. Only select <strong>enable</strong> if the custom CSS limit of 75kb is not already reached by your theme and/or other plugins and no other <code>amp-custom</code> tag is present on your pages.", $this->plugin_text_domain), OMGF_Admin_Settings::FFWP_WORDPRESS_PLUGINS_OMGF_PRO) . ' ' . $this->promo,
|
66 |
+
false,
|
67 |
+
true
|
68 |
+
);
|
69 |
+
}
|
70 |
+
|
71 |
/**
|
72 |
* Excluded Post/Page IDs (Pro)
|
73 |
*
|
74 |
* @return void
|
75 |
*/
|
76 |
+
public function do_promo_exclude_posts()
|
77 |
{
|
78 |
$this->do_text(
|
79 |
__('Excluded Post/Page IDs (Pro)', $this->plugin_text_domain),
|
80 |
'omgf_pro_excluded_ids',
|
81 |
__('e.g. 1,2,5,21,443'),
|
82 |
defined('OMGF_PRO_EXCLUDED_IDS') ? OMGF_PRO_EXCLUDED_IDS : '',
|
83 |
+
__('A comma separated list of post/page IDs where OMGF Pro shouldn\'t run.', $this->plugin_text_domain) . ' ' . $this->promo,
|
84 |
true
|
85 |
);
|
86 |
}
|
102 |
/**
|
103 |
*
|
104 |
*/
|
105 |
+
public function do_promo_fonts_source_url()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
{
|
107 |
$this->do_text(
|
108 |
+
__('Fonts Source URL (Pro)', $this->plugin_text_domain),
|
109 |
+
'omgf_pro_source_url',
|
110 |
+
__('e.g. https://cdn.mydomain.com/alternate/relative-path', $this->plugin_text_domain),
|
111 |
+
defined('OMGF_PRO_SOURCE_URL') ? OMGF_PRO_SOURCE_URL : '',
|
112 |
+
sprintf(
|
113 |
+
__("Modify the <code>src</code> URL for each font file in the stylesheet. This can be anything, like an absolute URL (e.g. <code>%s</code>) to an alternate relative URL (e.g. <code>/renamed-wp-content-dir/alternate/path/to/font-files</code>). Make sure you include the full path to where OMGF's files are stored and/or served from. Defaults to <code>%s</code>.", $this->plugin_text_domain),
|
114 |
+
str_replace(home_url(), 'https://your-cdn.com', WP_CONTENT_URL . OMGF_CACHE_PATH),
|
115 |
+
WP_CONTENT_URL . OMGF_CACHE_PATH
|
116 |
+
) . ' ' . $this->promo,
|
117 |
+
true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
);
|
119 |
}
|
120 |
|
includes/admin/settings/class-builder.php
CHANGED
@@ -96,13 +96,13 @@ class OMGF_Admin_Settings_Builder
|
|
96 |
<td>
|
97 |
<?php foreach ($inputs as $option => $option_label) : ?>
|
98 |
<label>
|
99 |
-
<input type="radio" class="<?= str_replace('_', '-', $name . '_' . $option); ?>" name="<?= $name; ?>" value="<?= $option; ?>" <?= $option == $checked ? 'checked="checked"' : ''; ?> />
|
100 |
<?= $option_label; ?>
|
101 |
</label>
|
102 |
<br />
|
103 |
<?php endforeach; ?>
|
104 |
<p class="description">
|
105 |
-
<?= $description; ?>
|
106 |
</p>
|
107 |
</td>
|
108 |
</tr>
|
96 |
<td>
|
97 |
<?php foreach ($inputs as $option => $option_label) : ?>
|
98 |
<label>
|
99 |
+
<input type="radio" <?= strpos($option_label, '(Pro)') !== false ? apply_filters($name . '_' . $option . '_setting_disabled', 'disabled') : ''; ?> class="<?= str_replace('_', '-', $name . '_' . $option); ?>" name="<?= $name; ?>" value="<?= $option; ?>" <?= $option == $checked ? 'checked="checked"' : ''; ?> />
|
100 |
<?= $option_label; ?>
|
101 |
</label>
|
102 |
<br />
|
103 |
<?php endforeach; ?>
|
104 |
<p class="description">
|
105 |
+
<?= $description . ' ' . $this->promo; ?>
|
106 |
</p>
|
107 |
</td>
|
108 |
</tr>
|
includes/admin/settings/class-detection.php
CHANGED
@@ -140,13 +140,13 @@ class OMGF_Admin_Settings_Detection extends OMGF_Admin_Settings_Builder
|
|
140 |
__('Safe Mode (Pro)', $this->plugin_text_domain),
|
141 |
'omgf_pro_safe_mode',
|
142 |
defined('OMGF_PRO_SAFE_MODE') ? OMGF_PRO_SAFE_MODE : false,
|
143 |
-
__('Enable Safe Mode if Advanced Processing (Pro) breaks styling of certain pages.'),
|
144 |
true
|
145 |
);
|
146 |
}
|
147 |
|
148 |
/**
|
149 |
-
*
|
150 |
*/
|
151 |
public function do_promo_process_resource_hints()
|
152 |
{
|
140 |
__('Safe Mode (Pro)', $this->plugin_text_domain),
|
141 |
'omgf_pro_safe_mode',
|
142 |
defined('OMGF_PRO_SAFE_MODE') ? OMGF_PRO_SAFE_MODE : false,
|
143 |
+
__('Enable Safe Mode if Advanced Processing (Pro) breaks styling of certain pages.', $this->plugin_text_domain) . ' ' . $this->promo,
|
144 |
true
|
145 |
);
|
146 |
}
|
147 |
|
148 |
/**
|
149 |
+
* Add promo options for Process Resource Hints
|
150 |
*/
|
151 |
public function do_promo_process_resource_hints()
|
152 |
{
|
includes/admin/settings/class-optimize.php
CHANGED
@@ -39,7 +39,7 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
|
|
39 |
add_filter('omgf_optimize_settings_content', [$this, 'do_optimization_mode'], 30);
|
40 |
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_combine_requests'], 40);
|
41 |
add_filter('omgf_optimize_settings_content', [$this, 'do_display_option'], 50);
|
42 |
-
add_filter('omgf_optimize_settings_content', [$this, '
|
43 |
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_force_subsets'], 70);
|
44 |
add_filter('omgf_optimize_settings_content', [$this, 'do_after'], 100);
|
45 |
|
@@ -67,6 +67,10 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
|
|
67 |
<?php
|
68 |
}
|
69 |
|
|
|
|
|
|
|
|
|
70 |
public function do_optimization_mode()
|
71 |
{
|
72 |
$this->do_radio(
|
@@ -74,7 +78,7 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
|
|
74 |
OMGF_Admin_Settings::OMGF_OPTIMIZATION_MODE,
|
75 |
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE,
|
76 |
OMGF_OPTIMIZATION_MODE,
|
77 |
-
__('<strong>Manual</strong> processing mode is best suited for configurations, which use a fixed number of fonts across the entire site. When in manual mode, the generated stylesheet is forced throughout the entire site
|
78 |
);
|
79 |
}
|
80 |
|
@@ -111,13 +115,16 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
|
|
111 |
*
|
112 |
* @return void
|
113 |
*/
|
114 |
-
public function
|
115 |
{
|
116 |
-
$this->
|
117 |
-
__('
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
121 |
);
|
122 |
}
|
123 |
|
@@ -131,7 +138,7 @@ class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
|
|
131 |
'omgf_pro_force_subsets',
|
132 |
OMGF_Admin_Settings::OMGF_FORCE_SUBSETS_OPTIONS,
|
133 |
defined('OMGF_PRO_FORCE_SUBSETS') ? OMGF_PRO_FORCE_SUBSETS : [],
|
134 |
-
__('If a theme or plugin loads subsets you don\'t need, use this option to force all Google Fonts to be loaded in the selected subsets. You can also use this option to force the loading of additional subsets, if a theme/plugin doesn\'t allow you to configure the loaded subsets.', $this->plugin_text_domain) . ' ' . $this->promo,
|
135 |
true,
|
136 |
true
|
137 |
);
|
39 |
add_filter('omgf_optimize_settings_content', [$this, 'do_optimization_mode'], 30);
|
40 |
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_combine_requests'], 40);
|
41 |
add_filter('omgf_optimize_settings_content', [$this, 'do_display_option'], 50);
|
42 |
+
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_include_file_types'], 60);
|
43 |
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_force_subsets'], 70);
|
44 |
add_filter('omgf_optimize_settings_content', [$this, 'do_after'], 100);
|
45 |
|
67 |
<?php
|
68 |
}
|
69 |
|
70 |
+
/**
|
71 |
+
*
|
72 |
+
* @return void
|
73 |
+
*/
|
74 |
public function do_optimization_mode()
|
75 |
{
|
76 |
$this->do_radio(
|
78 |
OMGF_Admin_Settings::OMGF_OPTIMIZATION_MODE,
|
79 |
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE,
|
80 |
OMGF_OPTIMIZATION_MODE,
|
81 |
+
__('<strong>Manual</strong> processing mode is best suited for configurations, which use a fixed number of fonts across the entire site. When in manual mode, the generated stylesheet is forced throughout the entire site. <strong>Automatic</strong> processing mode is best suited for configurations using e.g. page builders, which load different fonts on certain pages.', $this->plugin_text_domain)
|
82 |
);
|
83 |
}
|
84 |
|
115 |
*
|
116 |
* @return void
|
117 |
*/
|
118 |
+
public function do_promo_include_file_types()
|
119 |
{
|
120 |
+
$this->do_select(
|
121 |
+
__('Include File Types (Pro)', $this->plugin_text_domain),
|
122 |
+
'omgf_pro_file_types',
|
123 |
+
OMGF_Admin_Settings::OMGF_FILE_TYPES_OPTIONS,
|
124 |
+
defined('OMGF_PRO_FILE_TYPES') ? OMGF_PRO_FILE_TYPES : [],
|
125 |
+
__('Select which file types should be included in the stylesheet. Loading <strong>WOFF2</strong> files only will result in a smaller stylesheet, but will make the stylesheet slightly less Cross Browser compatible. Using <strong>WOFF</strong> and <strong>WOFF2</strong> together (default) accounts for +98% of browsers. Add <strong>EOT</strong> for IE 6-10 and <strong>TTF</strong> and <strong>SVG</strong> for legacy Android/iOS browsers. <em>Use CTRL + click to select multiple values</em>.', $this->plugin_text_domain) . ' ' . $this->promo,
|
126 |
+
true,
|
127 |
+
true
|
128 |
);
|
129 |
}
|
130 |
|
138 |
'omgf_pro_force_subsets',
|
139 |
OMGF_Admin_Settings::OMGF_FORCE_SUBSETS_OPTIONS,
|
140 |
defined('OMGF_PRO_FORCE_SUBSETS') ? OMGF_PRO_FORCE_SUBSETS : [],
|
141 |
+
__('If a theme or plugin loads subsets you don\'t need, use this option to force all Google Fonts to be loaded in the selected subsets. You can also use this option to force the loading of additional subsets, if a theme/plugin doesn\'t allow you to configure the loaded subsets. <em>Use CTRL + click to select multiple values</em>.', $this->plugin_text_domain) . ' ' . $this->promo,
|
142 |
true,
|
143 |
true
|
144 |
);
|
includes/api/class-download.php
CHANGED
@@ -138,23 +138,24 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
138 |
$font->variants = $this->filter_variants($font->id, $font->variants, $fonts_request, $original_handle);
|
139 |
}
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
foreach ($fonts as &$font) {
|
142 |
$font_id = $font->id;
|
143 |
|
144 |
foreach ($font->variants as &$variant) {
|
145 |
-
$filename
|
146 |
-
$variant->woff2 = $this->download($variant->woff2, $filename);
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
continue;
|
153 |
}
|
154 |
-
|
155 |
-
$variant->woff = $this->download($variant->woff, $filename);
|
156 |
-
$variant->eot = $this->download($variant->eot, $filename);
|
157 |
-
$variant->ttf = $this->download($variant->ttf, $filename);
|
158 |
}
|
159 |
}
|
160 |
|
@@ -437,12 +438,14 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
437 |
}
|
438 |
|
439 |
/**
|
440 |
-
* @param $url
|
441 |
-
* @param $filename
|
442 |
-
*
|
443 |
-
* @return string
|
|
|
|
|
444 |
*/
|
445 |
-
private function download($url, $filename)
|
446 |
{
|
447 |
if (!function_exists('download_url')) {
|
448 |
require_once ABSPATH . 'wp-admin/includes/file.php';
|
@@ -450,8 +453,8 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
450 |
|
451 |
wp_mkdir_p($this->path);
|
452 |
|
453 |
-
$file
|
454 |
-
$file_uri
|
455 |
|
456 |
if (file_exists($file)) {
|
457 |
return content_url($file_uri);
|
@@ -475,8 +478,14 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
475 |
*/
|
476 |
private function generate_stylesheet($fonts)
|
477 |
{
|
478 |
-
|
|
|
|
|
|
|
|
|
|
|
479 |
$font_display = OMGF_DISPLAY_OPTION;
|
|
|
480 |
|
481 |
foreach ($fonts as $font) {
|
482 |
/**
|
@@ -498,10 +507,12 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
498 |
$stylesheet .= " font-display: $font_display;\n";
|
499 |
|
500 |
/**
|
501 |
-
*
|
502 |
*/
|
503 |
-
if (
|
504 |
$stylesheet .= " src: url('" . $variant->eot . "');\n";
|
|
|
|
|
505 |
}
|
506 |
|
507 |
$local_src = '';
|
@@ -512,16 +523,11 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
512 |
}
|
513 |
}
|
514 |
|
515 |
-
$stylesheet
|
516 |
-
|
517 |
-
$font_src_url = isset($variant->woff2) ? ['woff2' => $variant->woff2] : [];
|
518 |
|
519 |
-
|
520 |
-
|
521 |
-
*/
|
522 |
-
if (!OMGF_WOFF2_ONLY) {
|
523 |
-
$font_src_url = $font_src_url + (isset($variant->woff) ? ['woff' => $variant->woff] : []);
|
524 |
-
$font_src_url = $font_src_url + (isset($variant->ttf) ? ['ttf' => $variant->ttf] : []);
|
525 |
}
|
526 |
|
527 |
$stylesheet .= $this->build_source_string($font_src_url);
|
@@ -570,13 +576,13 @@ class OMGF_API_Download extends WP_REST_Controller
|
|
570 |
*/
|
571 |
private function build_source_string($sources, $type = 'url', $end_semi_colon = true)
|
572 |
{
|
573 |
-
$
|
574 |
-
$source
|
575 |
|
576 |
foreach ($sources as $format => $url) {
|
577 |
$source .= " $type('$url')" . (!is_numeric($format) ? " format('$format')" : '');
|
578 |
|
579 |
-
if ($url === $
|
580 |
$source .= ";\n";
|
581 |
} else {
|
582 |
$source .= ",\n";
|
138 |
$font->variants = $this->filter_variants($font->id, $font->variants, $fonts_request, $original_handle);
|
139 |
}
|
140 |
|
141 |
+
/**
|
142 |
+
* Which file types should we download and include in the stylesheet?
|
143 |
+
*
|
144 |
+
* @since v4.5
|
145 |
+
*/
|
146 |
+
$file_types = apply_filters('omgf_include_file_types', ['woff2', 'woff', 'eot', 'ttf', 'svg']);
|
147 |
+
|
148 |
foreach ($fonts as &$font) {
|
149 |
$font_id = $font->id;
|
150 |
|
151 |
foreach ($font->variants as &$variant) {
|
152 |
+
$filename = strtolower($font_id . '-' . $variant->fontStyle . '-' . $variant->fontWeight);
|
|
|
153 |
|
154 |
+
foreach ($file_types as $file_type) {
|
155 |
+
if (isset($variant->$file_type)) {
|
156 |
+
$variant->$file_type = $this->download($variant->$file_type, $filename, $file_type);
|
157 |
+
}
|
|
|
158 |
}
|
|
|
|
|
|
|
|
|
159 |
}
|
160 |
}
|
161 |
|
438 |
}
|
439 |
|
440 |
/**
|
441 |
+
* @param mixed $url
|
442 |
+
* @param mixed $filename
|
443 |
+
* @param mixed $extension
|
444 |
+
* @return string
|
445 |
+
* @throws SodiumException
|
446 |
+
* @throws TypeError
|
447 |
*/
|
448 |
+
private function download($url, $filename, $extension)
|
449 |
{
|
450 |
if (!function_exists('download_url')) {
|
451 |
require_once ABSPATH . 'wp-admin/includes/file.php';
|
453 |
|
454 |
wp_mkdir_p($this->path);
|
455 |
|
456 |
+
$file = $this->path . '/' . $filename . '.' . $extension;
|
457 |
+
$file_uri = str_replace(WP_CONTENT_DIR, '', $file);
|
458 |
|
459 |
if (file_exists($file)) {
|
460 |
return content_url($file_uri);
|
478 |
*/
|
479 |
private function generate_stylesheet($fonts)
|
480 |
{
|
481 |
+
/**
|
482 |
+
* Which file types should we download and include in the stylesheet?
|
483 |
+
*
|
484 |
+
* @since v4.5
|
485 |
+
*/
|
486 |
+
$file_types = apply_filters('omgf_include_file_types', ['woff2', 'woff', 'eot', 'ttf']);
|
487 |
$font_display = OMGF_DISPLAY_OPTION;
|
488 |
+
$stylesheet = "/**\n * Auto Generated by OMGF\n * @author: Daan van den Bergh\n * @url: https://ffw.press\n */\n\n";
|
489 |
|
490 |
foreach ($fonts as $font) {
|
491 |
/**
|
507 |
$stylesheet .= " font-display: $font_display;\n";
|
508 |
|
509 |
/**
|
510 |
+
* For IE compatibility, EOT is added before the local family name is defined.
|
511 |
*/
|
512 |
+
if (in_array('eot', $file_types)) {
|
513 |
$stylesheet .= " src: url('" . $variant->eot . "');\n";
|
514 |
+
$eot_key = array_search('eot', $file_types);
|
515 |
+
unset($file_types[$eot_key]);
|
516 |
}
|
517 |
|
518 |
$local_src = '';
|
523 |
}
|
524 |
}
|
525 |
|
526 |
+
$stylesheet .= " src: $local_src\n";
|
527 |
+
$font_src_url = [];
|
|
|
528 |
|
529 |
+
foreach ($file_types as $file_type) {
|
530 |
+
$font_src_url = $font_src_url + (isset($variant->$file_type) ? [$file_type => $variant->$file_type] : []);
|
|
|
|
|
|
|
|
|
531 |
}
|
532 |
|
533 |
$stylesheet .= $this->build_source_string($font_src_url);
|
576 |
*/
|
577 |
private function build_source_string($sources, $type = 'url', $end_semi_colon = true)
|
578 |
{
|
579 |
+
$last_src = end($sources);
|
580 |
+
$source = '';
|
581 |
|
582 |
foreach ($sources as $format => $url) {
|
583 |
$source .= " $type('$url')" . (!is_numeric($format) ? " format('$format')" : '');
|
584 |
|
585 |
+
if ($url === $last_src && $end_semi_colon) {
|
586 |
$source .= ";\n";
|
587 |
} else {
|
588 |
$source .= ",\n";
|
includes/class-admin.php
CHANGED
@@ -40,11 +40,7 @@ class OMGF_Admin
|
|
40 |
[
|
41 |
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE,
|
42 |
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION,
|
43 |
-
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_WOFF2_ONLY,
|
44 |
OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH,
|
45 |
-
OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI,
|
46 |
-
OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL,
|
47 |
-
OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL
|
48 |
]
|
49 |
);
|
50 |
|
40 |
[
|
41 |
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE,
|
42 |
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION,
|
|
|
43 |
OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH,
|
|
|
|
|
|
|
44 |
]
|
45 |
);
|
46 |
|
includes/class-omgf.php
CHANGED
@@ -36,11 +36,6 @@ class OMGF
|
|
36 |
|
37 |
add_action('admin_init', [$this, 'do_optimize']);
|
38 |
add_action('rest_api_init', [$this, 'register_routes']);
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Proper rewrite URLs
|
42 |
-
*/
|
43 |
-
add_filter('content_url', [$this, 'rewrite_url'], 10, 2);
|
44 |
add_filter('content_url', [$this, 'force_ssl'], 1000, 2);
|
45 |
|
46 |
/**
|
@@ -59,12 +54,8 @@ class OMGF
|
|
59 |
define('OMGF_MANUAL_OPTIMIZE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL, site_url())));
|
60 |
define('OMGF_FONT_PROCESSING', esc_attr(get_option(OMGF_Admin_Settings::OMGF_DETECTION_SETTING_FONT_PROCESSING, 'replace')));
|
61 |
define('OMGF_DISPLAY_OPTION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION, 'swap')) ?: 'swap');
|
62 |
-
define('OMGF_WOFF2_ONLY', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_WOFF2_ONLY)));
|
63 |
define('OMGF_OPTIMIZE_EDIT_ROLES', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZE_EDIT_ROLES, 'on')));
|
64 |
define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH)) ?: '/uploads/omgf');
|
65 |
-
define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI)) ?: '');
|
66 |
-
define('OMGF_RELATIVE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL)));
|
67 |
-
define('OMGF_CDN_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL)));
|
68 |
define('OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH);
|
69 |
define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
|
70 |
define('OMGF_UNLOAD_STYLESHEETS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, '')));
|
@@ -213,7 +204,12 @@ class OMGF
|
|
213 |
$new_version = $plugin['new_version'];
|
214 |
|
215 |
if (version_compare($current_version, $new_version, '<')) {
|
216 |
-
$response
|
|
|
|
|
|
|
|
|
|
|
217 |
$update_notices = (array) json_decode(wp_remote_retrieve_body($response));
|
218 |
|
219 |
if (!isset($update_notices[$new_version])) {
|
@@ -227,41 +223,6 @@ class OMGF
|
|
227 |
}
|
228 |
}
|
229 |
|
230 |
-
/**
|
231 |
-
* @param $url
|
232 |
-
* @param $path
|
233 |
-
*
|
234 |
-
* @return mixed
|
235 |
-
*/
|
236 |
-
public function rewrite_url($url, $path)
|
237 |
-
{
|
238 |
-
/**
|
239 |
-
* Exit early if this isn't requested by OMGF.
|
240 |
-
*/
|
241 |
-
if (strpos($url, OMGF_CACHE_PATH) === false) {
|
242 |
-
return $url;
|
243 |
-
}
|
244 |
-
|
245 |
-
/**
|
246 |
-
* If Relative URLs is enabled, overwrite URL with Path and continue execution.
|
247 |
-
*/
|
248 |
-
if (OMGF_RELATIVE_URL) {
|
249 |
-
$content_dir = str_replace(home_url(), '', content_url());
|
250 |
-
|
251 |
-
$url = $content_dir . $path;
|
252 |
-
}
|
253 |
-
|
254 |
-
if (OMGF_CDN_URL) {
|
255 |
-
$url = str_replace(home_url(), OMGF_CDN_URL, $url);
|
256 |
-
}
|
257 |
-
|
258 |
-
if (OMGF_CACHE_URI) {
|
259 |
-
$url = str_replace(OMGF_CACHE_PATH, OMGF_CACHE_URI, $url);
|
260 |
-
}
|
261 |
-
|
262 |
-
return $url;
|
263 |
-
}
|
264 |
-
|
265 |
/**
|
266 |
* content_url() uses is_ssl() to detect whether SSL is used. This fails for servers behind
|
267 |
* load balancers and/or reverse proxies. So, we double check with this filter.
|
36 |
|
37 |
add_action('admin_init', [$this, 'do_optimize']);
|
38 |
add_action('rest_api_init', [$this, 'register_routes']);
|
|
|
|
|
|
|
|
|
|
|
39 |
add_filter('content_url', [$this, 'force_ssl'], 1000, 2);
|
40 |
|
41 |
/**
|
54 |
define('OMGF_MANUAL_OPTIMIZE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL, site_url())));
|
55 |
define('OMGF_FONT_PROCESSING', esc_attr(get_option(OMGF_Admin_Settings::OMGF_DETECTION_SETTING_FONT_PROCESSING, 'replace')));
|
56 |
define('OMGF_DISPLAY_OPTION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION, 'swap')) ?: 'swap');
|
|
|
57 |
define('OMGF_OPTIMIZE_EDIT_ROLES', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZE_EDIT_ROLES, 'on')));
|
58 |
define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH)) ?: '/uploads/omgf');
|
|
|
|
|
|
|
59 |
define('OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH);
|
60 |
define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
|
61 |
define('OMGF_UNLOAD_STYLESHEETS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS, '')));
|
204 |
$new_version = $plugin['new_version'];
|
205 |
|
206 |
if (version_compare($current_version, $new_version, '<')) {
|
207 |
+
$response = wp_remote_get('https://daan.dev/omgf-update-notices.json');
|
208 |
+
|
209 |
+
if (is_wp_error($response)) {
|
210 |
+
return;
|
211 |
+
}
|
212 |
+
|
213 |
$update_notices = (array) json_decode(wp_remote_retrieve_body($response));
|
214 |
|
215 |
if (!isset($update_notices[$new_version])) {
|
223 |
}
|
224 |
}
|
225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
/**
|
227 |
* content_url() uses is_ssl() to detect whether SSL is used. This fails for servers behind
|
228 |
* load balancers and/or reverse proxies. So, we double check with this filter.
|
includes/class-optimize.php
CHANGED
@@ -63,12 +63,10 @@ class OMGF_Optimize
|
|
63 |
|
64 |
add_filter('http_request_args', [$this, 'verify_ssl']);
|
65 |
|
66 |
-
|
67 |
-
$this->run_manual();
|
68 |
-
}
|
69 |
|
70 |
-
if ('
|
71 |
-
$this->
|
72 |
}
|
73 |
}
|
74 |
|
@@ -167,18 +165,6 @@ class OMGF_Optimize
|
|
167 |
add_settings_error('general', 'omgf_no_urls_found', sprintf(__('No (additional) Google Fonts found to optimize. If you believe this is an error, please refer to the %stroubleshooting%s section of the documentation for possible solutions.', $this->plugin_text_domain), '<a href="https://ffw.press/docs/omgf-pro/troubleshooting">', '</a>'), 'info');
|
168 |
}
|
169 |
|
170 |
-
/**
|
171 |
-
*
|
172 |
-
*/
|
173 |
-
private function run_auto()
|
174 |
-
{
|
175 |
-
OMGF_Admin_Notice::set_notice(
|
176 |
-
__('OMGF Optimization is silently running in the background. After visiting a few pages, return here to manage the captured Google Fonts.', $this->plugin_text_domain),
|
177 |
-
'omgf-auto-running',
|
178 |
-
false
|
179 |
-
);
|
180 |
-
}
|
181 |
-
|
182 |
/**
|
183 |
* Wrapper for wp_remote_get() with preset params.
|
184 |
*
|
63 |
|
64 |
add_filter('http_request_args', [$this, 'verify_ssl']);
|
65 |
|
66 |
+
$optimization_mode = apply_filters('omgf_optimization_mode', OMGF_OPTIMIZATION_MODE);
|
|
|
|
|
67 |
|
68 |
+
if ('manual' == $optimization_mode) {
|
69 |
+
$this->run_manual();
|
70 |
}
|
71 |
}
|
72 |
|
165 |
add_settings_error('general', 'omgf_no_urls_found', sprintf(__('No (additional) Google Fonts found to optimize. If you believe this is an error, please refer to the %stroubleshooting%s section of the documentation for possible solutions.', $this->plugin_text_domain), '<a href="https://ffw.press/docs/omgf-pro/troubleshooting">', '</a>'), 'info');
|
166 |
}
|
167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
/**
|
169 |
* Wrapper for wp_remote_get() with preset params.
|
170 |
*
|
includes/frontend/class-functions.php
CHANGED
@@ -182,7 +182,7 @@ class OMGF_Frontend_Functions
|
|
182 |
continue;
|
183 |
}
|
184 |
|
185 |
-
if (OMGF_OPTIMIZATION_MODE == '
|
186 |
$api_url = str_replace(['http:', 'https:'], '', home_url('/wp-json/omgf/v1/download/'));
|
187 |
$protocol = '';
|
188 |
|
182 |
continue;
|
183 |
}
|
184 |
|
185 |
+
if (OMGF_OPTIMIZATION_MODE == 'manual' && isset($_GET['omgf_optimize'])) {
|
186 |
$api_url = str_replace(['http:', 'https:'], '', home_url('/wp-json/omgf/v1/download/'));
|
187 |
$protocol = '';
|
188 |
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
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.
|
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
|
@@ -37,18 +37,25 @@ Please keep in mind that, although I try to make the configuration of this plugi
|
|
37 |
- Manage Optimized Google Fonts,
|
38 |
- Preload above the fold fonts,
|
39 |
- Don't load certain fonts or entire stylesheets.
|
40 |
-
- Leverage the font-display (swap) option
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
= Features in the PRO version =
|
45 |
Everything in the free version, plus:
|
|
|
46 |
- Automatically remove/replace all Google Fonts throughout the entire document/page,
|
47 |
-
- Also supports WebFont Loader (webfont.js)
|
|
|
48 |
- Combine all Google Fonts (made by your theme and/or plugins) stylesheets into one file,
|
49 |
- Deduplicate Google Fonts stylesheets,
|
|
|
50 |
- Reduce loading time and page size, by forcing the used subset(s) for all Google Fonts requests,
|
51 |
-
- Remove Resource Hints (preload, preconnect, dns-prefetch) pointing to fonts.googleapis.com or fonts.gstatic.com
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
*[Purchase OMGF Pro](https://ffw.press/wordpress/omgf-pro/) | [Documentation](https://ffw.press/docs/omgf-pro/) | [Tested Plugins & Themes](https://ffw.press/docs/omgf-pro/troubleshooting/compatibility/)*
|
54 |
|
@@ -123,9 +130,16 @@ No, not yet. But I will definitely try to make it compatible in the future!
|
|
123 |
|
124 |
== Changelog ==
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
= 4.4.4 =
|
127 |
* Fixed logo for Safari compatibility.
|
128 |
-
* Added
|
129 |
|
130 |
= 4.4.3 =
|
131 |
* Fixed a few warnings/notices.
|
2 |
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.8
|
6 |
+
Stable tag: 4.5.0
|
7 |
Requires PHP: 7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
37 |
- Manage Optimized Google Fonts,
|
38 |
- Preload above the fold fonts,
|
39 |
- Don't load certain fonts or entire stylesheets.
|
40 |
+
- Leverage the font-display (swap) option.
|
41 |
+
|
42 |
+
= Additional Features in OMGF Pro =
|
43 |
|
|
|
44 |
Everything in the free version, plus:
|
45 |
+
|
46 |
- Automatically remove/replace all Google Fonts throughout the entire document/page,
|
47 |
+
- Also supports WebFont Loader (webfont.js), Early Access Google Fonts and requests in stylesheets using @import (@font-face coming soon...).
|
48 |
+
- Automatically generate different stylesheets for pages with another configuration of Google Fonts.
|
49 |
- Combine all Google Fonts (made by your theme and/or plugins) stylesheets into one file,
|
50 |
- Deduplicate Google Fonts stylesheets,
|
51 |
+
- Define file types to include in stylesheet (WOFF, WOFF2, EOT, TTF, SVG),
|
52 |
- Reduce loading time and page size, by forcing the used subset(s) for all Google Fonts requests,
|
53 |
+
- Remove Resource Hints (preload, preconnect, dns-prefetch) pointing to fonts.googleapis.com or fonts.gstatic.com,
|
54 |
+
- Modify `src` attribute for fonts in stylesheet using the Fonts Source URL option to fully integrate with your configuration,
|
55 |
+
- Use this to serve fonts and the stylesheets from your CDN, or
|
56 |
+
- To serve fonts from an alternative path (e.g. when you're using Security through Obscurity plugins like WP Hide, etc.), or
|
57 |
+
- Anything you like!
|
58 |
+
- Proper handling for AMP pages (Fallback to or remove Google Fonts).
|
59 |
|
60 |
*[Purchase OMGF Pro](https://ffw.press/wordpress/omgf-pro/) | [Documentation](https://ffw.press/docs/omgf-pro/) | [Tested Plugins & Themes](https://ffw.press/docs/omgf-pro/troubleshooting/compatibility/)*
|
61 |
|
130 |
|
131 |
== Changelog ==
|
132 |
|
133 |
+
= 4.5.0 | July 28th, 2021 =
|
134 |
+
* [Removed] WOFF2 only option is superseded by Include File Types option, only available in OMGF Pro.
|
135 |
+
* [Removed] CDN URL, Cache URI and Relative URL options are combined into Fonts Source URL option, only available in OMGF Pro.
|
136 |
+
* [Removed] Optimization Mode > Automatic is only available in OMGF Pro.
|
137 |
+
* Tested with WordPress 5.8
|
138 |
+
* Several code optimizations.
|
139 |
+
|
140 |
= 4.4.4 =
|
141 |
* Fixed logo for Safari compatibility.
|
142 |
+
* Added updater notices for future important updates.
|
143 |
|
144 |
= 4.4.3 =
|
145 |
* Fixed a few warnings/notices.
|