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

Version Description

Fixed bug where the plugin would sometimes permanently change your upload-director to /local-fonts.

Download this release

Release Info

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

Code changes from version 1.0.1 to 1.1.0

Files changed (5) hide show
  1. .gitignore +4 -0
  2. LICENSE +21 -0
  3. host-webfonts-local.php +115 -33
  4. includes/generate-stylesheet.php +1 -9
  5. readme.txt +9 -3
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ .DS_Store
2
+ .idea
3
+ .git
4
+ .svn
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Daan van den Bergh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
host-webfonts-local.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: CAOS for Webfonts
4
  * Plugin URI: https://dev.daanvandenbergh.com/wordpress-plugins/host-google-fonts-locally
5
  * 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.
6
- * Version: 1.0
7
  * Author: Daan van den Bergh
8
  * Author URI: https://dev.daanvandenbergh.com
9
  * License: GPL2v2 or later
@@ -27,7 +27,6 @@ function hwlSetAllowedFiletypes($filetypes = array()) {
27
 
28
  return $filetypes;
29
  }
30
-
31
  add_filter('upload_mimes', 'hwlSetAllowedFiletypes');
32
 
33
  /**
@@ -42,11 +41,6 @@ function hwlCreateMenu()
42
  'optimize-webfonts',
43
  'hwlSettingsPage'
44
  );
45
-
46
- add_action(
47
- 'admin_init',
48
- 'registerHwlSettings'
49
- );
50
  }
51
 
52
  add_action('admin_menu', 'hwlCreateMenu');
@@ -94,10 +88,6 @@ function hwlSettingsPage()
94
  */
