Skip to content

Commit

Permalink
fixes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Jun 17, 2022
1 parent 1d33040 commit 780e564
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions wptt-webfont-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function get_local_files_from_css() {
$font_files = $this->get_remote_files_from_css();
$stored = get_site_option( 'downloaded_font_files', array() );
$change = false; // If in the end this is true, we need to update the cache option.

if ( ! defined( 'FS_CHMOD_DIR' ) ) {
define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );
}
Expand Down Expand Up @@ -418,7 +418,12 @@ public function get_remote_files_from_css() {
}

// Add the file URL.
$result[ $font_family ][] = rtrim( ltrim( $match[0], 'url(' ), ')' );
$font_family_url = rtrim( ltrim( $match[0], 'url(' ), ')' );

// Make sure to convert relative URLs to absolute.
$font_family_url = $this->get_absolute_path( $font_family_url );

$result[ $font_family ][] = $font_family_url;
}

// Make sure we have unique items.
Expand All @@ -438,7 +443,7 @@ public function get_remote_files_from_css() {
protected function write_stylesheet() {
$file_path = $this->get_local_stylesheet_path();
$filesystem = $this->get_filesystem();

if ( ! defined( 'FS_CHMOD_DIR' ) ) {
define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );
}
Expand Down Expand Up @@ -627,6 +632,26 @@ protected function get_filesystem() {
}
return $wp_filesystem;
}

/**
* Get an absolute URL from a relative URL.
*
* @access protected
*
* @param string $url The URL.
*
* @return string
*/
protected function get_absolute_path( $url ) {

// If dealing with a root-relative URL.
if ( 0 === stripos( $url, '/' ) ) {
$parsed_url = parse_url( $this->remote_url );
return $parsed_url['scheme'] . '://' . $parsed_url['hostname'] . $url;
}

return $url;
}
}
}

Expand Down

0 comments on commit 780e564

Please sign in to comment.