wp_apply_alignment_support()WP 5.6.0

Adds CSS classes for block alignment to the incoming attributes array. This will be applied to the block markup in the front-end.

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Return

Array. Block alignment CSS classes and inline styles.

Usage

wp_apply_alignment_support( $block_type, $block_attributes );
$block_type(WP_Block_Type) (required)
Block Type.
$block_attributes(array) (required)
Block attributes.

Changelog

Since 5.6.0 Introduced.

wp_apply_alignment_support() code WP 6.5.2

function wp_apply_alignment_support( $block_type, $block_attributes ) {
	$attributes        = array();
	$has_align_support = block_has_support( $block_type, 'align', false );
	if ( $has_align_support ) {
		$has_block_alignment = array_key_exists( 'align', $block_attributes );

		if ( $has_block_alignment ) {
			$attributes['class'] = sprintf( 'align%s', $block_attributes['align'] );
		}
	}

	return $attributes;
}