WP_Font_Utils::maybe_add_quotes( string $item ): string

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Adds surrounding quotes to font family names that contain special characters.

Description

It follows the recommendations from the CSS Fonts Module Level 4.

Parameters

$itemstringrequired
A font family name.

Return

string The font family name with surrounding quotes, if necessary.

Source

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;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.