diff --git a/src/wp-includes/fonts/class-wp-font-face.php b/src/wp-includes/fonts/class-wp-font-face.php index 193a5d0951ddb..c8d081b9557b5 100644 --- a/src/wp-includes/fonts/class-wp-font-face.php +++ b/src/wp-includes/fonts/class-wp-font-face.php @@ -363,17 +363,18 @@ private function compile_src( array $value ) { * Compiles the font variation settings. * * @since 6.4.0 + * @since 7.2.0 Quotes each axis tag and separates the axes with commas. * - * @param array $font_variation_settings Array of font variation settings. + * @param array $font_variation_settings Array of font variation settings, keyed by axis tag. * @return string The CSS. */ private function compile_variations( array $font_variation_settings ) { - $variations = ''; + $variations = array(); - foreach ( $font_variation_settings as $key => $value ) { - $variations .= "$key $value"; + foreach ( $font_variation_settings as $tag => $value ) { + $variations[] = sprintf( '"%s" %s', $tag, $value ); } - return $variations; + return implode( ', ', $variations ); } } diff --git a/tests/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php b/tests/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php index c0d7f9e328016..b9e723a06f442 100644 --- a/tests/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php +++ b/tests/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php @@ -239,6 +239,51 @@ public function data_should_print_given_fonts() { , ), ), + 'variation settings string' => array( + 'fonts' => array( + 'Inter' => + array( + array( + 'src' => + array( + 'https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf', + ), + 'font-family' => 'Inter', + 'font-style' => 'normal', + 'font-weight' => '400', + 'font-variation-settings' => '"slnt" 0, "wght" 400', + ), + ), + ), + 'expected' => << array( + 'fonts' => array( + 'Inter' => + array( + array( + 'src' => + array( + 'https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf', + ), + 'font-family' => 'Inter', + 'font-style' => 'normal', + 'font-weight' => '400', + 'font-variation-settings' => array( + 'slnt' => 0, + 'wght' => 400, + ), + ), + ), + ), + 'expected' => <<