Local Google Fonts - Version 0.9

Version Description

Download this release

Release Info

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

Code changes from version 0.8 to 0.9

README.md CHANGED
@@ -1,10 +1,10 @@
1
  # Local Google Fonts
2
 
3
- Contributors: everpress
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.8
8
  Requires PHP: 5.6+
9
  License: GPLv2 or later
10
  Author: EverPress
@@ -44,7 +44,7 @@ more on [wptavern.com](https://wptavern.com/german-court-fines-website-owner-for
44
 
45
  ### Will this load Google Fonts automatically?
46
 
47
- No, each font set must be manually triggered. Automatic loading of assets from a third party server is forbidden by the [plugin guidelines](https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/).
48
 
49
  ### Is it Legal to Self-Host Google Fonts?
50
 
@@ -60,6 +60,10 @@ The plugin currently only checks fonts embedded via [`wp_enqueue_style`](https:/
60
 
61
  ## Changelog
62
 
 
 
 
 
63
  ### 0.8
64
 
65
  - updated required WP version to 4.6
1
  # Local Google Fonts
2
 
3
+ 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.9
8
  Requires PHP: 5.6+
9
  License: GPLv2 or later
10
  Author: EverPress
44
 
45
  ### Will this load Google Fonts automatically?
46
 
47
+ Yes, if you check the option to load fonts automatically. Otherwise each font set must be manually triggered.
48
 
49
  ### Is it Legal to Self-Host Google Fonts?
50
 
60
 
61
  ## Changelog
62
 
63
+ ### 0.9
64
+
65
+ - new: options to load fonts automatically
66
+
67
  ### 0.8
68
 
69
  - updated required WP version to 4.6
includes/class-local-google-fonts-admin.php CHANGED
@@ -23,7 +23,12 @@ class LGF_Admin {
23
  }
24
 
25
  public function register_settings() {
26
- register_setting( 'local_google_fonts', 'local_google_fonts', array( $this, 'local_google_fonts_validate' ) );
 
 
 
 
 
27
  }
28
 
29
  public function settings_page() {
@@ -42,7 +47,7 @@ class LGF_Admin {
42
 
43
  }
44
 
45
- public function local_google_fonts_validate() {
46
 
47
  $class = LGF::get_instance();
48
 
@@ -68,8 +73,132 @@ class LGF_Admin {
68
  $class->clear();
69
  }
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
72
 
 
73
  public function get_font_info( $src ) {
74
 
75
  // a bit sanitation as URLs are often registered with esc_url
@@ -194,99 +323,4 @@ class LGF_Admin {
194
 
195
  }
196
 
197
- public function render_settings() {
198
-
199
- $buffer = get_option( 'local_google_fonts_buffer', array() );
200
-
201
- $folder = WP_CONTENT_DIR . '/uploads/fonts';
202
- $folder_url = WP_CONTENT_URL . '/uploads/fonts';
203
- $count = count( $buffer );
204
-
205
- ?>
206
- <div class="wrap">
207
- <h1><?php printf( esc_html__( _n( '%d Google font source found on your site.', '%d Google font sources found on your site.', $count, 'local-google-font' ) ), $count ); ?></h1>
208
-
209
- <p><?php esc_html_e( 'This page shows all discovered Google Fonts over time. If you miss a font start browsing your front end so they end up showing here.', 'local-google-fonts' ); ?></p>
210
-
211
- <?php if ( ! $count ) : ?>
212
- <p><?php esc_html_e( 'You have currently no Google fonts in use on your site.', 'local-google-fonts' ); ?></p>
213
- <?php endif; ?>
214
-
215
- <form action="options.php" method="post">
216
- <?php
217
- settings_fields( 'local_google_fonts' );
218
- do_settings_sections( 'local_google_fonts_section' );
219
- ?>
220
-
221
- <?php foreach ( $buffer as $id => $data ) : ?>
222
-
223
- <h2><?php esc_html_e( 'Handle', 'local-google-fonts' ); ?>: <code><?php esc_html_e( $data['handle'] ); ?></code></h2>
224
- <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>
225
-
226
- <table class="wp-list-table widefat fixed striped table-view-list ">
227
- <thead>
228
- <tr>
229
- <th scope="col" id="name" class="manage-column column-name column-primary" style="width: 150px"><?php esc_html_e( 'Name', 'local-google-fonts' ); ?></th>
230
- <th scope="col" id="description" class="manage-column column-description"><?php esc_html_e( 'Variants', 'local-google-fonts' ); ?></th>
231
- <th scope="col" id="auto-updates" class="manage-column column-auto-updates" style="width: 250px"><?php esc_html_e( 'Status', 'local-google-fonts' ); ?></th>
232
- </tr>
233
- </thead>
234
- <tbody>
235
- <?php $fontinfo = $this->get_font_info( $data['src'] ); ?>
236
-
237
- <?php foreach ( $fontinfo as $i => $set ) : ?>
238
- <tr>
239
- <td><strong><?php echo esc_html( $set->family ); ?></strong><br>
240
- </td>
241
- <td>
242
- <p class="code">
243
- <?php foreach ( $set->variants as $variant ) : ?>
244
- <span class="variant"><?php printf( '%s %s', $variant->fontStyle, $variant->fontWeight ); ?></span>
245
- <?php endforeach ?>
246
- </p>
247
- <details>
248
- <summary><strong><?php printf( '%d files from Google Servers', count( $set->variants ) * 5 ); ?></strong></summary>
249
- <div style="max-height: 200px; overflow: scroll;font-size: small;white-space: nowrap; overflow: hidden; overflow-y: auto;" class="code">
250
- <?php foreach ( $set->variants as $variant ) : ?>
251
- <p>
252
- <strong><?php printf( '%s %s', $variant->fontStyle, $variant->fontWeight ); ?></strong><br>
253
- <code><?php echo esc_url( $variant->woff2 ); ?></code><br>
254
- <code><?php echo esc_url( $variant->ttf ); ?></code><br>
255
- <code><?php echo esc_url( $variant->svg ); ?></code><br>
256
- <code><?php echo esc_url( $variant->eot ); ?></code><br>
257
- <code><?php echo esc_url( $variant->woff ); ?></code>
258
- </p>
259
- <?php endforeach ?>
260
- </div>
261
- </details>
262
- </td>
263
- <td>
264
- <?php if ( is_dir( $folder . '/' . $data['id'] ) ) : ?>
265
- <?php printf( '%s %s', '<strong>✔</strong>', esc_html__( 'loaded, served from your server', 'local-google-fonts' ) ); ?>
266
- <?php else : ?>
267
- <?php printf( '%s %s', '<strong class="wp-ui-text-notification">✕</strong>', esc_html__( 'not loaded, served from Google servers', 'local-google-fonts' ) ); ?>
268
- <?php endif; ?>
269
-
270
- </td>
271
-
272
- </tr>
273
- <?php endforeach ?>
274
- </tbody>
275
- </table>
276
- <p>
277
- <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>
278
- <?php if ( is_dir( $folder . '/' . $data['id'] ) ) : ?>
279
- <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>
280
- <?php endif; ?>
281
- </p>
282
- <?php endforeach ?>
283
- <p class="textright">
284
- <button class="host-locally button button-link-delete" name="flush" value="1"><?php esc_html_e( 'Remove all stored data', 'local-google-fonts' ); ?></button>
285
- </p>
286
- </form>
287
- </div>
288
- <?php
289
-
290
- }
291
-
292
  }
23
  }
24
 
25
  public function register_settings() {
26
+
27
+ register_setting( 'local_google_fonts_settings_page', 'local_google_fonts', array( $this, 'local_google_fonts_validate' ) );
28
+
29
+ add_settings_section( 'default', '', '', 'local_google_fonts_settings_page' );
30
+
31
+ add_settings_field( 'auto_load', __( 'Autoload', 'local-google-fonts' ), array( $this, 'auto_load_cb' ), 'local_google_fonts_settings_page', 'default' );
32
  }
33
 
34
  public function settings_page() {
47
 
48
  }
49
 
50
+ public function local_google_fonts_validate( $options ) {
51
 
52
  $class = LGF::get_instance();
53
 
73
  $class->clear();
74
  }
75
 
76
+ return $options;
77
+
78
+ }
79
+
80
+ public function auto_load_cb( $args ) {
81
+
82
+ $options = get_option( 'local_google_fonts' );
83
+ $checked = isset( $options['auto_load'] );
84
+ ?>
85
+ <p>
86
+ <label><input type="checkbox" value="1" name="local_google_fonts[auto_load]" <?php checked( $checked ); ?>>
87
+ <?php esc_html_e( 'Load Fonts automatically', 'local-google-fonts' ); ?>
88
+ </label>
89
+ </p>
90
+ <p class="description">
91
+ <?php esc_html_e( 'If you check this option discovered fonts will get loaded automatically.', 'local-google-fonts' ); ?>
92
+ </p>
93
+ <?php
94
+ }
95
+
96
+
97
+ public function render_settings() {
98
+ // check user capabilities
99
+ if ( ! current_user_can( 'manage_options' ) ) {
100
+ return;
101
+ }
102
+
103
+ $buffer = get_option( 'local_google_fonts_buffer', array() );
104
+
105
+ $folder = WP_CONTENT_DIR . '/uploads/fonts';
106
+ $folder_url = WP_CONTENT_URL . '/uploads/fonts';
107
+ $count = count( $buffer );
108
+
109
+ if ( ! $count ) :
110
+ add_settings_error( 'local_google_fonts_messages', 'local_google_fonts_message', __( 'You have currently no Google fonts in use on your site.', 'local-google-fonts' ) );
111
+ endif;
112
+ settings_errors( 'local_google_fonts_messages' );
113
+ ?>
114
+ <div class="wrap">
115
+ <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
116
+
117
+ <form action="options.php" method="post">
118
+ <?php
119
+ settings_fields( 'local_google_fonts_settings_page' );
120
+ do_settings_sections( 'local_google_fonts_settings_page' );
121
+
122
+ ?>
123
+ <?php submit_button(); ?>
124
+
125
+ <hr>
126
+ <h2><?php printf( esc_html__( _n( '%d Google font source found on your site.', '%d Google font sources found on your site.', $count, 'local-google-font' ) ), $count ); ?></h2>
127
+
128
+ <p><?php esc_html_e( 'This page shows all discovered Google Fonts over time. If you miss a font start browsing your front end so they end up showing here.', 'local-google-fonts' ); ?></p>
129
+
130
+ <?php foreach ( $buffer as $id => $data ) : ?>
131
+
132
+ <h3><?php esc_html_e( 'Handle', 'local-google-fonts' ); ?>: <code><?php esc_html_e( $data['handle'] ); ?></code></h3>
133
+ <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>
134
+
135
+ <table class="wp-list-table widefat fixed striped table-view-list ">
136
+ <thead>
137
+ <tr>
138
+ <th scope="col" id="name" class="manage-column column-name column-primary" style="width: 150px"><?php esc_html_e( 'Name', 'local-google-fonts' ); ?></th>
139
+ <th scope="col" id="description" class="manage-column column-description"><?php esc_html_e( 'Variants', 'local-google-fonts' ); ?></th>
140
+ <th scope="col" id="auto-updates" class="manage-column column-auto-updates" style="width: 250px"><?php esc_html_e( 'Status', 'local-google-fonts' ); ?></th>
141
+ </tr>
142
+ </thead>
143
+ <tbody>
144
+ <?php $fontinfo = $this->get_font_info( $data['src'] ); ?>
145
+
146
+ <?php foreach ( $fontinfo as $i => $set ) : ?>
147
+ <tr>
148
+ <td><strong><?php echo esc_html( $set->family ); ?></strong><br>
149
+ </td>
150
+ <td>
151
+ <p class="code">
152
+ <?php foreach ( $set->variants as $variant ) : ?>
153
+ <span class="variant"><?php printf( '%s %s', $variant->fontStyle, $variant->fontWeight ); ?></span>
154
+ <?php endforeach ?>
155
+ </p>
156
+ <details>
157
+ <summary><strong><?php printf( '%d files from Google Servers', count( $set->variants ) * 5 ); ?></strong></summary>
158
+ <div style="max-height: 200px; overflow: scroll;font-size: small;white-space: nowrap; overflow: hidden; overflow-y: auto;" class="code">
159
+ <?php foreach ( $set->variants as $variant ) : ?>
160
+ <p>
161
+ <strong><?php printf( '%s %s', $variant->fontStyle, $variant->fontWeight ); ?></strong><br>
162
+ <code><?php echo esc_url( $variant->woff2 ); ?></code><br>
163
+ <code><?php echo esc_url( $variant->ttf ); ?></code><br>
164
+ <code><?php echo esc_url( $variant->svg ); ?></code><br>
165
+ <code><?php echo esc_url( $variant->eot ); ?></code><br>
166
+ <code><?php echo esc_url( $variant->woff ); ?></code>
167
+ </p>
168
+ <?php endforeach ?>
169
+ </div>
170
+ </details>
171
+ </td>
172
+ <td>
173
+ <?php if ( is_dir( $folder . '/' . $data['id'] ) ) : ?>
174
+ <?php printf( '%s %s', '<strong>✔</strong>', esc_html__( 'loaded, served from your server', 'local-google-fonts' ) ); ?>
175
+ <?php else : ?>
176
+ <?php printf( '%s %s', '<strong class="wp-ui-text-notification">✕</strong>', esc_html__( 'not loaded, served from Google servers', 'local-google-fonts' ) ); ?>
177
+ <?php endif; ?>
178
+
179
+ </td>
180
+
181
+ </tr>
182
+ <?php endforeach ?>
183
+ </tbody>
184
+ </table>
185
+ <p>
186
+ <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>
187
+ <?php if ( is_dir( $folder . '/' . $data['id'] ) ) : ?>
188
+ <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>
189
+ <?php endif; ?>
190
+ </p>
191
+ <?php endforeach ?>
192
+ <hr>
193
+ <p class="textright">
194
+ <button class="host-locally button button-link-delete" name="flush" value="1"><?php esc_html_e( 'Remove all stored data', 'local-google-fonts' ); ?></button>
195
+ </p>
196
+ </form>
197
+ </div>
198
+ <?php
199
  }
200
 
201
+
202
  public function get_font_info( $src ) {
203
 
204
  // a bit sanitation as URLs are often registered with esc_url
323
 
324
  }
325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  }
includes/class-local-google-fonts.php CHANGED
@@ -56,6 +56,10 @@ class LGF {
56
 
57
  $WP_Filesystem = $this->wp_filesystem();
58
 
 
 
 
 
59
  $plugin_data = get_plugin_data( LGF_PLUGIN_FILE );
60
 
61
  $style = "/*\n";
@@ -172,6 +176,11 @@ class LGF {
172
  );
173
 
174
  update_option( 'local_google_fonts_buffer', $buffer );
 
 
 
 
 
175
  }
176
 
177
  return $src;
56
 
57
  $WP_Filesystem = $this->wp_filesystem();
58
 
59
+ if ( ! function_exists( 'get_plugin_data' ) ) {
60
+ include ABSPATH . 'wp-admin/includes/plugin.php';
61
+ }
62
+
63
  $plugin_data = get_plugin_data( LGF_PLUGIN_FILE );
64
 
65
  $style = "/*\n";
176
  );
177
 
178
  update_option( 'local_google_fonts_buffer', $buffer );
179
+
180
+ $options = get_option( 'local_google_fonts' );
181
+ if ( isset( $options['auto_load'] ) ) {
182
+ $src = $this->process_url( $src, $handle );
183
+ }
184
  }
185
 
186
  return $src;
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.8
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.9
6
  Author: EverPress
7
  Author URI: https://everpress.co
8
  License: GPLv2 or later