Skip to content

Commit

Permalink
Editor: add textAlign block support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 4, 2024
1 parent d546ce7 commit 12bc7a8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
21 changes: 20 additions & 1 deletion wp-includes/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function wp_register_typography_support( $block_type ) {
$has_font_weight_support = isset( $typography_supports['__experimentalFontWeight'] ) ? $typography_supports['__experimentalFontWeight'] : false;
$has_letter_spacing_support = isset( $typography_supports['__experimentalLetterSpacing'] ) ? $typography_supports['__experimentalLetterSpacing'] : false;
$has_line_height_support = isset( $typography_supports['lineHeight'] ) ? $typography_supports['lineHeight'] : false;
$has_text_align_support = isset( $typography_supports['textAlign'] ) ? $typography_supports['textAlign'] : false;
$has_text_columns_support = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
$has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
$has_text_transform_support = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
Expand All @@ -42,6 +43,7 @@ function wp_register_typography_support( $block_type ) {
|| $has_font_weight_support
|| $has_letter_spacing_support
|| $has_line_height_support
|| $has_text_align_support
|| $has_text_columns_support
|| $has_text_decoration_support
|| $has_text_transform_support
Expand Down Expand Up @@ -106,6 +108,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
$has_font_weight_support = isset( $typography_supports['__experimentalFontWeight'] ) ? $typography_supports['__experimentalFontWeight'] : false;
$has_letter_spacing_support = isset( $typography_supports['__experimentalLetterSpacing'] ) ? $typography_supports['__experimentalLetterSpacing'] : false;
$has_line_height_support = isset( $typography_supports['lineHeight'] ) ? $typography_supports['lineHeight'] : false;
$has_text_align_support = isset( $typography_supports['textAlign'] ) ? $typography_supports['textAlign'] : false;
$has_text_columns_support = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
$has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
$has_text_transform_support = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
Expand All @@ -117,6 +120,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
$should_skip_font_style = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontStyle' );
$should_skip_font_weight = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontWeight' );
$should_skip_line_height = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'lineHeight' );
$should_skip_text_align = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textAlign' );
$should_skip_text_columns = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textColumns' );
$should_skip_text_decoration = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' );
$should_skip_text_transform = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' );
Expand Down Expand Up @@ -176,6 +180,12 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
: null;
}

if ( $has_text_align_support && ! $should_skip_text_align ) {
$typography_block_styles['textAlign'] = isset( $block_attributes['style']['typography']['textAlign'] )
? $block_attributes['style']['typography']['textAlign']
: null;
}

if ( $has_text_columns_support && ! $should_skip_text_columns && isset( $block_attributes['style']['typography']['textColumns'] ) ) {
$typography_block_styles['textColumns'] = isset( $block_attributes['style']['typography']['textColumns'] )
? $block_attributes['style']['typography']['textColumns']
Expand Down Expand Up @@ -225,13 +235,22 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
}

$attributes = array();
$classnames = array();
$styles = wp_style_engine_get_styles(
array( 'typography' => $typography_block_styles ),
array( 'convert_vars_to_classnames' => true )
);

if ( ! empty( $styles['classnames'] ) ) {
$attributes['class'] = $styles['classnames'];
$classnames[] = $styles['classnames'];
}

if ( $has_text_align_support && ! $should_skip_text_align && isset( $block_attributes['style']['typography']['textAlign'] ) ) {
$classnames[] = 'has-text-align-' . $block_attributes['style']['typography']['textAlign'];
}

if ( ! empty( $classnames ) ) {
$attributes['class'] = implode( ' ', $classnames );
}

if ( ! empty( $styles['css'] ) ) {
Expand Down
3 changes: 3 additions & 0 deletions wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class WP_Theme_JSON {
'border-left-width' => array( 'border', 'left', 'width' ),
'border-left-style' => array( 'border', 'left', 'style' ),
'color' => array( 'color', 'text' ),
'text-align' => array( 'typography', 'textAlign' ),
'column-count' => array( 'typography', 'textColumns' ),
'font-family' => array( 'typography', 'fontFamily' ),
'font-size' => array( 'typography', 'fontSize' ),
Expand Down Expand Up @@ -454,6 +455,7 @@ class WP_Theme_JSON {
'fontWeight' => null,
'letterSpacing' => null,
'lineHeight' => null,
'textAlign' => null,
'textColumns' => null,
'textDecoration' => null,
'textTransform' => null,
Expand Down Expand Up @@ -558,6 +560,7 @@ class WP_Theme_JSON {
'fontWeight' => null,
'letterSpacing' => null,
'lineHeight' => null,
'textAlign' => null,
'textColumns' => null,
'textDecoration' => null,
'textTransform' => null,
Expand Down
1 change: 1 addition & 0 deletions wp-includes/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
"fontWeight": true,
"letterSpacing": true,
"lineHeight": false,
"textAlign": true,
"textDecoration": true,
"textTransform": true,
"writingMode": false
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-58313';
$wp_version = '6.6-alpha-58314';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 12bc7a8

Please sign in to comment.