Make WordPress Core


Ignore:
Timestamp:
05/18/2024 11:16:09 PM (11 months ago)
Author:
isabel_brison
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/typography.php

    r57329 r58171  
    499499 * @since 6.3.0 Using layout.wideSize as max viewport width, and logarithmic scale factor to calculate minimum font scale.
    500500 * @since 6.4.0 Added configurable min and max viewport width values to the typography.fluid theme.json schema.
    501  *
    502  * @param array $preset                     {
     501 * @since 6.6.0 Deprecated bool argument $should_use_fluid_typography.
     502 *
     503 * @param array      $preset   {
    503504 *     Required. fontSizes preset value as seen in theme.json.
    504505 *
     
    507508 *     @type string|int|float $size CSS font-size value, including units if applicable.
    508509 * }
    509  * @param bool  $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
    510  *                                           Default is false.
     510 * @param bool|array $settings Optional Theme JSON settings array that overrides any global theme settings.
     511 *                             Default is false.
    511512 * @return string|null Font-size value or null if a size is not passed in $preset.
    512513 */
    513 function wp_get_typography_font_size_value( $preset, $should_use_fluid_typography = false ) {
     514
     515
     516function wp_get_typography_font_size_value( $preset, $settings = array() ) {
    514517    if ( ! isset( $preset['size'] ) ) {
    515518        return null;
     
    524527    }
    525528
    526     // Checks if fluid font sizes are activated.
    527     $global_settings     = wp_get_global_settings();
    528     $typography_settings = isset( $global_settings['typography'] ) ? $global_settings['typography'] : array();
    529     $layout_settings     = isset( $global_settings['layout'] ) ? $global_settings['layout'] : array();
    530 
    531     if (
    532         isset( $typography_settings['fluid'] ) &&
    533         ( true === $typography_settings['fluid'] || is_array( $typography_settings['fluid'] ) )
    534     ) {
    535         $should_use_fluid_typography = true;
    536     }
     529    /*
     530     * As a boolean (deprecated since 6.6), $settings acts as an override to switch fluid typography "on" (`true`) or "off" (`false`).
     531     */
     532    if ( is_bool( $settings ) ) {
     533        _deprecated_argument( __FUNCTION__, '6.6.0', __( '`boolean` type for second argument `$settings` is deprecated. Use `array()` instead.' ) );
     534        $settings = array(
     535            'typography' => array(
     536                'fluid' => $settings,
     537            ),
     538        );
     539    }
     540
     541    // Fallback to global settings as default.
     542    $global_settings             = wp_get_global_settings();
     543    $settings                    = wp_parse_args(
     544        $settings,
     545        $global_settings
     546    );
     547
     548    $typography_settings         = isset( $settings['typography'] ) ? $settings['typography'] : array();
     549    $should_use_fluid_typography = ! empty( $typography_settings['fluid'] );
    537550
    538551    if ( ! $should_use_fluid_typography ) {
     
    540553    }
    541554
    542     $fluid_settings = isset( $typography_settings['fluid'] ) && is_array( $typography_settings['fluid'] )
    543         ? $typography_settings['fluid']
    544         : array();
     555    // $typography_settings['fluid'] can be a bool or an array. Normalize to array.
     556    $fluid_settings  = is_array( $typography_settings['fluid'] ) ? $typography_settings['fluid'] : array();
     557    $layout_settings = isset( $settings['layout'] ) ? $settings['layout'] : array();
    545558
    546559    // Defaults.
Note: See TracChangeset for help on using the changeset viewer.