Editor: pass fluid typography theme.json settings to wp_get_typography_font_size_value.

Updates `wp_get_typography_font_size_value` to accept an array of theme.json settings instead of a boolean derived from global state.

Props ramonopoly, audrasjb.
Fixes #61118.

Built from https://develop.svn.wordpress.org/trunk@58171


git-svn-id: http://core.svn.wordpress.org/trunk@57634 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
isabel_brison 2024-05-18 23:18:15 +00:00
parent ab8cc6dce3
commit ff2929bf19
3 changed files with 36 additions and 20 deletions

View File

@ -498,19 +498,22 @@ function wp_get_computed_fluid_typography_value( $args = array() ) {
* @since 6.2.0 Added 'settings.typography.fluid.minFontSize' support. * @since 6.2.0 Added 'settings.typography.fluid.minFontSize' support.
* @since 6.3.0 Using layout.wideSize as max viewport width, and logarithmic scale factor to calculate minimum font scale. * @since 6.3.0 Using layout.wideSize as max viewport width, and logarithmic scale factor to calculate minimum font scale.
* @since 6.4.0 Added configurable min and max viewport width values to the typography.fluid theme.json schema. * @since 6.4.0 Added configurable min and max viewport width values to the typography.fluid theme.json schema.
* @since 6.6.0 Deprecated bool argument $should_use_fluid_typography.
* *
* @param array $preset { * @param array $preset {
* Required. fontSizes preset value as seen in theme.json. * Required. fontSizes preset value as seen in theme.json.
* *
* @type string $name Name of the font size preset. * @type string $name Name of the font size preset.
* @type string $slug Kebab-case, unique identifier for the font size preset. * @type string $slug Kebab-case, unique identifier for the font size preset.
* @type string|int|float $size CSS font-size value, including units if applicable. * @type string|int|float $size CSS font-size value, including units if applicable.
* } * }
* @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing. * @param bool|array $settings Optional Theme JSON settings array that overrides any global theme settings.
* Default is false. * Default is false.
* @return string|null Font-size value or null if a size is not passed in $preset. * @return string|null Font-size value or null if a size is not passed in $preset.
*/ */
function wp_get_typography_font_size_value( $preset, $should_use_fluid_typography = false ) {
function wp_get_typography_font_size_value( $preset, $settings = array() ) {
if ( ! isset( $preset['size'] ) ) { if ( ! isset( $preset['size'] ) ) {
return null; return null;
} }
@ -523,25 +526,35 @@ function wp_get_typography_font_size_value( $preset, $should_use_fluid_typograph
return $preset['size']; return $preset['size'];
} }
// Checks if fluid font sizes are activated. /*
$global_settings = wp_get_global_settings(); * As a boolean (deprecated since 6.6), $settings acts as an override to switch fluid typography "on" (`true`) or "off" (`false`).
$typography_settings = isset( $global_settings['typography'] ) ? $global_settings['typography'] : array(); */
$layout_settings = isset( $global_settings['layout'] ) ? $global_settings['layout'] : array(); if ( is_bool( $settings ) ) {
_deprecated_argument( __FUNCTION__, '6.6.0', __( '`boolean` type for second argument `$settings` is deprecated. Use `array()` instead.' ) );
if ( $settings = array(
isset( $typography_settings['fluid'] ) && 'typography' => array(
( true === $typography_settings['fluid'] || is_array( $typography_settings['fluid'] ) ) 'fluid' => $settings,
) { ),
$should_use_fluid_typography = true; );
} }
// Fallback to global settings as default.
$global_settings = wp_get_global_settings();
$settings = wp_parse_args(
$settings,
$global_settings
);
$typography_settings = isset( $settings['typography'] ) ? $settings['typography'] : array();
$should_use_fluid_typography = ! empty( $typography_settings['fluid'] );
if ( ! $should_use_fluid_typography ) { if ( ! $should_use_fluid_typography ) {
return $preset['size']; return $preset['size'];
} }
$fluid_settings = isset( $typography_settings['fluid'] ) && is_array( $typography_settings['fluid'] ) // $typography_settings['fluid'] can be a bool or an array. Normalize to array.
? $typography_settings['fluid'] $fluid_settings = is_array( $typography_settings['fluid'] ) ? $typography_settings['fluid'] : array();
: array(); $layout_settings = isset( $settings['layout'] ) ? $settings['layout'] : array();
// Defaults. // Defaults.
$default_maximum_viewport_width = '1600px'; $default_maximum_viewport_width = '1600px';

View File

@ -1831,6 +1831,7 @@ class WP_Theme_JSON {
* </code> * </code>
* *
* @since 5.9.0 * @since 5.9.0
* @since 6.6.0 Passing $settings to the callbacks defined in static::PRESETS_METADATA.
* *
* @param array $settings Settings to process. * @param array $settings Settings to process.
* @param array $preset_metadata One of the PRESETS_METADATA values. * @param array $preset_metadata One of the PRESETS_METADATA values.
@ -1857,7 +1858,7 @@ class WP_Theme_JSON {
is_callable( $preset_metadata['value_func'] ) is_callable( $preset_metadata['value_func'] )
) { ) {
$value_func = $preset_metadata['value_func']; $value_func = $preset_metadata['value_func'];
$value = call_user_func( $value_func, $preset ); $value = call_user_func( $value_func, $preset, $settings );
} else { } else {
// If we don't have a value, then don't add it to the result. // If we don't have a value, then don't add it to the result.
continue; continue;
@ -2050,6 +2051,7 @@ class WP_Theme_JSON {
* @since 5.9.0 Added the `$settings` and `$properties` parameters. * @since 5.9.0 Added the `$settings` and `$properties` parameters.
* @since 6.1.0 Added `$theme_json`, `$selector`, and `$use_root_padding` parameters. * @since 6.1.0 Added `$theme_json`, `$selector`, and `$use_root_padding` parameters.
* @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set. * @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set.
* @since 6.6.0 Passing current theme JSON settings to wp_get_typography_font_size_value().
* *
* @param array $styles Styles to process. * @param array $styles Styles to process.
* @param array $settings Theme settings. * @param array $settings Theme settings.
@ -2117,8 +2119,9 @@ class WP_Theme_JSON {
* whether the incoming value can be converted to a fluid value. * whether the incoming value can be converted to a fluid value.
* Values that already have a clamp() function will not pass the test, * Values that already have a clamp() function will not pass the test,
* and therefore the original $value will be returned. * and therefore the original $value will be returned.
* Pass the current theme_json settings to override any global settings.
*/ */
$value = wp_get_typography_font_size_value( array( 'size' => $value ) ); $value = wp_get_typography_font_size_value( array( 'size' => $value ), $settings );
} }
if ( 'aspect-ratio' === $css_property ) { if ( 'aspect-ratio' === $css_property ) {

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.6-alpha-58170'; $wp_version = '6.6-alpha-58171';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.