Version Description
Improved overall error handling for Auto Detect and downloading using cURL.
Download this release
Release Info
Developer | DaanvandenBergh |
Plugin | OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy. |
Version | 2.2.5 |
Comparing to | |
See all releases |
Code changes from version 2.2.4 to 2.2.5
- host-webfonts-local.php +1 -1
- includes/ajax/class-detect.php +1 -1
- includes/class-ajax.php +21 -8
- js/hwl-admin.js +26 -11
- readme.txt +4 -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: 2.2.
|
8 |
* Author: Daan van den Bergh
|
9 |
* Author URI: https://daan.dev
|
10 |
* License: GPL2v2 or later
|
4 |
* Plugin Name: OMGF
|
5 |
* Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
|
6 |
* Description: Minimize DNS requests and leverage browser cache by easily saving Google Fonts to your server and removing the external Google Fonts.
|
7 |
+
* Version: 2.2.5
|
8 |
* Author: Daan van den Bergh
|
9 |
* Author URI: https://daan.dev
|
10 |
* License: GPL2v2 or later
|
includes/ajax/class-detect.php
CHANGED
@@ -36,7 +36,7 @@ class OMGF_AJAX_Detect
|
|
36 |
/** It only needs to run once. */
|
37 |
update_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, false);
|
38 |
|
39 |
-
|
40 |
}
|
41 |
|
42 |
/**
|
36 |
/** It only needs to run once. */
|
37 |
update_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, false);
|
38 |
|
39 |
+
wp_send_json_success($fonts);
|
40 |
}
|
41 |
|
42 |
/**
|
includes/class-ajax.php
CHANGED
@@ -25,6 +25,10 @@ class OMGF_AJAX
|
|
25 |
*/
|
26 |
public function __construct()
|
27 |
{
|
|
|
|
|
|
|
|
|
28 |
$this->db = new OMGF_DB();
|
29 |
|
30 |
// @formatter:off
|
@@ -111,9 +115,9 @@ class OMGF_AJAX
|
|
111 |
'subsets' => $result->subsets
|
112 |
);
|
113 |
}
|
114 |
-
|
115 |
} catch (\Exception $e) {
|
116 |
-
|
117 |
}
|
118 |
}
|
119 |
|
@@ -131,17 +135,20 @@ class OMGF_AJAX
|
|
131 |
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
|
132 |
|
133 |
$result = curl_exec($request);
|
|
|
134 |
curl_close($request);
|
135 |
|
136 |
-
|
137 |
-
$used_styles['variants'] = array_values($this->process_used_styles($_POST['used_styles'], json_decode($result)->variants));
|
138 |
|
139 |
-
|
|
|
|
|
|
|
140 |
}
|
141 |
|
142 |
-
|
143 |
} catch (\Exception $e) {
|
144 |
-
|
145 |
}
|
146 |
}
|
147 |
|
@@ -186,11 +193,17 @@ class OMGF_AJAX
|
|
186 |
new OMGF_AJAX_Detect($used_fonts);
|
187 |
}
|
188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
$this->enable_auto_detect();
|
190 |
|
191 |
$url = get_permalink(get_posts()[0]->ID);
|
192 |
|
193 |
-
|
194 |
}
|
195 |
|
196 |
/**
|
25 |
*/
|
26 |
public function __construct()
|
27 |
{
|
28 |
+
if (!function_exists('curl_exec')) {
|
29 |
+
$this->throw_error(500, 'cURL is disabled on your server and required for OMGF to function properly. Contact your hosting provider for assistance to enable cURL on your server.');
|
30 |
+
}
|
31 |
+
|
32 |
$this->db = new OMGF_DB();
|
33 |
|
34 |
// @formatter:off
|
115 |
'subsets' => $result->subsets
|
116 |
);
|
117 |
}
|
118 |
+
wp_send_json_success($response);
|
119 |
} catch (\Exception $e) {
|
120 |
+
wp_send_json_error($e->getMessage(), $e->getCode());
|
121 |
}
|
122 |
}
|
123 |
|
135 |
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
|
136 |
|
137 |
$result = curl_exec($request);
|
138 |
+
|
139 |
curl_close($request);
|
140 |
|
141 |
+
$result = json_decode($result);
|
|
|
142 |
|
143 |
+
if (!empty($_POST['used_styles']) && is_object($result) && $variants = $result->variants) {
|
144 |
+
$used_styles['variants'] = array_values($this->process_used_styles($_POST['used_styles'], $variants));
|
145 |
+
|
146 |
+
wp_send_json_success($used_styles);
|
147 |
}
|
148 |
|
149 |
+
wp_send_json_success($result);
|
150 |
} catch (\Exception $e) {
|
151 |
+
wp_send_json_error($e->getMessage(), $e->getCode());
|
152 |
}
|
153 |
}
|
154 |
|
193 |
new OMGF_AJAX_Detect($used_fonts);
|
194 |
}
|
195 |
|
196 |
+
if ((!$used_fonts && $auto_detect) || ($used_fonts && !$auto_detect)) {
|
197 |
+
update_option(OMGF_Admin_Settings::OMGF_SETTING_DETECTED_FONTS, '');
|
198 |
+
update_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, null);
|
199 |
+
$this->throw_error(406, 'Something went wrong while trying to enable Auto Detection. <a href="javascript:location.reload()">Refresh this page</a> and try again.');
|
200 |
+
}
|
201 |
+
|
202 |
$this->enable_auto_detect();
|
203 |
|
204 |
$url = get_permalink(get_posts()[0]->ID);
|
205 |
|
206 |
+
wp_send_json_success(__("Auto-detection mode enabled. Open any page on your frontend (e.g. your <a href='$url' target='_blank'>latest post</a>). After the page is fully loaded, return here and <a href='javascript:location.reload()'>click here</a> to refresh this page. Then click 'Load fonts'.", "host-webfonts-local"));
|
207 |
}
|
208 |
|
209 |
/**
|
js/hwl-admin.js
CHANGED
@@ -45,7 +45,10 @@ function hwlSearchFontSubsets(queriedFonts)
|
|
45 |
hwlUpdateInputValue(searchButton, 'Searching...', '0 20px');
|
46 |
searchField.val('');
|
47 |
},
|
48 |
-
|
|
|
|
|
|
|
49 |
hwlUpdateInputValue(searchButton, 'Search', '0 36px');
|
50 |
hwlRenderAvailableSubsets(response);
|
51 |
}
|
@@ -68,15 +71,18 @@ function hwlAutoDetectFonts()
|
|
68 |
hwlCleanQueue();
|
69 |
}
|
70 |
},
|
|
|
|
|
|
|
71 |
complete: function(response) {
|
72 |
if (omgf.auto_detect_enabled === '' && omgf.detected_fonts === '') {
|
73 |
hwlScrollTop();
|
74 |
-
jQuery('#hwl-admin-notices').append("<div class='notice notice-success is-dismissible'><p>" + response
|
75 |
hwlUpdateInputValue(detectButton, 'Enabled', '0 38px 1px');
|
76 |
} else {
|
77 |
try {
|
78 |
hwlUpdateInputValue(detectButton, 'Auto-detect', '0 36px 1px');
|
79 |
-
hwlRenderAvailableSubsets(response);
|
80 |
} catch(error) {
|
81 |
hwlScrollTop();
|
82 |
jQuery('#hwl-admin-notices').append("<div class='notice notice-success is-dismissible'><p>Oops! Something went wrong. " + error + ". <a href='javascript:location.reload();'>Refresh this page</a> and try again. If it still fails, <a href='javascript:hwlEmptyDir();'>empty the cache</a> and <a href='javascript:location.reload();'>refresh this page</a>.");
|
@@ -100,8 +106,8 @@ if (omgf.auto_detect_enabled !== '' && omgf.detected_fonts !== '') {
|
|
100 |
*/
|
101 |
function hwlRenderAvailableSubsets(response)
|
102 |
{
|
103 |
-
let data = response
|
104 |
-
let subsetArray = data
|
105 |
|
106 |
for (let ii = 0; ii < subsetArray.length; ii++) {
|
107 |
subsets = subsetArray[ii]['subsets'];
|
@@ -180,10 +186,10 @@ function hwlSearchGoogleFonts(id, subsets, usedStyles = null)
|
|
180 |
beforeSend: function() {
|
181 |
loadingDiv.show()
|
182 |
},
|
183 |
-
error: function() {
|
184 |
-
|
185 |
},
|
186 |
-
|
187 |
loadingDiv.hide();
|
188 |
errorDiv.hide();
|
189 |
if(response['responseText'] !== 'Not found') {
|
@@ -195,6 +201,16 @@ function hwlSearchGoogleFonts(id, subsets, usedStyles = null)
|
|
195 |
})
|
196 |
}
|
197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
/**
|
199 |
* Displays the search results
|
200 |
*
|
@@ -202,8 +218,7 @@ function hwlSearchGoogleFonts(id, subsets, usedStyles = null)
|
|
202 |
*/
|
203 |
function hwlRenderAvailableFonts(results)
|
204 |
{
|
205 |
-
|
206 |
-
variants = response['variants'];
|
207 |
length = variants.length;
|
208 |
renderedFonts = [];
|
209 |
for(iii = 0; iii < length; iii++) {
|
@@ -368,7 +383,7 @@ function hwlUpdateStatusBar(progress)
|
|
368 |
*/
|
369 |
function hwlGenerateStylesheet()
|
370 |
{
|
371 |
-
let hwlFonts = hwlSerializeArray(jQuery('#hwl-options-form'))
|
372 |
let generateButton = jQuery('#generate-btn');
|
373 |
jQuery.ajax({
|
374 |
type: 'POST',
|
45 |
hwlUpdateInputValue(searchButton, 'Searching...', '0 20px');
|
46 |
searchField.val('');
|
47 |
},
|
48 |
+
error: function(response) {
|
49 |
+
displayError(response.responseJSON.data);
|
50 |
+
},
|
51 |
+
success: function(response) {
|
52 |
hwlUpdateInputValue(searchButton, 'Search', '0 36px');
|
53 |
hwlRenderAvailableSubsets(response);
|
54 |
}
|
71 |
hwlCleanQueue();
|
72 |
}
|
73 |
},
|
74 |
+
error: function (response) {
|
75 |
+
displayError(response.responseJSON.data);
|
76 |
+
},
|
77 |
complete: function(response) {
|
78 |
if (omgf.auto_detect_enabled === '' && omgf.detected_fonts === '') {
|
79 |
hwlScrollTop();
|
80 |
+
jQuery('#hwl-admin-notices').append("<div class='notice notice-success is-dismissible'><p>" + response.responseJSON.data + "</p></div>");
|
81 |
hwlUpdateInputValue(detectButton, 'Enabled', '0 38px 1px');
|
82 |
} else {
|
83 |
try {
|
84 |
hwlUpdateInputValue(detectButton, 'Auto-detect', '0 36px 1px');
|
85 |
+
hwlRenderAvailableSubsets(response.responseJSON);
|
86 |
} catch(error) {
|
87 |
hwlScrollTop();
|
88 |
jQuery('#hwl-admin-notices').append("<div class='notice notice-success is-dismissible'><p>Oops! Something went wrong. " + error + ". <a href='javascript:location.reload();'>Refresh this page</a> and try again. If it still fails, <a href='javascript:hwlEmptyDir();'>empty the cache</a> and <a href='javascript:location.reload();'>refresh this page</a>.");
|
106 |
*/
|
107 |
function hwlRenderAvailableSubsets(response)
|
108 |
{
|
109 |
+
let data = response.data;
|
110 |
+
let subsetArray = data.subsets === undefined ? data : data.subsets;
|
111 |
|
112 |
for (let ii = 0; ii < subsetArray.length; ii++) {
|
113 |
subsets = subsetArray[ii]['subsets'];
|
186 |
beforeSend: function() {
|
187 |
loadingDiv.show()
|
188 |
},
|
189 |
+
error: function(response) {
|
190 |
+
displayError(response.responseJSON.data);
|
191 |
},
|
192 |
+
success: function(response) {
|
193 |
loadingDiv.hide();
|
194 |
errorDiv.hide();
|
195 |
if(response['responseText'] !== 'Not found') {
|
201 |
})
|
202 |
}
|
203 |
|
204 |
+
function displayError(message) {
|
205 |
+
let loadingDiv = jQuery('#hwl-warning .loading');
|
206 |
+
let errorDiv = jQuery('#hwl-warning .error');
|
207 |
+
|
208 |
+
loadingDiv.hide();
|
209 |
+
errorDiv.show();
|
210 |
+
hwlScrollTop();
|
211 |
+
jQuery('#hwl-admin-notices').html("<div class='notice notice-success is-dismissible'><p>Oops! Something went wrong. " + message + ".");
|
212 |
+
}
|
213 |
+
|
214 |
/**
|
215 |
* Displays the search results
|
216 |
*
|
218 |
*/
|
219 |
function hwlRenderAvailableFonts(results)
|
220 |
{
|
221 |
+
variants = results.data.variants === undefined ? results.responseJSON.data.variants : results.data.variants;
|
|
|
222 |
length = variants.length;
|
223 |
renderedFonts = [];
|
224 |
for(iii = 0; iii < length; iii++) {
|
383 |
*/
|
384 |
function hwlGenerateStylesheet()
|
385 |
{
|
386 |
+
let hwlFonts = hwlSerializeArray(jQuery('#hwl-options-form'));
|
387 |
let generateButton = jQuery('#generate-btn');
|
388 |
jQuery.ajax({
|
389 |
type: 'POST',
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ 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.3
|
7 |
-
Stable tag: 2.2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -115,6 +115,9 @@ N/A
|
|
115 |
|
116 |
== Changelog ==
|
117 |
|
|
|
|
|
|
|
118 |
= 2.2.4 =
|
119 |
Auto-detect is now loaded before 'Remove Google Fonts' and both are loaded absolute last.
|
120 |
|
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.3
|
7 |
+
Stable tag: 2.2.5
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
115 |
|
116 |
== Changelog ==
|
117 |
|
118 |
+
= 2.2.5 =
|
119 |
+
Improved overall error handling for Auto Detect and downloading using cURL.
|
120 |
+
|
121 |
= 2.2.4 =
|
122 |
Auto-detect is now loaded before 'Remove Google Fonts' and both are loaded absolute last.
|
123 |
|