95
  function hwlMediaUploadInit() {
96
  wp_enqueue_media();
97
-
98
- update_option('upload_path',WP_CONTENT_DIR . '/local-fonts');
99
- update_option('upload_url_path',content_url() . '/local-fonts');
100
- update_option('uploads_use_yearmonth_folders', false);
101
  ?>
102
  <table>
103
  <tbody>
@@ -127,25 +117,78 @@ function hwlMediaUploadInit() {
127
  <script type="text/javascript">
128
  var media_uploader = null;
129
 
 
 
 
130
  function hwlFontUploader()
131
  {
132
  media_uploader = wp.media({
133
- frame: "post",
134
- state: "insert",
135
- multiple: true
136
- }).open();
137
-
138
- media_uploader.on("insert", function(){
139
- var length = media_uploader.state().get("selection").length;
140
- var fonts = media_uploader.state().get("selection").models;
141
-
142
- for(var iii = 0; iii < length; iii++)
143
- {
144
- var font_url = fonts[iii].changed.url;
145
- var font_name = fonts[iii].changed.title;
146
- var font_type = fonts[iii].changed.subtype;
147
-
148
- var uploadedFont = `<tr valign="top">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  <td>
150
  <input type="text" name="hwl_uploaded_font][${font_name}]"
151
  id="hwl_uploaded_font][${font_name}]"
@@ -172,10 +215,13 @@ function hwlMediaUploadInit() {
172
  value="${font_url}" readonly />
173
  </td>
174
  </tr>`;
175
- jQuery('#hwl_uploaded_fonts').append(uploadedFont);
176
- }
177
- });
178
  }
 
 
 
 
179
  function hwlGenerateStylesheet() {
180
  var hwlData = hwlSerializeArray($('#hwl-options-form'));
181
 
@@ -187,7 +233,6 @@ function hwlMediaUploadInit() {
187
  uploaded_fonts: hwlData
188
  },
189
  success: function(response) {
190
- console.log(response);
191
  jQuery('#hwl-admin-notices').append(
192
  `<div class="updated settings-error notice is-dismissible">
193
  <p>${response}</p>
@@ -208,6 +253,10 @@ function hwlMediaUploadInit() {
208
  }
209
  });
210
  }
 
 
 
 
211
  function hwlSerializeArray(data) {
212
  var result = [];
213
  data.each(function() {
@@ -224,6 +273,40 @@ function hwlMediaUploadInit() {
224
  <?php
225
  }
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  function hwlAjaxGenerateStyles() {
228
  require_once('includes/generate-stylesheet.php');
229
  }
@@ -240,5 +323,4 @@ function hwlEnqueueStylesheet()
240
  wp_enqueue_style('hwl-style');
241
  }
242
  }
243
-
244
- add_action('wp_enqueue_scripts', 'hwlEnqueueStylesheet' );
3
  * Plugin Name: CAOS for Webfonts
4
  * Plugin URI: https://dev.daanvandenbergh.com/wordpress-plugins/host-google-fonts-locally
5
  * 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.
6
+ * Version: 1.1.0
7
  * Author: Daan van den Bergh
8
  * Author URI: https://dev.daanvandenbergh.com
9
  * License: GPL2v2 or later
27
 
28
  return $filetypes;
29
  }
 
30
  add_filter('upload_mimes', 'hwlSetAllowedFiletypes');
31
 
32
  /**
41
  'optimize-webfonts',
42
  'hwlSettingsPage'
43
  );
 
 
 
 
 
44
  }
45
 
46
  add_action('admin_menu', 'hwlCreateMenu');
88
  */
89
  function hwlMediaUploadInit() {
90
  wp_enqueue_media();
 
 
 
 
91
  ?>
92
  <table>
93
  <tbody>
117
  <script type="text/javascript">
118
  var media_uploader = null;
119
 
120
+ /**
121
+ * Get the Media Uploader and prepare the uploaded fonts for generating the style sheet.
122
+ */
123
  function hwlFontUploader()
124
  {
125
  media_uploader = wp.media({
126
+ frame: "post",
127
+ state: "insert",
128
+ multiple: true
129
+ }).open();
130
+
131
+ hwlSetUploadDir();
132
+
133
+ media_uploader.on(
134
+ "close",
135
+ function() {
136
+ hwlResetUploadDir();
137
+ }
138
+ ).on(
139
+ "insert",
140
+ function() {
141
+ hwlGenerateOutput();
142
+ }
143
+ );
144
+ }
145
+
146
+ /**
147
+ * Call the media-upload script or logs an error to the console.
148
+ */
149
+ function hwlSetUploadDir()
150
+ {
151
+ jQuery.ajax({
152
+ type: 'POST',
153
+ url: ajaxurl,
154
+ data: {
155
+ action: 'hwlAjaxSetUploadDir'
156
+ },
157
+ error: function(response) {
158
+ console.log(response);
159
+ }
160
+ });
161
+ }
162
+
163
+ /**
164
+ * AJAX call to reset upload directory.
165
+ */
166
+ function hwlResetUploadDir()
167
+ {
168
+ jQuery.ajax({
169
+ type: 'POST',
170
+ url: ajaxurl,
171
+ data: {
172
+ action: 'hwlAjaxResetUploadDir'
173
+ },
174
+ error: function(response) {
175
+ console.log(response);
176
+ }
177
+ });
178
+ }
179
+
180
+ /**
181
+ * Generate the output after upload/insert
182
+ */
183
+ function hwlGenerateOutput()
184
+ {
185
+ var length = media_uploader.state().get("selection").length;
186
+ var fonts = media_uploader.state().get("selection").models;
187
+ for (var iii = 0; iii < length; iii++) {
188
+ var font_url = fonts[iii].changed.url;
189
+ var font_name = fonts[iii].changed.title;
190
+ var font_type = fonts[iii].changed.subtype;
191
+ var uploadedFont = `<tr valign="top">
192
  <td>
193
  <input type="text" name="hwl_uploaded_font][${font_name}]"
194
  id="hwl_uploaded_font][${font_name}]"
215
  value="${font_url}" readonly />
216
  </td>
217
  </tr>`;
218
+ jQuery('#hwl_uploaded_fonts').append(uploadedFont);
219
+ }
 
220
  }
221
+
222
+ /**
223
+ * Call the generate-stylesheet script and reset the upload dir to the default setting.
224
+ */
225
  function hwlGenerateStylesheet() {
226
  var hwlData = hwlSerializeArray($('#hwl-options-form'));
227
 
233
  uploaded_fonts: hwlData
234
  },
235
  success: function(response) {
 
236
  jQuery('#hwl-admin-notices').append(
237
  `<div class="updated settings-error notice is-dismissible">
238
  <p>${response}</p>
253
  }
254
  });
255
  }
256
+
257
+ /**
258
+ * Serialize form data to a multi-dimensional array.
259
+ */
260
  function hwlSerializeArray(data) {
261
  var result = [];
262
  data.each(function() {
273
  <?php
274
  }
275
 
276
+ /**
277
+ * Before each upload we temporarily set our custom upload-directory.
278
+ */
279
+ function hwlAjaxSetUploadDir() {
280
+ try {
281
+ update_option('upload_path',WP_CONTENT_DIR . '/local-fonts');
282
+ update_option('upload_url_path',content_url() . '/local-fonts');
283
+ update_option('uploads_use_yearmonth_folders', false);
284
+ wp_die();
285
+ } catch (\Exception $e) {
286
+ wp_die($e);
287
+ }
288
+ }
289
+ add_action('wp_ajax_hwlAjaxSetUploadDir', 'hwlAjaxSetUploadDir');
290
+
291
+
292
+ /**
293
+ * After we're done uploading we need to reset the upload-directory.
294
+ */
295
+ function hwlAjaxResetUploadDir() {
296
+ try {
297
+ update_option('upload_path',null);
298
+ update_option('upload_url_path',null);
299
+ update_option('uploads_use_yearmonth_folders', true);
300
+ wp_die();
301
+ } catch (\Exception $e) {
302
+ wp_die($e);
303
+ }
304
+ }
305
+ add_action('wp_ajax_hwlAjaxResetUploadDir', 'hwlAjaxResetUploadDir');
306
+
307
+ /**
308
+ * The function for generating the stylesheet and resetting the upload dir to the default.
309
+ */
310
  function hwlAjaxGenerateStyles() {
311
  require_once('includes/generate-stylesheet.php');
312
  }
323
  wp_enqueue_style('hwl-style');
324
  }
325
  }
326
+ add_action('wp_enqueue_scripts', 'hwlEnqueueStylesheet' );
 
includes/generate-stylesheet.php CHANGED
@@ -54,15 +54,8 @@ function hwlReturnFontUrl($font, $requestedType) {
54
  return implode($url);
55
  }
56
  }
