wppaste
WordPress

wp_apply_typography_support( WP_Block_Type $block_type, array $block_attributes ): array

Since
5.6.0, 6.1.0, 6.3.0, 7.0.0
Source
wp-includes/block-supports/typography.php:93
Adds CSS classes and inline styles for typography features such as font sizes to the incoming attributes array. This will be applied to the block markup in the front-end.

Compatibility

WordPress
since 7.0.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$block_typeWP_Block_Type
Block type.
$block_attributesarray
Block attributes.

Return value

array
Typography CSS classes and inline styles.

Performance profile

How much work a call to wp_apply_typography_support() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
151–210

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 368.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_apply_typography_support() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$block_type instanceof && !wp_should_skip_block_supports_serialization() && !$typography_supports151–200wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), typography()
$block_type instanceof && !wp_should_skip_block_supports_serialization() && !$typography_supports && isset($value)166–210wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), wp_typography_get_preset_inline_style_value(), typography()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev366151–210652 fewer instructions than PHP 8.5
8.5368151–21065
8.4368151–210653 fewer instructions than PHP 8.3
8.3371151–21365
8.2371151–21365
8.1371151–213652 fewer instructions than PHP 7.4
7.4373151–21365

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 4

Source code

function wp_apply_typography_support( $block_type, $block_attributes ) {	if ( ! ( $block_type instanceof WP_Block_Type ) ) {		return array();	} 	$typography_supports = $block_type->supports['typography'] ?? false;	if ( ! $typography_supports ) {		return array();	} 	if ( wp_should_skip_block_supports_serialization( $block_type, 'typography' ) ) {		return array();	} 	$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; 	// Whether to skip individual block support features.	$should_skip_font_size       = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontSize' );	$should_skip_font_family     = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontFamily' );	$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' );	$should_skip_letter_spacing  = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' );	$should_skip_text_indent     = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textIndent' );	$should_skip_writing_mode    = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'writingMode' ); 	$typography_block_styles = array();	if ( $has_font_size_support && ! $should_skip_font_size ) {		$preset_font_size                    = array_key_exists( 'fontSize', $block_attributes )			? "var:preset|font-size|{$block_attributes['fontSize']}"			: null;		$custom_font_size                    = $block_attributes['style']['typography']['fontSize'] ?? null;		$typography_block_styles['fontSize'] = $preset_font_size ? $preset_font_size : wp_get_typography_font_size_value(			array(				'size' => $custom_font_size,			)		);	} 	if ( $has_font_family_support && ! $should_skip_font_family ) {		$preset_font_family                    = array_key_exists( 'fontFamily', $block_attributes )			? "var:preset|font-family|{$block_attributes['fontFamily']}"			: null;		$custom_font_family                    = isset( $block_attributes['style']['typography']['fontFamily'] )			? wp_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['fontFamily'], 'font-family' )			: null;		$typography_block_styles['fontFamily'] = $preset_font_family ? $preset_font_family : $custom_font_family;	} 	if (		$has_font_style_support &&		! $should_skip_font_style &&		isset( $block_attributes['style']['typography']['fontStyle'] )	) {		$typography_block_styles['fontStyle'] = wp_typography_get_preset_inline_style_value(			$block_attributes['style']['typography']['fontStyle'],			'font-style'		);	} 	if (		$has_font_weight_support &&		! $should_skip_font_weight &&		isset( $block_attributes['style']['typography']['fontWeight'] )	) {

Changelog

Introduced in 5.6.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.0.0
Added support for text-indent.from the docblock
6.3.0
Added support for text-columns.from the docblock
6.1.0
Used the style engine to generate CSS and classnames.from the docblock
5.6.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/block-supports/typography.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.