Changeset 52069 for trunk/src/wp-includes/block-supports/typography.php
- Timestamp:
- 11/09/2021 02:15:23 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/typography.php
r51246 r52069 29 29 $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false ); 30 30 $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false ); 31 $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false ); 31 32 $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false ); 32 33 $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false ); … … 37 38 || $has_font_style_support 38 39 || $has_font_weight_support 40 || $has_letter_spacing_support 39 41 || $has_line_height_support 40 42 || $has_text_decoration_support … … 94 96 $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false ); 95 97 $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false ); 98 $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false ); 96 99 $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false ); 97 100 $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false ); … … 103 106 104 107 if ( $has_named_font_size ) { 105 $classes[] = sprintf( 'has-%s-font-size', $block_attributes['fontSize']);108 $classes[] = sprintf( 'has-%s-font-size', _wp_to_kebab_case( $block_attributes['fontSize'] ) ); 106 109 } elseif ( $has_custom_font_size ) { 107 110 $styles[] = sprintf( 'font-size: %s;', $block_attributes['style']['typography']['fontSize'] ); … … 110 113 111 114 if ( $has_font_family_support ) { 112 $has_font_family = isset( $block_attributes['style']['typography']['fontFamily'] ); 113 if ( $has_font_family ) { 114 $font_family = $block_attributes['style']['typography']['fontFamily']; 115 if ( strpos( $font_family, 'var:preset|font-family' ) !== false ) { 116 // Get the name from the string and add proper styles. 117 $index_to_splice = strrpos( $font_family, '|' ) + 1; 118 $font_family_name = substr( $font_family, $index_to_splice ); 119 $styles[] = sprintf( 'font-family: var(--wp--preset--font-family--%s);', $font_family_name ); 120 } else { 121 $styles[] = sprintf( 'font-family: %s;', $block_attributes['style']['typography']['fontFamily'] ); 115 $has_named_font_family = array_key_exists( 'fontFamily', $block_attributes ); 116 $has_custom_font_family = isset( $block_attributes['style']['typography']['fontFamily'] ); 117 118 if ( $has_named_font_family ) { 119 $classes[] = sprintf( 'has-%s-font-family', _wp_to_kebab_case( $block_attributes['fontFamily'] ) ); 120 } elseif ( $has_custom_font_family ) { 121 // Before using classes, the value was serialized as a CSS Custom Property. 122 // We don't need this code path when it lands in core. 123 $font_family_custom = $block_attributes['style']['typography']['fontFamily']; 124 if ( strpos( $font_family_custom, 'var:preset|font-family' ) !== false ) { 125 $index_to_splice = strrpos( $font_family_custom, '|' ) + 1; 126 $font_family_slug = _wp_to_kebab_case( substr( $font_family_custom, $index_to_splice ) ); 127 $font_family_custom = sprintf( 'var(--wp--preset--font-family--%s)', $font_family_slug ); 122 128 } 129 $styles[] = sprintf( 'font-family: %s;', $font_family_custom ); 123 130 } 124 131 } … … 156 163 if ( $text_transform_style ) { 157 164 $styles[] = $text_transform_style; 165 } 166 } 167 168 if ( $has_letter_spacing_support ) { 169 $letter_spacing_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'letterSpacing', 'letter-spacing' ); 170 if ( $letter_spacing_style ) { 171 $styles[] = $letter_spacing_style; 158 172 } 159 173 }
Note: See TracChangeset
for help on using the changeset viewer.