Skip to content

Commit d29bfe0

Browse files
committed
Simplify font style rule generation for system and external
1 parent 24943c3 commit d29bfe0

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

includes/class-amp-story-post-type.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,29 +1402,23 @@ public static function render_block_with_google_fonts( $block_content, $block )
14021402
}
14031403

14041404
$font = self::get_font( $block['attrs'][ $font_family_attribute ] );
1405-
14061405
if ( ! $font ) {
14071406
return $block_content;
14081407
}
14091408

1410-
// Output system fonts.
1411-
if ( ! isset( $font['handle'], $font['src'] ) ) {
1412-
$style = sprintf( '<style data-font-family="%s">%s</style>', esc_attr( $font['name'] ), self::get_inline_font_style_rule( $font ) );
1413-
return $style . $block_content;
1414-
}
1415-
1416-
if ( wp_style_is( $font['handle'] ) ) {
1417-
return $block_content;
1418-
}
1419-
1420-
wp_enqueue_style( $font['handle'], $font['src'], [], null, 'all' ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
1421-
1422-
wp_add_inline_style(
1423-
$font['handle'],
1409+
// Create style rule for the custom font. The style sanitizer will de-duplicate.
1410+
$style = sprintf(
1411+
'<style data-font-family="%s">%s</style>',
1412+
esc_attr( $font['name'] ),
14241413
self::get_inline_font_style_rule( $font )
14251414
);
14261415

1427-
return $block_content;
1416+
// Make sure that the Google Font is enqueued.
1417+
if ( isset( $font['src'], $font['handle'] ) && ! wp_style_is( $font['handle'] ) ) {
1418+
wp_enqueue_style( $font['handle'], $font['src'], [], null, 'all' ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
1419+
}
1420+
1421+
return $style . $block_content;
14281422
}
14291423

14301424
/**

0 commit comments

Comments
 (0)