WP_Font_Utils::maybe_add_quotes
Adds surrounding quotes to font family names that contain special characters.
It follows the recommendations from the CSS Fonts Module Level 4.
Method of the class: WP_Font_Utils{}
No Hooks.
Returns
String. The font family name with surrounding quotes, if necessary.
Usage
$result = WP_Font_Utils::maybe_add_quotes( $item );
- $item(string) (required)
- A font family name.
Changelog
| Since 6.5.0 | Introduced. |
WP_Font_Utils::maybe_add_quotes() WP Font Utils::maybe add quotes code WP 7.0
private static function maybe_add_quotes( $item ) {
// Matches strings that are not exclusively alphabetic characters or hyphens, and do not exactly follow the pattern generic(alphabetic characters or hyphens).
$regex = '/^(?!generic\([a-zA-Z\-]+\)$)(?!^[a-zA-Z\-]+$).+/';
$item = trim( $item );
if ( preg_match( $regex, $item ) ) {
$item = trim( $item, "\"'" );
return '"' . $item . '"';
}
return $item;
}