3
3
* Download webfonts locally.
4
4
*
5
5
* @package wptt/font-loader
6
+ * @link https://github.com/WPTT/webfont-loader
6
7
* @license https://opensource.org/licenses/MIT
7
8
*/
8
9
@@ -101,9 +102,9 @@ class WPTT_WebFont_Loader {
101
102
*
102
103
* @access protected
103
104
* @since 1.1.0
104
- * @var string
105
+ * @var null| string
105
106
*/
106
- protected $ css ;
107
+ protected $ css = null ;
107
108
108
109
/**
109
110
* Cleanup routine frequency.
@@ -138,6 +139,11 @@ public function __construct( $url = '' ) {
138
139
*/
139
140
public function get_url () {
140
141
142
+ // If remote URL is empty just return itself.
143
+ if ( empty ( $ this ->remote_url ) ) {
144
+ return $ this ->remote_url ;
145
+ }
146
+
141
147
// Check if the local stylesheet exists.
142
148
if ( $ this ->local_file_exists () ) {
143
149
@@ -180,10 +186,20 @@ public function get_local_stylesheet_url() {
180
186
*/
181
187
public function get_styles () {
182
188
189
+ // If remote URL is empty, set empty string.
190
+ if ( empty ( $ this ->remote_url ) ) {
191
+ $ this ->css = '' ;
192
+ }
193
+
194
+ // If the CSS is set already, return it.
195
+ if ( is_string ( $ this ->css ) ) {
196
+ return $ this ->css ;
197
+ }
198
+
183
199
// If we already have the local file, return its contents.
184
- $ local_stylesheet_contents = $ this ->get_local_stylesheet_contents ();
185
- if ( $ local_stylesheet_contents ) {
186
- return $ local_stylesheet_contents ;
200
+ $ this -> css = $ this ->get_local_stylesheet_contents ();
201
+ if ( ! empty ( $ this -> css ) ) {
202
+ return $ this -> css ;
187
203
}
188
204
189
205
// Get the remote URL contents.
@@ -220,7 +236,6 @@ public function get_styles() {
220
236
* @return string|false Returns the remote URL contents.
221
237
*/
222
238
public function get_local_stylesheet_contents () {
223
- $ local_path = $ this ->get_local_stylesheet_path ();
224
239
225
240
// Check if the local stylesheet exists.
226
241
if ( $ this ->local_file_exists () ) {
@@ -232,7 +247,7 @@ public function get_local_stylesheet_contents() {
232
247
}
233
248
234
249
ob_start ();
235
- include $ local_path ;
250
+ include $ this -> get_local_stylesheet_path () ;
236
251
return ob_get_clean ();
237
252
}
238
253
@@ -464,7 +479,7 @@ protected function write_stylesheet() {
464
479
465
480
// If the folder doesn't exist, create it.
466
481
if ( ! file_exists ( $ this ->get_fonts_folder () ) ) {
467
- $ this -> get_filesystem () ->mkdir ( $ this ->get_fonts_folder (), FS_CHMOD_DIR );
482
+ $ filesystem ->mkdir ( $ this ->get_fonts_folder (), FS_CHMOD_DIR );
468
483
}
469
484
470
485
// If the file doesn't exist, create it. Return false if it can not be created.
@@ -474,7 +489,7 @@ protected function write_stylesheet() {
474
489
475
490
// If we got this far, we need to write the file.
476
491
// Get the CSS.
477
- if ( ! $ this ->css ) {
492
+ if ( null === $ this ->css ) {
478
493
$ this ->get_styles ();
479
494
}
480
495
@@ -529,6 +544,10 @@ public function set_font_format( $format = 'woff2' ) {
529
544
/**
530
545
* Check if the local stylesheet exists.
531
546
*
547
+ * The name of this method is wrong. Should be "no_local_file_exists()"
548
+ * as it returns true if the file does NOT exist.
549
+ * Keeping the original name not to break 3rd party scripts.
550
+ *
532
551
* @access public
533
552
* @since 1.1.0
534
553
* @return bool
0 commit comments