Make WordPress Core

Changeset 55133


Ignore:
Timestamp:
01/24/2023 08:38:25 PM (15 months ago)
Author:
hellofromTonya
Message:

Editor: Adds 'settings.typography.fluid.minFontSize' support to wp_get_typography_font_size_value().

In wp_get_typography_font_size_value(), adds support for using a minimum font size for fluid typography when defined in a theme's theme.json file.

Reference:

Follow-up to [54497], [54260].

Props andrewserong, ramonopoly, hellofromTonya, joen.
Fixes #57529.

Location:
trunk
Files:
3 added
3 edited

Legend:

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

    r54823 r55133  
    454454 * @since 6.1.0
    455455 * @since 6.1.1 Adjusted rules for min and max font sizes.
     456 * @since 6.2.0 Added 'settings.typography.fluid.minFontSize' support.
    456457 *
    457458 * @param array $preset                     {
     
    480481
    481482    // Checks if fluid font sizes are activated.
    482     $typography_settings         = wp_get_global_settings( array( 'typography' ) );
    483     $should_use_fluid_typography = isset( $typography_settings['fluid'] ) && true === $typography_settings['fluid'] ? true : $should_use_fluid_typography;
     483    $typography_settings = wp_get_global_settings( array( 'typography' ) );
     484    if (
     485        isset( $typography_settings['fluid'] ) &&
     486        ( true === $typography_settings['fluid'] || is_array( $typography_settings['fluid'] ) )
     487    ) {
     488        $should_use_fluid_typography = true;
     489    }
    484490
    485491    if ( ! $should_use_fluid_typography ) {
    486492        return $preset['size'];
    487493    }
     494
     495    $fluid_settings = isset( $typography_settings['fluid'] ) && is_array( $typography_settings['fluid'] )
     496        ? $typography_settings['fluid']
     497        : array();
    488498
    489499    // Defaults.
     
    492502    $default_minimum_font_size_factor = 0.75;
    493503    $default_scale_factor             = 1;
    494     $default_minimum_font_size_limit  = '14px';
     504    $has_min_font_size                = isset( $fluid_settings['minFontSize'] ) && ! empty( wp_get_typography_value_and_unit( $fluid_settings['minFontSize'] ) );
     505    $default_minimum_font_size_limit  = $has_min_font_size ? $fluid_settings['minFontSize'] : '14px';
    495506
    496507    // Font sizes.
  • trunk/tests/phpunit/tests/block-supports/typography.php

    r54889 r55133  
    568568     * @ticket 56467
    569569     * @ticket 57065
     570     * @ticket 57529
    570571     *
    571572     * @covers ::wp_register_typography_support
     
    573574     * @dataProvider data_generate_block_supports_font_size_fixtures
    574575     *
    575      * @param string $font_size_value             The block supports custom font size value.
    576      * @param bool   $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
    577      * @param string $expected_output             Expected value of style property from wp_apply_typography_support().
    578      */
    579     public function test_should_covert_font_sizes_to_fluid_values( $font_size_value, $should_use_fluid_typography, $expected_output ) {
    580         if ( $should_use_fluid_typography ) {
    581             switch_theme( 'block-theme-child-with-fluid-typography' );
    582         } else {
    583             switch_theme( 'default' );
    584         }
     576     * @param string $font_size_value The block supports custom font size value.
     577     * @param string $theme_slug      A theme slug corresponding to an available test theme.
     578     * @param string $expected_output Expected value of style property from wp_apply_typography_support().
     579     */
     580    public function test_should_covert_font_sizes_to_fluid_values( $font_size_value, $theme_slug, $expected_output ) {
     581        switch_theme( $theme_slug );
    585582
    586583        $this->test_block_name = 'test/font-size-fluid-value';
     
    624621    public function data_generate_block_supports_font_size_fixtures() {
    625622        return array(
    626             'default_return_value'               => array(
    627                 'font_size_value'             => '50px',
    628                 'should_use_fluid_typography' => false,
    629                 'expected_output'             => 'font-size:50px;',
    630             ),
    631             'return_value_with_fluid_typography' => array(
    632                 'font_size_value'             => '50px',
    633                 'should_use_fluid_typography' => true,
    634                 'expected_output'             => 'font-size:clamp(37.5px, 2.344rem + ((1vw - 7.68px) * 1.502), 50px);',
     623            'returns value when fluid typography is not active' => array(
     624                'font_size_value' => '15px',
     625                'theme_slug'      => 'default',
     626                'expected_output' => 'font-size:15px;',
     627            ),
     628            'returns clamp value using default config' => array(
     629                'font_size_value' => '15px',
     630                'theme_slug'      => 'block-theme-child-with-fluid-typography',
     631                'expected_output' => 'font-size:clamp(14px, 0.875rem + ((1vw - 7.68px) * 0.12), 15px);',
     632            ),
     633            'returns value when font size <= default min font size bound' => array(
     634                'font_size_value' => '13px',
     635                'theme_slug'      => 'block-theme-child-with-fluid-typography',
     636                'expected_output' => 'font-size:13px;',
     637            ),
     638            'returns clamp value using custom fluid config' => array(
     639                'font_size_value' => '17px',
     640                'theme_slug'      => 'block-theme-child-with-fluid-typography-config',
     641                'expected_output' => 'font-size:clamp(16px, 1rem + ((1vw - 7.68px) * 0.12), 17px);',
     642            ),
     643            'returns value when font size <= custom min font size bound' => array(
     644                'font_size_value' => '15px',
     645                'theme_slug'      => 'block-theme-child-with-fluid-typography-config',
     646                'expected_output' => 'font-size:15px;',
    635647            ),
    636648        );
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r55086 r55133  
    181181            'Block Theme Child with no theme.json',
    182182            'Block Theme Child Theme With Fluid Typography',
     183            'Block Theme Child Theme With Fluid Typography Config',
    183184            'Block Theme [0.4.0]',
    184185            'Block Theme [1.0.0] in subdirectory',
Note: See TracChangeset for help on using the changeset viewer.