diff --git a/lib/blocks.php b/lib/blocks.php index b9bf822ea318d9..737ecae100a8bd 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -237,12 +237,14 @@ function gutenberg_experimental_apply_classnames_and_styles( $block_content, $bl if ( ! $block_type || ! $block_type->render_callback ) { return $block_content; } + // Check what style features the block supports. $supports = gutenberg_experimental_global_styles_get_supported_styles( $block_type->supports ); $attributes = array(); $attributes = gutenberg_experimental_build_css_colors( $attributes, $block['attrs'], $supports ); $attributes = gutenberg_experimental_build_css_typography( $attributes, $block['attrs'], $supports ); + $attributes = gutenberg_build_css_block_alignment( $attributes, $block['attrs'], $supports ); if ( ! count( $attributes ) ) { return $block_content; @@ -290,8 +292,8 @@ function gutenberg_experimental_apply_classnames_and_styles( $block_content, $bl add_filter( 'render_block', 'gutenberg_experimental_apply_classnames_and_styles', 10, 2 ); /** - * Build an array with CSS classes and inline styles defining the colors - * which will be applied to the block markup in the front-end. + * Add CSS classes and inline styles for colors to the incoming attributes array. + * This will be applied to the block markup in the front-end. * * @param array $attributes comprehensive list of attributes to be applied. * @param array $block_attributes block attributes. @@ -372,8 +374,8 @@ function gutenberg_experimental_build_css_colors( $attributes, $block_attributes } /** - * Build an array with CSS classes and inline styles defining the font sizes - * which will be applied to the block markup in the front-end. + * Add CSS classes and inline styles for font sizes to the incoming attributes array. + * This will be applied to the block markup in the front-end. * * @param array $attributes comprehensive list of attributes to be applied. * @param array $block_attributes block attributes. @@ -405,3 +407,24 @@ function gutenberg_experimental_build_css_typography( $attributes, $block_attrib return $attributes; } + +/** + * Add CSS classes for block alignment to the incoming attributes array. + * This will be applied to the block markup in the front-end. + * + * @param array $attributes comprehensive list of attributes to be applied. + * @param array $block_attributes block attributes. + * @param array $supports style features the block attributes. + * @return array Block alignment CSS classes and inline styles. + */ +function gutenberg_build_css_block_alignment( $attributes, $block_attributes, $supports ) { + if ( in_array( 'block-align', $supports, true ) ) { + $has_block_alignment = array_key_exists( 'align', $block_attributes ); + + if ( $has_block_alignment ) { + $attributes['css_classes'][] = sprintf( 'align%s', $block_attributes['align'] ); + } + } + + return $attributes; +} diff --git a/lib/global-styles.php b/lib/global-styles.php index 0971f3d8538687..2c3eddda4eb1b0 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -276,6 +276,7 @@ function gutenberg_experimental_global_styles_get_supported_styles( $supports ) 'link-color' => array( '__experimentalColor', 'linkColor' ), 'line-height' => array( '__experimentalLineHeight' ), 'font-size' => array( '__experimentalFontSize' ), + 'block-align' => array( 'align' ), ); $supported_features = array(); diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index de8de1212ca1fe..82ba837fc4594e 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -63,7 +63,7 @@ function render_block_core_template_part( $attributes ) { } $content = do_shortcode( $content ); - return str_replace( ']]>', ']]>', $content ); + return '