wppaste
WordPress

wp_get_typography_font_size_value( array $preset, bool|array $settings = array() ): string|null

Since
6.1.0, 6.1.1, 6.2.0, 6.3.0, 6.4.0, 6.6.0, 6.7.0
Source
wp-includes/block-supports/typography.php:565
Returns a font-size value based on a given font-size preset.

Description

Takes into account fluid typography parameters and attempts to return a CSS formula depending on available, valid values.

Compatibility

WordPress
since 6.7.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

$presetarray
Required. fontSizes preset value as seen in theme.json.
  • $namestring

    Name of the font size preset.
  • $slugstring

    Kebab-case, unique identifier for the font size preset.
  • $sizestring|int|float

    CSS font-size value, including units if applicable.
$settingsbool|arrayoptional
Optional Theme JSON settings array that overrides any global theme settings.
Default is false.Default: array()

Return value

string|null
Font-size value or null if a size is not passed in $preset.

Performance profile

How much work a call to wp_get_typography_font_size_value() 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
Light

Only touches the object cache, via wp_cache_get().

Scaling
Constant

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

Instructions
11–142

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
5

5 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()one call below wp_get_typography_font_size_value()
  • cacheobject cachewp_cache_get()one call below wp_get_typography_font_size_value()

Further down the call graph this can also reach query, option, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 9 distinct outcomes

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

WhenInstructionsCalls it makes
isset($preset) && !$preset && $fluid_font_size_settings === false11none
isset($preset) && !$preset && $fluid_font_size_settings !== false && !empty($preset) && !is_bool($settings) && !$settings && !empty($typography_settings) && !$typography_settings && !$fluid_settings && !isset($layout_settings) && !isset($fluid_settings) && empty($preferred_size)65–70wp_get_global_settings(), wp_parse_args(), wp_get_typography_value_and_unit()
isset($preset) && !$preset && $fluid_font_size_settings !== false && !empty($preset) && !is_bool($settings) && !$settings && !empty($typography_settings) && !$typography_settings && !$fluid_settings && empty($preferred_size)71–76wp_get_global_settings(), wp_parse_args(), wp_get_typography_value_and_unit(), wp_get_typography_value_and_unit()
isset($preset) && !$preset && $fluid_font_size_settings !== false && !empty($preset) && !is_bool($settings) && !$settings && !empty($typography_settings) && !$typography_settings && !$fluid_settings && !isset($layout_settings) && !isset($fluid_settings) && !empty($preferred_size) && !empty($minimum_font_size_limit)80–85wp_get_global_settings(), wp_parse_args(), wp_get_typography_value_and_unit(), coerce_to()
isset($preset) && !$preset && $fluid_font_size_settings !== false && !empty($preset) && !is_bool($settings) && !$settings && !empty($typography_settings) && !$typography_settings && !$fluid_settings && !isset($layout_settings) && !isset($fluid_settings) && !empty($preferred_size)86–102wp_get_global_settings(), wp_parse_args(), wp_get_typography_value_and_unit(), coerce_to(), minimum_viewport_width()
isset($preset) && !$preset && $fluid_font_size_settings !== false && !empty($preset) && !is_bool($settings) && !$settings && !empty($typography_settings) && !$typography_settings && !$fluid_settings && !empty($preferred_size) && !empty($minimum_font_size_limit)86–91wp_get_global_settings(), wp_parse_args(), wp_get_typography_value_and_unit(), wp_get_typography_value_and_unit(), coerce_to()
isset($preset) && !$preset && $fluid_font_size_settings !== false && !empty($preset) && !is_bool($settings) && !$settings && !empty($typography_settings) && !$typography_settings && !$fluid_settings && !empty($preferred_size)92–108wp_get_global_settings(), wp_parse_args(), wp_get_typography_value_and_unit(), wp_get_typography_value_and_unit(), coerce_to(), minimum_viewport_width()
isset($preset) && !$preset && $fluid_font_size_settings !== false && !empty($preset) && !is_bool($settings) && !$settings && !empty($typography_settings) && !$typography_settings && !$fluid_settings && !isset($layout_settings) && !isset($fluid_settings) && !empty($preferred_size)115–136wp_get_global_settings(), wp_parse_args(), wp_get_typography_value_and_unit(), coerce_to(), log(), clamp(), round(), minimum_viewport_width()
isset($preset) && !$preset && $fluid_font_size_settings !== false && !empty($preset) && !is_bool($settings) && !$settings && !empty($typography_settings) && !$typography_settings && !$fluid_settings && !empty($preferred_size)121–142wp_get_global_settings(), wp_parse_args(), wp_get_typography_value_and_unit(), wp_get_typography_value_and_unit(), coerce_to(), log(), clamp(), round(), minimum_viewport_width()

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-dev17711–136296 fewer instructions than PHP 8.5
8.518311–14229
8.418311–14229
8.318311–14229
8.218311–14229
8.118311–142294 fewer instructions than PHP 7.4
7.418711–14429

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 · 7

