mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
Fluid typography: allow individual preset overrides
In theme.json, individual font sizes may opt out of fluid typography if it is turned on globally. This commit ensures that individual font size presets can also opt in to fluid typography if it is not turned on globally. Props aaronrobertshaw, mmaattiiaass, ramonopoly, wildworks. Fixes #61932. Built from https://develop.svn.wordpress.org/trunk@58950 git-svn-id: http://core.svn.wordpress.org/trunk@58346 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4d0a623d7a
commit
06e50d2cbb
@ -518,6 +518,7 @@ function wp_get_computed_fluid_typography_value( $args = array() ) {
|
|||||||
* @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.
|
* @since 6.6.0 Deprecated bool argument $should_use_fluid_typography.
|
||||||
|
* @since 6.7.0 Font size presets can enable fluid typography individually, even if it’s disabled globally.
|
||||||
*
|
*
|
||||||
* @param array $preset {
|
* @param array $preset {
|
||||||
* Required. fontSizes preset value as seen in theme.json.
|
* Required. fontSizes preset value as seen in theme.json.
|
||||||
@ -538,10 +539,11 @@ function wp_get_typography_font_size_value( $preset, $settings = array() ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Catches empty values and 0/'0'.
|
* Catches falsy values and 0/'0'. Fluid calculations cannot be performed on `0`.
|
||||||
* Fluid calculations cannot be performed on 0.
|
* Also returns early when a preset font size explicitly disables fluid typography with `false`.
|
||||||
*/
|
*/
|
||||||
if ( empty( $preset['size'] ) ) {
|
$fluid_font_size_settings = $preset['fluid'] ?? null;
|
||||||
|
if ( false === $fluid_font_size_settings || empty( $preset['size'] ) ) {
|
||||||
return $preset['size'];
|
return $preset['size'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,15 +566,20 @@ function wp_get_typography_font_size_value( $preset, $settings = array() ) {
|
|||||||
$global_settings
|
$global_settings
|
||||||
);
|
);
|
||||||
|
|
||||||
$typography_settings = isset( $settings['typography'] ) ? $settings['typography'] : array();
|
$typography_settings = $settings['typography'] ?? array();
|
||||||
$should_use_fluid_typography = ! empty( $typography_settings['fluid'] );
|
|
||||||
|
|
||||||
if ( ! $should_use_fluid_typography ) {
|
/*
|
||||||
|
* 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'];
|
return $preset['size'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// $typography_settings['fluid'] can be a bool or an array. Normalize to array.
|
$fluid_settings = isset( $typography_settings['fluid'] ) ? $typography_settings['fluid'] : array();
|
||||||
$fluid_settings = is_array( $typography_settings['fluid'] ) ? $typography_settings['fluid'] : array();
|
|
||||||
$layout_settings = isset( $settings['layout'] ) ? $settings['layout'] : array();
|
$layout_settings = isset( $settings['layout'] ) ? $settings['layout'] : array();
|
||||||
|
|
||||||
// Defaults.
|
// Defaults.
|
||||||
@ -592,14 +599,6 @@ function wp_get_typography_font_size_value( $preset, $settings = array() ) {
|
|||||||
$has_min_font_size = isset( $fluid_settings['minFontSize'] ) && ! empty( wp_get_typography_value_and_unit( $fluid_settings['minFontSize'] ) );
|
$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;
|
$minimum_font_size_limit = $has_min_font_size ? $fluid_settings['minFontSize'] : $default_minimum_font_size_limit;
|
||||||
|
|
||||||
// Font sizes.
|
|
||||||
$fluid_font_size_settings = isset( $preset['fluid'] ) ? $preset['fluid'] : null;
|
|
||||||
|
|
||||||
// A font size has explicitly bypassed fluid calculations.
|
|
||||||
if ( false === $fluid_font_size_settings ) {
|
|
||||||
return $preset['size'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to grab explicit min and max fluid font sizes.
|
// Try to grab explicit min and max fluid font sizes.
|
||||||
$minimum_font_size_raw = isset( $fluid_font_size_settings['min'] ) ? $fluid_font_size_settings['min'] : null;
|
$minimum_font_size_raw = isset( $fluid_font_size_settings['min'] ) ? $fluid_font_size_settings['min'] : null;
|
||||||
$maximum_font_size_raw = isset( $fluid_font_size_settings['max'] ) ? $fluid_font_size_settings['max'] : null;
|
$maximum_font_size_raw = isset( $fluid_font_size_settings['max'] ) ? $fluid_font_size_settings['max'] : null;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.7-alpha-58949';
|
$wp_version = '6.7-alpha-58950';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
Loading…
Reference in New Issue
Block a user