Skip to content

Commit

Permalink
Get font family slug through wp_register_webfonts output
Browse files Browse the repository at this point in the history
  • Loading branch information
zaguiini committed Apr 6, 2022
1 parent 47ba4d4 commit dda5f5d
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function register_google_fonts() {
$fonts_to_register = apply_filters( 'jetpack_google_fonts_list', JETPACK_GOOGLE_FONTS_LIST );

foreach ( $fonts_to_register as $font_family ) {
wp_register_webfonts(
$font_family_slugs = wp_register_webfonts(
array(
array(
'font-family' => $font_family,
Expand All @@ -82,15 +82,24 @@ public function register_google_fonts() {
)
);

$slug = wp_webfonts()->get_font_slug( $font_family );
if ( empty( $font_family_slugs ) ) {
// Fonts were not registered.
continue;
}

/**
* As we're registering faces for the same font family,
* let's just pick the first one as they must be equal.
*/
$font_family_slug = $font_family_slugs[0];

/**
* When introspecting, all we have is the slug,
* so we need to keep track of the registered families
* to check whether the font was filtered after
* running the `jetpack_google_fonts_list` hook.
*/
$this->registered_google_fonts[ $slug ] = $font_family;
$this->registered_google_fonts[ $font_family_slug ] = $font_family;
}
}

Expand Down

0 comments on commit dda5f5d

Please sign in to comment.