Skip to content

Commit

Permalink
Support custom font families
Browse files Browse the repository at this point in the history
There may be cases in which patterns add their own font-families
without being slugs for us to process.
  • Loading branch information
oandregal committed Jul 5, 2021
1 parent cf4d770 commit 16f2bc1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,18 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {

if ( $has_font_family_support ) {
$has_named_font_family = array_key_exists( 'fontFamily', $block_attributes );
$has_legacy_font_family = isset( $block_attributes['style']['typography']['fontFamily'] );
$has_custom_font_family = isset( $block_attributes['style']['typography']['fontFamily'] );

if ( $has_named_font_family ) {
$classes[] = sprintf( 'has-%s-font-family', $block_attributes['fontFamily'] );
} elseif ( $has_legacy_font_family ) {
$font_family = $block_attributes['style']['typography']['fontFamily'];
if ( strpos( $font_family, 'var:preset|font-family' ) !== false ) {
$index_to_splice = strrpos( $font_family, '|' ) + 1;
$font_family_name = substr( $font_family, $index_to_splice );
$styles[] = sprintf( 'font-family: var(--wp--preset--font-family--%s) !important;', $font_family_name );
$font_family_custom = $block_attributes['style']['typography']['fontFamily'];
if ( strpos( $font_family_custom, 'var:preset|font-family' ) !== false ) {
$index_to_splice = strrpos( $font_family_custom, '|' ) + 1;
$font_family_slug = substr( $font_family_custom, $index_to_splice );
$classes[] = sprintf( 'has-%s-font-family', $font_family_slug );
} else {
$styles[] = sprintf( 'font-family: %s', $font_family_custom );
}
}
}
Expand Down

0 comments on commit 16f2bc1

Please sign in to comment.