Make WordPress Core


Ignore:
Timestamp:
06/04/2024 05:34:12 AM (12 months ago)
Author:
ellatrix
Message:

Editor: add textAlign block support.

See https://github.com/WordPress/gutenberg/pull/59531.
See https://github.com/WordPress/gutenberg/pull/61182.
See https://github.com/WordPress/gutenberg/pull/61717.
See https://github.com/WordPress/wordpress-develop/pull/6590.

Fixes #61256.

Props wildworks, ellatrix.

File:
1 edited

Legend:

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

    r58171 r58314  
    3232    $has_letter_spacing_support  = isset( $typography_supports['__experimentalLetterSpacing'] ) ? $typography_supports['__experimentalLetterSpacing'] : false;
    3333    $has_line_height_support     = isset( $typography_supports['lineHeight'] ) ? $typography_supports['lineHeight'] : false;
     34    $has_text_align_support      = isset( $typography_supports['textAlign'] ) ? $typography_supports['textAlign'] : false;
    3435    $has_text_columns_support    = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
    3536    $has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
     
    4344        || $has_letter_spacing_support
    4445        || $has_line_height_support
     46        || $has_text_align_support
    4547        || $has_text_columns_support
    4648        || $has_text_decoration_support
     
    107109    $has_letter_spacing_support  = isset( $typography_supports['__experimentalLetterSpacing'] ) ? $typography_supports['__experimentalLetterSpacing'] : false;
    108110    $has_line_height_support     = isset( $typography_supports['lineHeight'] ) ? $typography_supports['lineHeight'] : false;
     111    $has_text_align_support      = isset( $typography_supports['textAlign'] ) ? $typography_supports['textAlign'] : false;
    109112    $has_text_columns_support    = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
    110113    $has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
     
    118121    $should_skip_font_weight     = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontWeight' );
    119122    $should_skip_line_height     = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'lineHeight' );
     123    $should_skip_text_align      = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textAlign' );
    120124    $should_skip_text_columns    = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textColumns' );
    121125    $should_skip_text_decoration = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' );
     
    177181    }
    178182
     183    if ( $has_text_align_support && ! $should_skip_text_align ) {
     184        $typography_block_styles['textAlign'] = isset( $block_attributes['style']['typography']['textAlign'] )
     185            ? $block_attributes['style']['typography']['textAlign']
     186            : null;
     187    }
     188
    179189    if ( $has_text_columns_support && ! $should_skip_text_columns && isset( $block_attributes['style']['typography']['textColumns'] ) ) {
    180190        $typography_block_styles['textColumns'] = isset( $block_attributes['style']['typography']['textColumns'] )
     
    226236
    227237    $attributes = array();
     238    $classnames = array();
    228239    $styles     = wp_style_engine_get_styles(
    229240        array( 'typography' => $typography_block_styles ),
     
    232243
    233244    if ( ! empty( $styles['classnames'] ) ) {
    234         $attributes['class'] = $styles['classnames'];
     245        $classnames[] = $styles['classnames'];
     246    }
     247
     248    if ( $has_text_align_support && ! $should_skip_text_align && isset( $block_attributes['style']['typography']['textAlign'] ) ) {
     249        $classnames[] = 'has-text-align-' . $block_attributes['style']['typography']['textAlign'];
     250    }
     251
     252    if ( ! empty( $classnames ) ) {
     253        $attributes['class'] = implode( ' ', $classnames );
    235254    }
    236255
Note: See TracChangeset for help on using the changeset viewer.