Used by · 5

Source code

function wp_get_typography_font_size_value( $preset, $settings = array() ) {	if ( ! isset( $preset['size'] ) ) {		return null;	} 	/*	 * Catches falsy values and 0/'0'. Fluid calculations cannot be performed on `0`.	 * Also returns early when a preset font size explicitly disables fluid typography with `false`.	 */	$fluid_font_size_settings = $preset['fluid'] ?? null;	if ( false === $fluid_font_size_settings || empty( $preset['size'] ) ) {		return $preset['size'];	} 	/*	 * As a boolean (deprecated since 6.6), $settings acts as an override to switch fluid typography "on" (`true`) or "off" (`false`).	 */	if ( is_bool( $settings ) ) {		_deprecated_argument( __FUNCTION__, '6.6.0', __( '`boolean` type for second argument `$settings` is deprecated. Use `array()` instead.' ) );		$settings = array(			'typography' => array(				'fluid' => $settings,			),		);	} 	// Fallback to global settings as default.	$global_settings = wp_get_global_settings();	$settings        = wp_parse_args(		$settings,		$global_settings	); 	$typography_settings = $settings['typography'] ?? array(); 	/*	 * Return early when fluid typography is disabled in the settings, and there	 * are no local settings to enable it for the individual preset.	 *	 * If this condition isn't met, either the settings or individual preset settings	 * have enabled fluid typography.	 */	if ( empty( $typography_settings['fluid'] ) && empty( $fluid_font_size_settings ) ) {		return $preset['size'];	} 	$fluid_settings  = $typography_settings['fluid'] ?? array();	$layout_settings = $settings['layout'] ?? array(); 	// Defaults.	$default_maximum_viewport_width       = '1600px';	$default_minimum_viewport_width       = '320px';	$default_minimum_font_size_factor_max = 0.75;	$default_minimum_font_size_factor_min = 0.25;	$default_scale_factor                 = 1;	$default_minimum_font_size_limit      = '14px'; 	// Defaults overrides.	$minimum_viewport_width = $fluid_settings['minViewportWidth'] ?? $default_minimum_viewport_width;	$maximum_viewport_width = isset( $layout_settings['wideSize'] ) && ! empty( wp_get_typography_value_and_unit( $layout_settings['wideSize'] ) ) ? $layout_settings['wideSize'] : $default_maximum_viewport_width;	if ( isset( $fluid_settings['maxViewportWidth'] ) ) {		$maximum_viewport_width = $fluid_settings['maxViewportWidth'];	}	$has_min_font_size       = isset( $fluid_settings['minFontSize'] ) && ! empty( wp_get_typography_value_and_unit( $fluid_settings['minFontSize'] ) );	$minimum_font_size_limit = $has_min_font_size ? $fluid_settings['minFontSize'] : $default_minimum_font_size_limit; 	// Try to grab explicit min and max fluid font sizes.	$minimum_font_size_raw = $fluid_font_size_settings['min'] ?? null;	$maximum_font_size_raw = $fluid_font_size_settings['max'] ?? null; 	// Font sizes.	$preferred_size = wp_get_typography_value_and_unit( $preset['size'] ); 	// Protects against unsupported units.	if ( empty( $preferred_size['unit'] ) ) {		return $preset['size'];	} 	/*	 * Normalizes the minimum font size limit according to the incoming unit,

Changelog

Introduced in 6.1.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.

6.7.0
Font size presets can enable fluid typography individually, even if it’s disabled globally.from the docblock
6.6.0
Deprecated bool argument $should_use_fluid_typography.from the docblock
6.4.0
Added configurable min and max viewport width values to the typography.fluid theme.json schema.from the docblock
6.3.0
Using layout.wideSize as max viewport width, and logarithmic scale factor to calculate minimum font scale.from the docblock
6.2.0
Added 'settings.typography.fluid.minFontSize' support.from the docblock
6.1.1
Adjusted rules for min and max font sizes.from the docblock
6.1.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.