Version Description
Download this release
Release Info
Developer | everpress |
Plugin | Local Google Fonts |
Version | 0.7 |
Comparing to | |
See all releases |
Code changes from version 0.6 to 0.7
- README.md +5 -1
- includes/class-local-google-fonts-admin.php +14 -0
- includes/class-local-google-fonts.php +28 -1
- local-google-fonts.php +1 -1
README.md
CHANGED
@@ -4,7 +4,7 @@ Contributors: everpress
|
|
4 |
Tags: googlefonts, google, fonts, gdpr, lgf, font, speed
|
5 |
Requires at least: 4.2
|
6 |
Tested up to: 6.0
|
7 |
-
Stable tag: 0.
|
8 |
Requires PHP: 5.6+
|
9 |
License: GPLv2 or later
|
10 |
Author: EverPress
|
@@ -60,6 +60,10 @@ The plugin currently only checks fonts embedded via [`wp_enqueue_style`](https:/
|
|
60 |
|
61 |
## Changelog
|
62 |
|
|
|
|
|
|
|
|
|
63 |
### 0.6
|
64 |
|
65 |
- loading all variants if none explicit are requested
|
4 |
Tags: googlefonts, google, fonts, gdpr, lgf, font, speed
|
5 |
Requires at least: 4.2
|
6 |
Tested up to: 6.0
|
7 |
+
Stable tag: 0.7
|
8 |
Requires PHP: 5.6+
|
9 |
License: GPLv2 or later
|
10 |
Author: EverPress
|
60 |
|
61 |
## Changelog
|
62 |
|
63 |
+
### 0.7
|
64 |
+
|
65 |
+
- better handling of multiple "family" arguments in the URL
|
66 |
+
|
67 |
### 0.6
|
68 |
|
69 |
- loading all variants if none explicit are requested
|
includes/class-local-google-fonts-admin.php
CHANGED
@@ -77,6 +77,20 @@ class LGF_Admin {
|
|
77 |
|
78 |
$query = wp_parse_url( $src, PHP_URL_QUERY );
|
79 |
wp_parse_str( $query, $args );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
$args = wp_parse_args(
|
81 |
$args,
|
82 |
array(
|
77 |
|
78 |
$query = wp_parse_url( $src, PHP_URL_QUERY );
|
79 |
wp_parse_str( $query, $args );
|
80 |
+
|
81 |
+
// handling of multiple "family" arguments
|
82 |
+
$parts = explode( '&', $query );
|
83 |
+
$groups = array();
|
84 |
+
foreach ( $parts as $part ) {
|
85 |
+
if ( 0 === strpos( $part, 'family=' ) ) {
|
86 |
+
$groups[] = str_replace( 'family=', '', $part );
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
if ( ! empty( $groups ) ) {
|
91 |
+
$args['family'] = rawurldecode( implode( '|', $groups ) );
|
92 |
+
}
|
93 |
+
|
94 |
$args = wp_parse_args(
|
95 |
$args,
|
96 |
array(
|
includes/class-local-google-fonts.php
CHANGED
@@ -19,6 +19,9 @@ class LGF {
|
|
19 |
add_filter( 'activated_plugin', array( $this, 'clear_option' ) );
|
20 |
add_filter( 'wp_resource_hints', array( $this, 'remove_dns_prefetch' ), 10, 2 );
|
21 |
|
|
|
|
|
|
|
22 |
}
|
23 |
|
24 |
public static function get_instance() {
|
@@ -125,7 +128,27 @@ class LGF {
|
|
125 |
}
|
126 |
|
127 |
|
128 |
-
public function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
$id = md5( $src );
|
131 |
|
@@ -140,6 +163,10 @@ class LGF {
|
|
140 |
$src = add_query_arg( 'v', filemtime( $stylesheet ), $stylesheet_url );
|
141 |
} else {
|
142 |
|
|
|
|
|
|
|
|
|
143 |
$buffer[ $handle ] = array(
|
144 |
'id' => $id,
|
145 |
'handle' => $handle,
|
19 |
add_filter( 'activated_plugin', array( $this, 'clear_option' ) );
|
20 |
add_filter( 'wp_resource_hints', array( $this, 'remove_dns_prefetch' ), 10, 2 );
|
21 |
|
22 |
+
add_filter( 'local_google_fonts_replace_in_content', array( $this, 'replace_in_content' ) );
|
23 |
+
add_filter( 'local_google_fonts_replace_url', array( $this, 'google_to_local_url' ), 10, 2 );
|
24 |
+
|
25 |
}
|
26 |
|
27 |
public static function get_instance() {
|
128 |
}
|
129 |
|
130 |
|
131 |
+
public function replace_in_content( $content ) {
|
132 |
+
|
133 |
+
if ( false !== strpos( $content, '//fonts.googleapis.com/css' ) ) {
|
134 |
+
|
135 |
+
$regex = "/\b(?:(?:https?):\/\/fonts\.googleapis\.com\/css)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i";
|
136 |
+
|
137 |
+
if ( $urls = preg_match_all( $regex, $content, $matches ) ) {
|
138 |
+
foreach ( $matches[0] as $i => $url ) {
|
139 |
+
$local_url = $this->google_to_local_url( $url );
|
140 |
+
if ( $local_url != $url ) {
|
141 |
+
$content = str_replace( $url, $local_url, $content );
|
142 |
+
}
|
143 |
+
}
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
return $content;
|
148 |
+
}
|
149 |
+
|
150 |
+
|
151 |
+
public function google_to_local_url( $src, $handle = null ) {
|
152 |
|
153 |
$id = md5( $src );
|
154 |
|
163 |
$src = add_query_arg( 'v', filemtime( $stylesheet ), $stylesheet_url );
|
164 |
} else {
|
165 |
|
166 |
+
if ( is_null( $handle ) ) {
|
167 |
+
$handle = $id;
|
168 |
+
}
|
169 |
+
|
170 |
$buffer[ $handle ] = array(
|
171 |
'id' => $id,
|
172 |
'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.
|
6 |
Author: EverPress
|
7 |
Author URI: https://everpress.co
|
8 |
Text Domain: local-google-fonts
|
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.7
|
6 |
Author: EverPress
|
7 |
Author URI: https://everpress.co
|
8 |
Text Domain: local-google-fonts
|