Skip to content

Commit

Permalink
The _wp_resolve_font_face_uri function is only used once. Can be removed
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Apr 20, 2022
1 parent b2eb078 commit 0de1117
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
13 changes: 12 additions & 1 deletion lib/experimental/register-webfonts-from-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,19 @@ function _wp_register_webfonts_from_theme_json( $settings ) {
}

foreach ( $font_family['fontFaces'] as $font_face ) {

// Transforms the source of the font face from `file.:/` into an actual URI.
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 ( ! str_starts_with( $url, 'file:./' ) ) {
continue;
}
$font_face['src'][ $src_key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) );
}
}
$font_face['provider'] = $font_family['provider'];
$font_face = _wp_resolve_font_face_uri( $font_face );
$font_face = _wp_array_keys_to_kebab_case( $font_face );

$font_faces_to_register[] = $font_face;
Expand Down
29 changes: 0 additions & 29 deletions lib/experimental/webfonts-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,6 @@
* @package gutenberg
*/

if ( ! function_exists( '_wp_resolve_font_face_uri' ) ) {
/**
* Transforms the source of the font face from `file.:/` into an actual URI.
*
* @since 6.0.0
* @private
*
* @param array $font_face The font face.
* @return array The URI-resolved font face.
*/
function _wp_resolve_font_face_uri( array $font_face ) {
if ( empty( $font_face['src'] ) ) {
return $font_face;
}

$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 ( ! str_starts_with( $url, 'file:./' ) ) {
continue;
}
$font_face['src'][ $src_key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) );
}

return $font_face;
}
}

if ( ! function_exists( '_wp_array_keys_to_camel_case' ) ) {
/**
* Transforms the keys in the given array to camelCase.
Expand Down

0 comments on commit 0de1117

Please sign in to comment.