WP_Font_Face::build_font_face_css
Builds the font-family's CSS.
Method of the class: WP_Font_Face{}
No Hooks.
Returns
String. This font-family's CSS.
Usage
// private - for code of main (parent) class only $result = $this->build_font_face_css( $font_face );
- $font_face(array) (required)
- Font face to process.
Changelog
| Since 6.4.0 | Introduced. |
WP_Font_Face::build_font_face_css() WP Font Face::build font face css code WP 7.0
private function build_font_face_css( array $font_face ) {
$css = '';
/*
* Wrap font-family in quotes if it contains spaces
* and is not already wrapped in quotes.
*/
if (
str_contains( $font_face['font-family'], ' ' ) &&
! str_contains( $font_face['font-family'], '"' ) &&
! str_contains( $font_face['font-family'], "'" )
) {
$font_face['font-family'] = '"' . $font_face['font-family'] . '"';
}
foreach ( $font_face as $key => $value ) {
// Compile the "src" parameter.
if ( 'src' === $key ) {
$value = $this->compile_src( $value );
}
// If font-variation-settings is an array, convert it to a string.
if ( 'font-variation-settings' === $key && is_array( $value ) ) {
$value = $this->compile_variations( $value );
}
if ( ! empty( $value ) ) {
$css .= "$key:$value;";
}
}
return $css;
}