wp_get_computed_fluid_typography_value( array $args = array() ): string|null
- Since
- 6.1.0, 6.3.0, 6.5.0
- Source
wp-includes/block-supports/typography.php:464
Compatibility
- WordPress
- since 6.5.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
$argsarrayoptional- An associative array of values to calculate a fluid formula for font size. Default is empty array.Default:
array()$maximum_viewport_widthstringMaximum size up to which type will have fluidity.$minimum_viewport_widthstringMinimum viewport size from which type will have fluidity.$maximum_font_sizestringMaximum font size for any clamp() calculation.$minimum_font_sizestringMinimum font size for any clamp() calculation.$scale_factorintA scale factor to determine how fast a font scales within boundaries.
Return value
string|null- A font-size value using clamp() on success, otherwise null.
Performance profile
How much work a call to wp_get_computed_fluid_typography_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
- Trivial
- Scaling
- Constant
- Instructions
- 31–98
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 102.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_computed_fluid_typography_value() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 31–38 | wp_get_typography_value_and_unit(), coerce_to() |
| always | 50–62 | wp_get_typography_value_and_unit(), coerce_to(), wp_get_typography_value_and_unit(), coerce_to(), coerce_to() |
!empty($linear_factor_denominator) | 91–98 | wp_get_typography_value_and_unit(), coerce_to(), wp_get_typography_value_and_unit(), coerce_to(), coerce_to(), round(), round() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 102 | 31–98 | 12 | |
| 8.5 | 102 | 31–98 | 12 | |
| 8.4 | 102 | 31–98 | 12 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 105 | 31–101 | 12 | |
| 8.2 | 105 | 31–101 | 12 | |
| 8.1 | 105 | 31–101 | 12 | |
| 7.4 | 105 | 31–101 | 12 |
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 · 1
- wp_get_typography_value_and_unit()Checks a string for a unit and value and returns an array consisting of `'value'` and `'unit'`, e.g. array( '42', 'rem' ).
Used by · 1
- wp_get_typography_font_size_value()Returns a font-size value based on a given font-size preset.
Source code
function wp_get_computed_fluid_typography_value( $args = array() ) { $maximum_viewport_width_raw = $args['maximum_viewport_width'] ?? null; $minimum_viewport_width_raw = $args['minimum_viewport_width'] ?? null; $maximum_font_size_raw = $args['maximum_font_size'] ?? null; $minimum_font_size_raw = $args['minimum_font_size'] ?? null; $scale_factor = $args['scale_factor'] ?? null; // Normalizes the minimum font size in order to use the value for calculations. $minimum_font_size = wp_get_typography_value_and_unit( $minimum_font_size_raw ); /* * We get a 'preferred' unit to keep units consistent when calculating, * otherwise the result will not be accurate. */ $font_size_unit = $minimum_font_size['unit'] ?? 'rem'; // Normalizes the maximum font size in order to use the value for calculations. $maximum_font_size = wp_get_typography_value_and_unit( $maximum_font_size_raw, array( 'coerce_to' => $font_size_unit, ) ); // Checks for mandatory min and max sizes, and protects against unsupported units. if ( ! $maximum_font_size || ! $minimum_font_size ) { return null; } // Uses rem for accessible fluid target font scaling. $minimum_font_size_rem = wp_get_typography_value_and_unit( $minimum_font_size_raw, array( 'coerce_to' => 'rem', ) ); // Viewport widths defined for fluid typography. Normalize units. $maximum_viewport_width = wp_get_typography_value_and_unit( $maximum_viewport_width_raw, array( 'coerce_to' => $font_size_unit, ) ); $minimum_viewport_width = wp_get_typography_value_and_unit( $minimum_viewport_width_raw, array( 'coerce_to' => $font_size_unit, ) ); // Protects against unsupported units in min and max viewport widths. if ( ! $minimum_viewport_width || ! $maximum_viewport_width ) { return null; } // Calculates the linear factor denominator. If it's 0, we cannot calculate a fluid value. $linear_factor_denominator = $maximum_viewport_width['value'] - $minimum_viewport_width['value']; if ( empty( $linear_factor_denominator ) ) { return null; } /* * Build CSS rule. * Borrowed from https://websemantics.uk/tools/responsive-font-calculator/. */ $view_port_width_offset = round( $minimum_viewport_width['value'] / 100, 3 ) . $font_size_unit; $linear_factor = 100 * ( ( $maximum_font_size['value'] - $minimum_font_size['value'] ) / ( $linear_factor_denominator ) ); $linear_factor_scaled = round( $linear_factor * $scale_factor, 3 ); $linear_factor_scaled = empty( $linear_factor_scaled ) ? 1 : $linear_factor_scaled; $fluid_target_font_size = implode( '', $minimum_font_size_rem ) . " + ((1vw - $view_port_width_offset) * $linear_factor_scaled)"; return "clamp($minimum_font_size_raw, $fluid_target_font_size, $maximum_font_size_raw)";}Changelog
Introduced in 6.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
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.