Make WordPress Core


Ignore:
Timestamp:
11/09/2021 02:15:23 AM (3 years ago)
Author:
noisysocks
Message:

Add Site Editor and PHP changes from Gutenberg 10.1 - 11.9

  • First pass at adding the site editor from the Gutenberg plugin to wp-admin/site-editor.php.
  • Adds miscellaneous PHP changes from Gutenberg 10.1 - 11.9.

Follows [52042].
See #54337.
Props youknowriad, aristath, hellofromtonya, gziolo.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/typography.php

    r51246 r52069  
    2929    $has_font_style_support      = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
    3030    $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 );
    3132    $has_line_height_support     = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
    3233    $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
     
    3738        || $has_font_style_support
    3839        || $has_font_weight_support
     40        || $has_letter_spacing_support
    3941        || $has_line_height_support
    4042        || $has_text_decoration_support
     
    9496    $has_font_style_support      = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
    9597    $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 );
    9699    $has_line_height_support     = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
    97100    $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
     
    103106
    104107        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'] ) );
    106109        } elseif ( $has_custom_font_size ) {
    107110            $styles[] = sprintf( 'font-size: %s;', $block_attributes['style']['typography']['fontSize'] );
     
    110113
    111114    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 );
    122128            }
     129            $styles[] = sprintf( 'font-family: %s;', $font_family_custom );
    123130        }
    124131    }
     
    156163        if ( $text_transform_style ) {
    157164            $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;
    158172        }
    159173    }
Note: See TracChangeset for help on using the changeset viewer.