From 0b40c80d0d650dbdf342ba5fff28b1e5f99e3a58 Mon Sep 17 00:00:00 2001 From: Isabel Brison Date: Fri, 1 Sep 2023 04:01:23 +0000 Subject: [PATCH] Editor: Don't use fluid layout value in typography. Changes fluid typography calculation to use fallback value if layout wide size is a fluid value. Props ramonopoly, mukesh27, jastos, aurooba. See #58754. git-svn-id: https://develop.svn.wordpress.org/trunk@56503 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/block-supports/typography.php | 2 +- .../block-theme-child-with-fluid-layout/style.css | 8 ++++++++ .../block-theme-child-with-fluid-layout/theme.json | 12 ++++++++++++ tests/phpunit/tests/block-supports/typography.php | 5 +++++ tests/phpunit/tests/theme/themeDir.php | 1 + 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/data/themedir1/block-theme-child-with-fluid-layout/style.css create mode 100644 tests/phpunit/data/themedir1/block-theme-child-with-fluid-layout/theme.json diff --git a/src/wp-includes/block-supports/typography.php b/src/wp-includes/block-supports/typography.php index 78c8b0a2ff..34345ca4ec 100644 --- a/src/wp-includes/block-supports/typography.php +++ b/src/wp-includes/block-supports/typography.php @@ -517,7 +517,7 @@ function wp_get_typography_font_size_value( $preset, $should_use_fluid_typograph : array(); // Defaults. - $default_maximum_viewport_width = isset( $layout_settings['wideSize'] ) ? $layout_settings['wideSize'] : '1600px'; + $default_maximum_viewport_width = isset( $layout_settings['wideSize'] ) && ! empty( wp_get_typography_value_and_unit( $layout_settings['wideSize'] ) ) ? $layout_settings['wideSize'] : '1600px'; $default_minimum_viewport_width = '320px'; $default_minimum_font_size_factor_max = 0.75; $default_minimum_font_size_factor_min = 0.25; diff --git a/tests/phpunit/data/themedir1/block-theme-child-with-fluid-layout/style.css b/tests/phpunit/data/themedir1/block-theme-child-with-fluid-layout/style.css new file mode 100644 index 0000000000..193b8f098a --- /dev/null +++ b/tests/phpunit/data/themedir1/block-theme-child-with-fluid-layout/style.css @@ -0,0 +1,8 @@ +/* +Theme Name: Block Theme Child Theme With Fluid Layout +Theme URI: https://wordpress.org/ +Description: For testing purposes only. +Template: block-theme +Version: 1.0.0 +Text Domain: block-theme-child-with-fluid-layout +*/ diff --git a/tests/phpunit/data/themedir1/block-theme-child-with-fluid-layout/theme.json b/tests/phpunit/data/themedir1/block-theme-child-with-fluid-layout/theme.json new file mode 100644 index 0000000000..6985da16c6 --- /dev/null +++ b/tests/phpunit/data/themedir1/block-theme-child-with-fluid-layout/theme.json @@ -0,0 +1,12 @@ +{ + "version": 2, + "settings": { + "appearanceTools": true, + "layout": { + "wideSize": "clamp(1000px, 85vw, 2000px)" + }, + "typography": { + "fluid": true + } + } +} diff --git a/tests/phpunit/tests/block-supports/typography.php b/tests/phpunit/tests/block-supports/typography.php index 1b47ea379b..c9ed84fd12 100644 --- a/tests/phpunit/tests/block-supports/typography.php +++ b/tests/phpunit/tests/block-supports/typography.php @@ -699,6 +699,11 @@ class Tests_Block_Supports_Typography extends WP_UnitTestCase { 'theme_slug' => 'block-theme-child-with-fluid-typography-config', 'expected_output' => 'font-size:15px;', ), + 'returns clamp value using default config if layout is fluid' => array( + 'font_size_value' => '15px', + 'theme_slug' => 'block-theme-child-with-fluid-layout', + 'expected_output' => 'font-size:clamp(14px, 0.875rem + ((1vw - 3.2px) * 0.078), 15px);', + ), ); } diff --git a/tests/phpunit/tests/theme/themeDir.php b/tests/phpunit/tests/theme/themeDir.php index 73cf63539e..d12377c2d9 100644 --- a/tests/phpunit/tests/theme/themeDir.php +++ b/tests/phpunit/tests/theme/themeDir.php @@ -179,6 +179,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { 'Block Theme', 'Block Theme Child Theme', 'Block Theme Child with no theme.json', + 'Block Theme Child Theme With Fluid Layout', 'Block Theme Child Theme With Fluid Typography', 'Block Theme Child Theme With Fluid Typography Config', 'Block Theme Non Latin',