Skip to content

Commit

Permalink
Move src attribute processing to the local provider
Browse files Browse the repository at this point in the history
  • Loading branch information
zaguiini committed Mar 17, 2022
1 parent 7a12067 commit 5ab6da7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/compat/wordpress-6.0/class-wp-webfonts-provider-local.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ private function compile_src( $font_family, array $value ) {
$src = "local($font_family)";

foreach ( $value as $item ) {

if ( 0 === strpos( $item['url'], get_site_url() ) ) {
$item['url'] = wp_make_link_relative( $item['url'] );
if ( 0 === strpos( $item['url'], 'file:./' ) ) {
$absolute_path_to_url = get_stylesheet_directory_uri() . '/' . str_replace( 'file:./', '', $item['url'] );
$item['url'] = wp_make_link_relative( $absolute_path_to_url );
}

$src .= ( 'data' === $item['format'] )
Expand Down
13 changes: 0 additions & 13 deletions lib/compat/wordpress-6.0/register-webfonts-from-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ function gutenberg_register_webfonts_from_theme_json() {
$font_family['fontFace'] = (array) $font_family['fontFace'];

foreach ( $font_family['fontFace'] as $font_face ) {
// Check if webfonts have a "src" param, and if they do account for the use of "file:./".
if ( ! empty( $font_face['src'] ) ) {
$font_face['src'] = (array) $font_face['src'];

foreach ( $font_face['src'] as $src_key => $url ) {
// Tweak the URL to be relative to the theme root.
if ( 0 !== strpos( $url, 'file:./' ) ) {
continue;
}
$font_face['src'][ $src_key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) );
}
}

// Convert keys to kebab-case.
foreach ( $font_face as $property => $value ) {
$kebab_case = _wp_to_kebab_case( $property );
Expand Down

0 comments on commit 5ab6da7

Please sign in to comment.