wp_register_typography_support()WP 5.6.0

Registers the style and typography block attributes for block types that support it.

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.

Returns

null. Nothing (null).

Usage

wp_register_typography_support( $block_type );
$block_type(WP_Block_Type) (required)
Block Type.

Changelog

Since 5.6.0 Introduced.
Since 6.3.0 Added support for text-columns.
Since 7.0.0 Added support for text-indent.

wp_register_typography_support() code WP 7.0

function wp_register_typography_support( $block_type ) {
	if ( ! ( $block_type instanceof WP_Block_Type ) ) {
		return;
	}

	$typography_supports = $block_type->supports['typography'] ?? false;
	if ( ! $typography_supports ) {
		return;
	}

	$has_font_family_support     = $typography_supports['__experimentalFontFamily'] ?? false;
	$has_font_size_support       = $typography_supports['fontSize'] ?? false;
	$has_font_style_support      = $typography_supports['__experimentalFontStyle'] ?? false;
	$has_font_weight_support     = $typography_supports['__experimentalFontWeight'] ?? false;
	$has_letter_spacing_support  = $typography_supports['__experimentalLetterSpacing'] ?? false;
	$has_line_height_support     = $typography_supports['lineHeight'] ?? false;
	$has_text_align_support      = $typography_supports['textAlign'] ?? false;
	$has_text_columns_support    = $typography_supports['textColumns'] ?? false;
	$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
	$has_text_transform_support  = $typography_supports['__experimentalTextTransform'] ?? false;
	$has_text_indent_support     = $typography_supports['textIndent'] ?? false;
	$has_writing_mode_support    = $typography_supports['__experimentalWritingMode'] ?? false;

	$has_typography_support = $has_font_family_support
		|| $has_font_size_support
		|| $has_font_style_support
		|| $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
		|| $has_text_indent_support
		|| $has_writing_mode_support;

	if ( ! $block_type->attributes ) {
		$block_type->attributes = array();
	}

	if ( $has_typography_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
		$block_type->attributes['style'] = array(
			'type' => 'object',
		);
	}

	if ( $has_font_size_support && ! array_key_exists( 'fontSize', $block_type->attributes ) ) {
		$block_type->attributes['fontSize'] = array(
			'type' => 'string',
		);
	}

	if ( $has_font_family_support && ! array_key_exists( 'fontFamily', $block_type->attributes ) ) {
		$block_type->attributes['fontFamily'] = array(
			'type' => 'string',
		);
	}
}