Skip to content

Commit 780e564

Browse files
committed
fixes #13
1 parent 1d33040 commit 780e564

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

wptt-webfont-loader.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function get_local_files_from_css() {
283283
$font_files = $this->get_remote_files_from_css();
284284
$stored = get_site_option( 'downloaded_font_files', array() );
285285
$change = false; // If in the end this is true, we need to update the cache option.
286-
286+
287287
if ( ! defined( 'FS_CHMOD_DIR' ) ) {
288288
define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );
289289
}
@@ -418,7 +418,12 @@ public function get_remote_files_from_css() {
418418
}
419419

420420
// Add the file URL.
421-
$result[ $font_family ][] = rtrim( ltrim( $match[0], 'url(' ), ')' );
421+
$font_family_url = rtrim( ltrim( $match[0], 'url(' ), ')' );
422+
423+
// Make sure to convert relative URLs to absolute.
424+
$font_family_url = $this->get_absolute_path( $font_family_url );
425+
426+
$result[ $font_family ][] = $font_family_url;
422427
}
423428

424429
// Make sure we have unique items.
@@ -438,7 +443,7 @@ public function get_remote_files_from_css() {
438443
protected function write_stylesheet() {
439444
$file_path = $this->get_local_stylesheet_path();
440445
$filesystem = $this->get_filesystem();
441-
446+
442447
if ( ! defined( 'FS_CHMOD_DIR' ) ) {
443448
define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );
444449
}
@@ -627,6 +632,26 @@ protected function get_filesystem() {
627632
}
628633
return $wp_filesystem;
629634
}
635+
636+
/**
637+
* Get an absolute URL from a relative URL.
638+
*
639+
* @access protected
640+
*
641+
* @param string $url The URL.
642+
*
643+
* @return string
644+
*/
645+
protected function get_absolute_path( $url ) {
646+
647+
// If dealing with a root-relative URL.
648+
if ( 0 === stripos( $url, '/' ) ) {
649+
$parsed_url = parse_url( $this->remote_url );
650+
return $parsed_url['scheme'] . '://' . $parsed_url['hostname'] . $url;
651+
}
652+
653+
return $url;
654+
}
630655
}
631656
}
632657

0 commit comments

Comments
 (0)