Skip to content

Commit

Permalink
add theme fonts uris
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbenedetto committed Sep 26, 2024
1 parent 8ced871 commit ee98b6e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,50 @@ public static function get_style_variations_from_directory( $directory, $scope =
return $variations;
}

/**
* Resolves relative paths in theme.json typography to theme absolute paths
* and returns them in an array that can be embedded
* as the value of `_link` object in REST API responses.
*
* @since 6.6.0
*
* @param

Check failure on line 841 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
* @return array An array of resolved paths.
*/
private static function get_resolved_fonts_theme_uris( $theme_json_data ) {
$resolved_theme_uris = array();

if ( !empty( $theme_json_data['settings']['typography']['fontFamilies'] ) ) {

Check failure on line 847 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 space after "!"; 0 found

$font_families = ( $theme_json_data['settings']['typography']['fontFamilies']['theme'] ?? array() )
+ ( $theme_json_data['settings']['typography']['fontFamilies']['custom'] ?? array() )
+ ( $theme_json_data['settings']['typography']['fontFamilies']['default'] ?? array() );

foreach ( $font_families as $font_family ) {
if ( !empty( $font_family['fontFace'] ) ) {

Check failure on line 854 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 space after "!"; 0 found
foreach ( $font_family['fontFace'] as $font_face ) {
if ( !empty( $font_face['src'] ) ) {

Check failure on line 856 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 space after "!"; 0 found
$sources = is_string( $font_face['src'] )

Check failure on line 857 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
? array( $font_face['src'] )
: $font_face['src'];
foreach ( $sources as $source ) {
if ( str_starts_with( $source, 'file:' ) ) {
$resolved_theme_uris[] = array(
'name' => $source,

Check warning on line 863 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 3 space(s) between "'name'" and double arrow, but found 1.
'href' => sanitize_url( get_theme_file_uri( str_replace( 'file:./', '', $source ) ) ),

Check warning on line 864 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 3 space(s) between "'href'" and double arrow, but found 1.
'target' => "typography.fontFamilies.{$font_family['slug']}.fontFace.src",
);
}
}
}
}
}
}
}

return $resolved_theme_uris;
}


/**
* Resolves relative paths in theme.json styles to theme absolute paths
Expand All @@ -852,6 +896,12 @@ public static function get_resolved_theme_uris( $theme_json ) {

$theme_json_data = $theme_json->get_raw_data();

// Add font URIs.
$resolved_theme_uris = array_merge(
$resolved_theme_uris,
static::get_resolved_fonts_theme_uris( $theme_json_data )
);

// Using the same file convention when registering web fonts. See: WP_Font_Face_Resolver:: to_theme_file_uri.
$placeholder = 'file:./';

Expand Down

0 comments on commit ee98b6e

Please sign in to comment.