57
- }
58
 
59
- /**
60
- * After we're done uploading we need to reset the upload-directory.
61
- */
62
- function hwlResetUploadDir() {
63
- update_option('upload_path',null);
64
- update_option('upload_url_path',null);
65
- update_option('uploads_use_yearmonth_folders', true);
66
  }
67
 
68
  /**
@@ -101,7 +94,6 @@ try {
101
  $stylesheet = fopen($file, 'w') or die ("Cannot create file {$file}");
102
  fwrite ($stylesheet, $fonts);
103
  fclose ($stylesheet);
104
- hwlResetUploadDir();
105
  wp_die(_e('Stylesheet was successfully generated and added to your theme\'s header.'));
106
  } catch (Exception $e) {
107
  wp_die($e);
54
  return implode($url);
55
  }
56
  }
 
57
 
58
+ return null;
 
 
 
 
 
 
59
  }
60
 
61
  /**
94
  $stylesheet = fopen($file, 'w') or die ("Cannot create file {$file}");
95
  fwrite ($stylesheet, $fonts);
96
  fclose ($stylesheet);
 
97
  wp_die(_e('Stylesheet was successfully generated and added to your theme\'s header.'));
98
  } catch (Exception $e) {
99
  wp_die($e);
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://dev.daanvandenbergh.com/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: 4.9
7
- Stable tag: 1.56
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -18,7 +18,7 @@ This will *decrease your pageload times*, *leverage browser cache*, *minimize DN
18
 
19
  == Installation ==
20
 
21
- 1. Upload the plugin files to the `/wp-content/plugins/host-webforms-local` directory, or install the plugin through the WordPress plugins screen directly.
22
  1. Activate the plugin through the 'Plugins' screen in WordPress
23
  1. Use the Settings -> Optimize Webfonts screen to configure the plugin
24
 
@@ -34,5 +34,11 @@ N/A
34
 
35
  == Changelog ==
36
 
 
 
 
 
 
 
37
  = 1.0 =
38
- First release! No changes so far!
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: 4.9
7
+ Stable tag: 1.1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
18
 
19
  == Installation ==
20
 
21
+ 1. Upload the plugin files to the `/wp-content/plugins/host-webfonts-local` directory, or install the plugin through the WordPress plugins screen directly.
22
  1. Activate the plugin through the 'Plugins' screen in WordPress
23
  1. Use the Settings -> Optimize Webfonts screen to configure the plugin
24
 
34
 
35
  == Changelog ==
36
 
37
+ = 1.1.0 =
38
+ Fixed bug where the plugin would sometimes permanently change your upload-director to /local-fonts.
39
+
40
+ = 1.0.1 =
41
+ Changed to Github.
42
+
43
  = 1.0 =
44
+ First release! No changes so far!