Local Google Fonts - Version 0.12

Version Description

Download this release

Release Info

Developer everpress
Plugin Icon 128x128 Local Google Fonts
Version 0.12
Comparing to
See all releases

Code changes from version 0.11 to 0.12

README.md CHANGED
@@ -4,7 +4,7 @@ Contributors: everpress, xaverb
4
  Tags: googlefonts, google, fonts, gdpr, lgf, font, speed
5
  Requires at least: 4.6
6
  Tested up to: 6.0
7
- Stable tag: 0.11
8
  Requires PHP: 5.6+
9
  License: GPLv2 or later
10
  Author: EverPress
@@ -24,6 +24,10 @@ more on [wptavern.com](https://wptavern.com/german-court-fines-website-owner-for
24
 
25
  ![Option Interface.](.wordpress-org/screenshot-1.png)
26
 
 
 
 
 
27
  ### Features
28
 
29
  ### 1. Quick install (activate, setup and forget)
@@ -50,6 +54,17 @@ Yes, if you check the option to load fonts automatically. Otherwise each font se
50
 
51
  Yes. The open source fonts from Google Fonts are published under a licenses that allow you to use them on any website, no matter if it’s commercial or personal.
52
 
 
 
 
 
 
 
 
 
 
 
 
53
  ### My fonts do not show up on the settings page, what can I do?
54
 
55
  Fonts are discovered once they are used. Try to browse your front end first and get back to the settings page.
@@ -62,8 +77,25 @@ The plugin currently only checks fonts embedded via [`wp_enqueue_style`](https:/
62
 
63
  The Divi theme has a custom implementation of Google Fonts. To use LGF with Divi disable _Improve Google Fonts Loading_ on the Performance Settings page of Divi.
64
 
 
 
 
 
65
  ## Changelog
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  ### 0.11
68
 
69
  - fixed: problem on customizer in Neve theme
4
  Tags: googlefonts, google, fonts, gdpr, lgf, font, speed
5
  Requires at least: 4.6
6
  Tested up to: 6.0
7
+ Stable tag: 0.12
8
  Requires PHP: 5.6+
9
  License: GPLv2 or later
10
  Author: EverPress
24
 
25
  ![Option Interface.](.wordpress-org/screenshot-1.png)
26
 
27
+ ### 2. Access dev tools in your browser
28
+
29
+ ![Dev tools](.wordpress-org/screenshot-2.png)
30
+
31
  ### Features
32
 
33
  ### 1. Quick install (activate, setup and forget)
54
 
55
  Yes. The open source fonts from Google Fonts are published under a licenses that allow you to use them on any website, no matter if it’s commercial or personal.
56
 
57
+ ### How to check if my site is loading Google Fonts?
58
+
59
+ It's easy to check if your site is loading fonts from a third party source (check [2nd screenshot](https://wordpress.org/plugins/local-google-fonts/#screenshots) above):
60
+
61
+ 1. Open the dev tools (Cmd + Opt + I on Mac or F12, or Ctrl + Shift + I on Windows)
62
+ 2. Go to the **Network** tab and select the **Fonts** type
63
+ 3. Reload your page to see all fonts loaded on your site.
64
+ 4. Check the **Domain** column if it contains domains from a third party (Google is fonts.gstatic.com)
65
+
66
+ If you host your fonts locally with [Local Google Fonts](https://wordpress.org/plugins/local-google-fonts/) there should be no fonts loaded from the Google servers.
67
+
68
  ### My fonts do not show up on the settings page, what can I do?
69
 
70
  Fonts are discovered once they are used. Try to browse your front end first and get back to the settings page.
77
 
78
  The Divi theme has a custom implementation of Google Fonts. To use LGF with Divi disable _Improve Google Fonts Loading_ on the Performance Settings page of Divi.
79
 
80
+ ### Why are some characters displayed in the fallback font?
81
+
82
+ You may have loaded a subset which doesn't included required characters. Check additional subsets on the settings page and reload your font.
83
+
84
  ## Changelog
85
 
86
+ ### 0.13
87
+
88
+ - improved: better explanations on errors.
89
+ - improved: Higher propriety for wp_resource_hints to catch them all. Fixes #8
90
+ - implemented an alias method for no longer supported fonts.
91
+ - fixed: Syntax error on older PHP versions
92
+
93
+ ### 0.12
94
+
95
+ - Do not handle fonts sources with more than 30 families (why would you need that?)
96
+ - Add option to choose subsets for each font family
97
+ - Disable functionality in the customizer
98
+
99
  ### 0.11
100
 
101
  - fixed: problem on customizer in Neve theme
includes/class-local-google-fonts-admin.php CHANGED
@@ -66,6 +66,17 @@ class LGF_Admin {
66
  $class = LGF::get_instance();
67
 
68
  $buffer = get_option( 'local_google_fonts_buffer', array() );
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  if ( isset( $_POST['hostlocal'] ) ) {
71
  $handle = $_POST['hostlocal'];
@@ -145,89 +156,108 @@ class LGF_Admin {
145
 
146
  <h3><?php esc_html_e( 'Handle', 'local-google-fonts' ); ?>: <code><?php esc_html_e( $data['handle'] ); ?></code></h3>
147
  <p><?php esc_html_e( 'Original URL', 'local-google-fonts' ); ?>: <code><?php echo rawurldecode( $data['src'] ); ?></code> <a href="<?php echo esc_url( $data['src'] ); ?>" class="dashicons dashicons-external" target="_blank" title="<?php esc_attr_e( 'show original URL', 'local-google-fonts' ); ?>"></a></p>
148
-
149
- <table class="wp-list-table widefat fixed striped table-view-list ">
150
- <thead>
151
- <tr>
152
- <th scope="col" id="name" class="manage-column column-name column-primary" style="width: 150px"><?php esc_html_e( 'Name', 'local-google-fonts' ); ?></th>
153
- <th scope="col" id="description" class="manage-column column-description"><?php esc_html_e( 'Variants', 'local-google-fonts' ); ?></th>
154
- <th scope="col" id="auto-updates" class="manage-column column-auto-updates" style="width: 250px"><?php esc_html_e( 'Status', 'local-google-fonts' ); ?></th>
155
- </tr>
156
- </thead>
157
- <tbody>
158
- <?php $fontinfo = $this->get_font_info( $data['src'] ); ?>
159
-
160
- <?php foreach ( $fontinfo as $i => $font ) : ?>
161
-
162
- <?php $filename = $font->id . '-' . $font->version . '-' . $font->defSubset; ?>
163
- <tr>
164
- <td><strong><?php echo esc_html( $font->family ); ?></strong><br>
165
- </td>
166
- <td>
167
- <p class="code">
168
- <?php foreach ( $font->variants as $variant ) : ?>
169
- <span class="variant"><?php printf( '%s %s', $variant->fontStyle, $variant->fontWeight ); ?></span>
170
- <?php endforeach ?>
171
- </p>
172
- <details>
173
- <summary><strong><?php printf( esc_html__( '%1$d of %2$d files loaded.', 'local-google-fonts' ), $font->loaded, $font->total ); ?></strong></summary>
174
- <div style="max-height: 280px; overflow: scroll;font-size: small;white-space: nowrap; overflow: hidden; overflow-y: auto;" class="code">
175
  <?php foreach ( $font->variants as $variant ) : ?>
176
- <div>
177
- <h4><?php printf( '%s %s', $variant->fontStyle, $variant->fontWeight ); ?></h4>
178
- <?php foreach ( array( 'woff', 'svg', 'woff2', 'ttf', 'eot' ) as $ext ) : ?>
179
- <ul>
180
- <li>
181
- <?php $file = $data['id'] . '/' . $filename . '-' . $variant->id . '.' . $ext; ?>
182
- <?php if ( file_exists( $folder . '/' . $file ) ) : ?>
183
- <code><?php esc_html_e( 'Local', 'local-google-fonts' ); ?>: <a href="<?php echo esc_url( $folder_url . '/' . $file ); ?>" download><?php echo esc_html( basename( $file ) ); ?></a></code>
184
- <strong title="<?php esc_attr_e( 'loaded, served from your server', 'local-google-fonts' ); ?>">✔</strong>
185
- <?php else : ?>
186
- <code><?php esc_html_e( 'Local', 'local-google-fonts' ); ?>: <?php echo esc_html( basename( $file ) ); ?></code>
187
- <strong class="wp-ui-text-notification" title="<?php esc_attr_e( 'not loaded, served from Google servers', 'local-google-fonts' ); ?>">✕</strong>
188
- <?php endif; ?>
189
- </li>
190
- <li><code><?php esc_html_e( 'Remote', 'local-google-fonts' ); ?>: <?php echo esc_url( $variant->{$ext} ); ?></code></li>
191
- </ul>
192
- <?php endforeach; ?>
193
- </div>
194
  <?php endforeach ?>
195
- </div>
196
- </details>
197
- </td>
198
- <td>
199
- <?php if ( is_dir( $folder . '/' . $data['id'] ) ) : ?>
200
- <?php printf( '%s %s', '<strong>✔</strong>', esc_html__( 'loaded, served from your server', 'local-google-fonts' ) ); ?>
201
- <?php else : ?>
202
- <?php printf( '%s %s', '<strong class="wp-ui-text-notification">✕</strong>', esc_html__( 'not loaded, served from Google servers', 'local-google-fonts' ) ); ?>
203
- <?php endif; ?>
204
-
205
- </td>
206
-
207
- </tr>
208
- <?php endforeach ?>
209
- </tbody>
210
- </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  <p>
212
- <?php if ( is_dir( $folder . '/' . $data['id'] ) ) : ?>
213
  <button class="host-locally button button-primary" name="hostlocal" value="<?php echo esc_attr( $data['handle'] ); ?>"><?php esc_html_e( 'Reload Fonts', 'local-google-fonts' ); ?></button>
214
  <button class="host-locally button button-link-delete" name="removelocal" value="<?php echo esc_attr( $data['handle'] ); ?>"><?php esc_html_e( 'Remove hosted files', 'local-google-fonts' ); ?></button>
215
  <?php else : ?>
216
  <button class="host-locally button button-primary" name="hostlocal" value="<?php echo esc_attr( $data['handle'] ); ?>"><?php esc_html_e( 'Host locally', 'local-google-fonts' ); ?></button>
217
  <?php endif; ?>
218
  </p>
 
 
 
 
 
 
219
  <?php endforeach ?>
220
  <hr>
221
  <p class="textright">
222
  <button class="host-locally button button-link-delete" name="flush" value="1"><?php esc_html_e( 'Remove all stored data', 'local-google-fonts' ); ?></button>
223
- </p>
 
 
224
  </form>
225
  </div>
 
226
  <?php
227
  }
228
 
229
 
230
- public function get_font_info( $src ) {
231
 
232
  $folder = WP_CONTENT_DIR . '/uploads/fonts';
233
  $folder_url = WP_CONTENT_URL . '/uploads/fonts';
@@ -277,13 +307,21 @@ class LGF_Admin {
277
  }
278
  }
279
 
 
 
 
 
 
 
 
280
  foreach ( $families as $family => $variants ) {
281
  $url = 'https://google-webfonts-helper.herokuapp.com/api/fonts/';
 
282
  $the_url = add_query_arg(
283
  array(
284
  // doesn't seem to have an effect so we filter it later
285
  // 'variants' => implode( ',', $variants ),
286
- 'subsets' => $args['subset'],
287
  ),
288
  $url . $family
289
  );
66
  $class = LGF::get_instance();
67
 
68
  $buffer = get_option( 'local_google_fonts_buffer', array() );
69
+ if ( isset( $_POST['subsets'] ) ) {
70
+ foreach ( $_POST['subsets'] as $handle => $subsets ) {
71
+ if ( isset( $buffer[ $handle ] ) ) {
72
+ if ( ! isset( $buffer[ $handle ]['subsets'] ) ) {
73
+ $buffer[ $handle ]['subsets'] = array();
74
+ }
75
+ $buffer[ $handle ]['subsets'] = $subsets;
76
+ }
77
+ }
78
+ }
79
+ update_option( 'local_google_fonts_buffer', $buffer );
80
 
81
  if ( isset( $_POST['hostlocal'] ) ) {
82
  $handle = $_POST['hostlocal'];
156
 
157
  <h3><?php esc_html_e( 'Handle', 'local-google-fonts' ); ?>: <code><?php esc_html_e( $data['handle'] ); ?></code></h3>
158
  <p><?php esc_html_e( 'Original URL', 'local-google-fonts' ); ?>: <code><?php echo rawurldecode( $data['src'] ); ?></code> <a href="<?php echo esc_url( $data['src'] ); ?>" class="dashicons dashicons-external" target="_blank" title="<?php esc_attr_e( 'show original URL', 'local-google-fonts' ); ?>"></a></p>
159
+
160
+ <?php $fontinfo = $this->get_font_info( $data['src'], $data['handle'] ); ?>
161
+
162
+ <?php if ( $fontinfo ) : ?>
163
+
164
+ <table class="wp-list-table widefat fixed striped table-view-list ">
165
+ <thead>
166
+ <tr>
167
+ <th scope="col" id="name" class="manage-column column-name column-primary" style="width: 150px"><?php esc_html_e( 'Name', 'local-google-fonts' ); ?></th>
168
+ <th scope="col" id="description" class="manage-column column-description"><?php esc_html_e( 'Variants', 'local-google-fonts' ); ?></th>
169
+ <th scope="col" id="auto-updates" class="manage-column column-auto-updates" style="width: 250px"><?php esc_html_e( 'Status', 'local-google-fonts' ); ?></th>
170
+ </tr>
171
+ </thead>
172
+ <tbody>
173
+ <?php foreach ( $fontinfo as $i => $font ) : ?>
174
+
175
+ <?php $filename = $font->id . '-' . $font->version . '-' . $font->defSubset; ?>
176
+ <tr>
177
+ <td><strong><?php echo esc_html( $font->family ); ?></strong><br>
178
+ </td>
179
+ <td>
180
+ <p class="code">
 
 
 
 
 
181
  <?php foreach ( $font->variants as $variant ) : ?>
182
+ <span class="variant"><?php printf( '%s %s', $variant->fontStyle, $variant->fontWeight ); ?></span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  <?php endforeach ?>
184
+ </p>
185
+ <?php
186
+ $active_subsets = isset( $data['subsets'] ) ? $data['subsets'][ $font->id ] : array_keys( array_filter( (array) $font->subsetMap ) );
187
+ ?>
188
+ <p><strong><?php esc_html_e( 'Subsets', 'local-google-fonts' ); ?></strong><br>
189
+ <?php foreach ( $font->subsetMap as $subset => $is_active ) : ?>
190
+ <label title="<?php printf( esc_attr__( 'Load %s subset with this font', 'local-google-fonts' ), $subset ); ?>" class="subset"><input type="checkbox" name="subsets[<?php echo esc_attr( $data['handle'] ); ?>][<?php echo esc_attr( $font->id ); ?>][]" value="<?php echo esc_attr( $subset ); ?>" <?php checked( in_array( $subset, $active_subsets ) ); ?>> <?php echo esc_html( $subset ); ?> </label>
191
+ <?php endforeach ?>
192
+ </p>
193
+ <details>
194
+ <summary><strong><?php printf( esc_html__( '%1$d of %2$d files loaded.', 'local-google-fonts' ), $font->loaded, $font->total ); ?></strong></summary>
195
+ <div style="max-height: 280px; overflow: scroll;font-size: small;white-space: nowrap; overflow: hidden; overflow-y: auto;" class="code">
196
+ <?php foreach ( $font->variants as $variant ) : ?>
197
+ <div>
198
+ <h4><?php printf( '%s %s', $variant->fontStyle, $variant->fontWeight ); ?></h4>
199
+ <?php foreach ( array( 'woff', 'svg', 'woff2', 'ttf', 'eot' ) as $ext ) : ?>
200
+ <ul>
201
+ <li>
202
+ <?php $file = $data['id'] . '/' . $filename . '-' . $variant->id . '.' . $ext; ?>
203
+ <?php if ( file_exists( $folder . '/' . $file ) ) : ?>
204
+ <code><?php esc_html_e( 'Local', 'local-google-fonts' ); ?>: <a href="<?php echo esc_url( $folder_url . '/' . $file ); ?>" download><?php echo esc_html( basename( $file ) ); ?></a></code>
205
+ <strong title="<?php esc_attr_e( 'loaded, served from your server', 'local-google-fonts' ); ?>">✔</strong>
206
+ <?php else : ?>
207
+ <code><?php esc_html_e( 'Local', 'local-google-fonts' ); ?>: <?php echo esc_html( basename( $file ) ); ?></code>
208
+ <strong class="wp-ui-text-notification" title="<?php esc_attr_e( 'not loaded, served from Google servers', 'local-google-fonts' ); ?>">✕</strong>
209
+ <?php endif; ?>
210
+ </li>
211
+ <li><code><?php esc_html_e( 'Remote', 'local-google-fonts' ); ?>: <?php echo esc_url( $variant->{$ext} ); ?></code></li>
212
+ </ul>
213
+ <?php endforeach; ?>
214
+ </div>
215
+ <?php endforeach ?>
216
+ </div>
217
+ </details>
218
+ </td>
219
+ <td>
220
+ <?php if ( is_dir( $folder . '/' . $data['id'] ) ) : ?>
221
+ <?php printf( '%s %s', '<strong>✔</strong>', esc_html__( 'loaded, served from your server', 'local-google-fonts' ) ); ?>
222
+ <?php else : ?>
223
+ <?php printf( '%s %s', '<strong class="wp-ui-text-notification">✕</strong>', esc_html__( 'not loaded, served from Google servers', 'local-google-fonts' ) ); ?>
224
+ <?php endif; ?>
225
+
226
+ </td>
227
+
228
+ </tr>
229
+ <?php endforeach ?>
230
+ </tbody>
231
+ </table>
232
  <p>
233
+ <?php if ( is_dir( $folder . '/' . $data['id'] ) ) : ?>
234
  <button class="host-locally button button-primary" name="hostlocal" value="<?php echo esc_attr( $data['handle'] ); ?>"><?php esc_html_e( 'Reload Fonts', 'local-google-fonts' ); ?></button>
235
  <button class="host-locally button button-link-delete" name="removelocal" value="<?php echo esc_attr( $data['handle'] ); ?>"><?php esc_html_e( 'Remove hosted files', 'local-google-fonts' ); ?></button>
236
  <?php else : ?>
237
  <button class="host-locally button button-primary" name="hostlocal" value="<?php echo esc_attr( $data['handle'] ); ?>"><?php esc_html_e( 'Host locally', 'local-google-fonts' ); ?></button>
238
  <?php endif; ?>
239
  </p>
240
+ <?php else : ?>
241
+ <div class="notice inline error">
242
+ <p><strong><?php esc_html_e( 'This source contains more than 30 fonts and is most likely used as helper for your theme. Skipped.', 'local-google-fonts' ); ?></strong></p>
243
+ </div>
244
+ <?php endif; ?>
245
+
246
  <?php endforeach ?>
247
  <hr>
248
  <p class="textright">
249
  <button class="host-locally button button-link-delete" name="flush" value="1"><?php esc_html_e( 'Remove all stored data', 'local-google-fonts' ); ?></button>
250
+ </p>
251
+ <?php submit_button(); ?>
252
+
253
  </form>
254
  </div>
255
+
256
  <?php
257
  }
258
 
259
 
260
+ public function get_font_info( $src, $handle = null ) {
261
 
262
  $folder = WP_CONTENT_DIR . '/uploads/fonts';
263
  $folder_url = WP_CONTENT_URL . '/uploads/fonts';
307
  }
308
  }
309
 
310
+ // do not load them as its most likely some helper font thing
311
+ if ( count( $families ) > 30 ) {
312
+ return false;
313
+ }
314
+
315
+ $buffer = get_option( 'local_google_fonts_buffer', array() );
316
+
317
  foreach ( $families as $family => $variants ) {
318
  $url = 'https://google-webfonts-helper.herokuapp.com/api/fonts/';
319
+ $subsets = isset( $buffer[ $handle ]['subsets'][ $family ] ) ? implode( ',', array_filter( $buffer[ $handle ]['subsets'][ $family ] ) ) : $args['subset'];
320
  $the_url = add_query_arg(
321
  array(
322
  // doesn't seem to have an effect so we filter it later
323
  // 'variants' => implode( ',', $variants ),
324
+ 'subsets' => $subsets,
325
  ),
326
  $url . $family
327
  );
includes/class-local-google-fonts.php CHANGED
@@ -87,7 +87,11 @@ class LGF {
87
  $new_dir = $folder . '/' . $id . '/font.css';
88
 
89
  $class = LGF_Admin::get_instance();
90
- $fontinfo = $class->get_font_info( $src );
 
 
 
 
91
 
92
  foreach ( $fontinfo as $font ) {
93
  $filename = $font->id . '-' . $font->version . '-' . $font->defSubset;
@@ -139,7 +143,6 @@ class LGF {
139
  }
140
  }
141
 
142
-
143
  $WP_Filesystem->put_contents( $new_dir, $style );
144
 
145
  return $new_src;
@@ -176,14 +179,13 @@ class LGF {
176
 
177
  $stylesheet = $folder . '/' . $id . '/font.css';
178
  $stylesheet_url = $folder_url . '/' . $id . '/font.css';
179
- $buffer = get_option( 'local_google_fonts_buffer', array() );
180
 
181
  if ( file_exists( $stylesheet ) ) {
182
  $src = add_query_arg( 'v', filemtime( $stylesheet ), $stylesheet_url );
183
  } else {
184
 
185
- // special case for neve theme (https://wordpress.org/support/topic/problems-with-neve-theme-costomizer/)
186
- if ( false !== strpos( $handle, 'neve-fonts-control-google-fonts-' ) ) {
187
  return $src;
188
  }
189
 
@@ -191,6 +193,7 @@ class LGF {
191
  $handle = $id;
192
  }
193
 
 
194
  $buffer[ $handle ] = array(
195
  'id' => $id,
196
  'handle' => $handle,
87
  $new_dir = $folder . '/' . $id . '/font.css';
88
 
89
  $class = LGF_Admin::get_instance();
90
+ $fontinfo = $class->get_font_info( $src, $handle );
91
+
92
+ if ( ! $fontinfo ) {
93
+ return $src;
94
+ }
95
 
96
  foreach ( $fontinfo as $font ) {
97
  $filename = $font->id . '-' . $font->version . '-' . $font->defSubset;
143
  }
144
  }
145
 
 
146
  $WP_Filesystem->put_contents( $new_dir, $style );
147
 
148
  return $new_src;
179
 
180
  $stylesheet = $folder . '/' . $id . '/font.css';
181
  $stylesheet_url = $folder_url . '/' . $id . '/font.css';
 
182
 
183
  if ( file_exists( $stylesheet ) ) {
184
  $src = add_query_arg( 'v', filemtime( $stylesheet ), $stylesheet_url );
185
  } else {
186
 
187
+ // do not load on customizer preview.
188
+ if ( is_customize_preview() ) {
189
  return $src;
190
  }
191
 
193
  $handle = $id;
194
  }
195
 
196
+ $buffer = get_option( 'local_google_fonts_buffer', array() );
197
  $buffer[ $handle ] = array(
198
  'id' => $id,
199
  'handle' => $handle,
local-google-fonts.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Local Google Fonts
4
  Description: Host your used Google fonts on your server and make your site GDPR compliant.
5
- Version: 0.11
6
  Author: EverPress
7
  Author URI: https://everpress.co
8
  License: GPLv2 or later
2
  /*
3
  Plugin Name: Local Google Fonts
4
  Description: Host your used Google fonts on your server and make your site GDPR compliant.
5
+ Version: 0.12
6
  Author: EverPress
7
  Author URI: https://everpress.co
8
  License: GPLv2 or later