Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/wp-includes/fonts/class-wp-font-face.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
45 changes: 45 additions & 0 deletions tests/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => <<<CSS
@font-face{font-family:Inter;font-style:normal;font-weight:400;font-display:fallback;src:url('https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf') format('truetype');font-variation-settings:"slnt" 0, "wght" 400;}
CSS
,
),
'variation settings array' => 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' => <<<CSS
@font-face{font-family:Inter;font-style:normal;font-weight:400;font-display:fallback;src:url('https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf') format('truetype');font-variation-settings:"slnt" 0, "wght" 400;}
CSS
,
),
);
}

Expand Down
Loading