Sanitizes and formats font family names.
Description
- Applies
sanitize_text_field
. - Adds surrounding quotes to names containing any characters that are not alphabetic or dashes.
It follows the recommendations from the CSS Fonts Module Level 4.
See also
Parameters
$font_family
stringrequired- Font family name(s), comma-separated.
Source
public static function sanitize_font_family( $font_family ) {
if ( ! $font_family ) {
return '';
}
$output = sanitize_text_field( $font_family );
$formatted_items = array();
if ( str_contains( $output, ',' ) ) {
$items = explode( ',', $output );
foreach ( $items as $item ) {
$formatted_item = self::maybe_add_quotes( $item );
if ( ! empty( $formatted_item ) ) {
$formatted_items[] = $formatted_item;
}
}
return implode( ', ', $formatted_items );
}
return self::maybe_add_quotes( $output );
}
Changelog
Version | Description |
---|---|
6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.