Skip to content

Commit 12bc7a8

Browse files
committed
Editor: add textAlign block support.
See WordPress/gutenberg#59531. See WordPress/gutenberg#61182. See WordPress/gutenberg#61717. See WordPress/wordpress-develop#6590. Fixes #61256. Props wildworks, ellatrix. Built from https://develop.svn.wordpress.org/trunk@58314 git-svn-id: http://core.svn.wordpress.org/trunk@57771 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent d546ce7 commit 12bc7a8

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

wp-includes/block-supports/typography.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function wp_register_typography_support( $block_type ) {
3131
$has_font_weight_support = isset( $typography_supports['__experimentalFontWeight'] ) ? $typography_supports['__experimentalFontWeight'] : false;
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;
3637
$has_text_transform_support = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
@@ -42,6 +43,7 @@ function wp_register_typography_support( $block_type ) {
4243
|| $has_font_weight_support
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
4749
|| $has_text_transform_support
@@ -106,6 +108,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
106108
$has_font_weight_support = isset( $typography_supports['__experimentalFontWeight'] ) ? $typography_supports['__experimentalFontWeight'] : false;
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;
111114
$has_text_transform_support = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
@@ -117,6 +120,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
117120
$should_skip_font_style = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontStyle' );
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' );
122126
$should_skip_text_transform = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' );
@@ -176,6 +180,12 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
176180
: null;
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'] )
181191
? $block_attributes['style']['typography']['textColumns']
@@ -225,13 +235,22 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
225235
}
226236

227237
$attributes = array();
238+
$classnames = array();
228239
$styles = wp_style_engine_get_styles(
229240
array( 'typography' => $typography_block_styles ),
230241
array( 'convert_vars_to_classnames' => true )
231242
);
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

237256
if ( ! empty( $styles['css'] ) ) {

wp-includes/class-wp-theme-json.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class WP_Theme_JSON {
256256
'border-left-width' => array( 'border', 'left', 'width' ),
257257
'border-left-style' => array( 'border', 'left', 'style' ),
258258
'color' => array( 'color', 'text' ),
259+
'text-align' => array( 'typography', 'textAlign' ),
259260
'column-count' => array( 'typography', 'textColumns' ),
260261
'font-family' => array( 'typography', 'fontFamily' ),
261262
'font-size' => array( 'typography', 'fontSize' ),
@@ -454,6 +455,7 @@ class WP_Theme_JSON {
454455
'fontWeight' => null,
455456
'letterSpacing' => null,
456457
'lineHeight' => null,
458+
'textAlign' => null,
457459
'textColumns' => null,
458460
'textDecoration' => null,
459461
'textTransform' => null,
@@ -558,6 +560,7 @@ class WP_Theme_JSON {
558560
'fontWeight' => null,
559561
'letterSpacing' => null,
560562
'lineHeight' => null,
563+
'textAlign' => null,
561564
'textColumns' => null,
562565
'textDecoration' => null,
563566
'textTransform' => null,

wp-includes/theme.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
"fontWeight": true,
304304
"letterSpacing": true,
305305
"lineHeight": false,
306+
"textAlign": true,
306307
"textDecoration": true,
307308
"textTransform": true,
308309
"writingMode": false

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.6-alpha-58313';
19+
$wp_version = '6.6-alpha-58314';
2020

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

0 commit comments

Comments
 (0)