WPTT / webfont-loader

Download webfonts and host them locally on a WordPress site

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typekit font are not loading locally

cristian-ungureanu opened this issue · comments

Given the following external file generated by Adobe fonts, https://use.typekit.net/deq6zwt.css, trying to load fonts locally from it won't work.

I did a bit of debugging and I think I found the issue. The result of get_local_files_from_css function looks like this:

array(1) {
  ["maecenas"]=>
  array(1) {
    [0]=>
    string(148) ""https://use.typekit.net/af/867c45/00000000000000007735c629/30/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=i6&v=3""
  }
}

The URL is wrapped twice in double-quotes and when that URL is passed to download_url it will throw an error saying "A valid URL was not provided."
I didn't checked the get_local_files_from_css function but a simple fix for this would be sanitizing the URL before calling download_url function.
$url = preg_replace('/^"(.*)"$/', '$1', $url);

Let me know what you think, I can submit a PR if you think the fix is good.