wp-includes/fonts/class-wp-font-utils.php:20A class of utilities for working with the Font Library.
class WP_Font_Utils { /** * Adds surrounding quotes to font family names that contain special characters. * * It follows the recommendations from the CSS Fonts Module Level 4. * @link https://www.w3.org/TR/css-fonts-4/#font-family-prop * * @since 6.5.0 * * @param string $item A font family name. * @return string The font family name with surrounding quotes, if necessary. */ 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; } /** * Sanitizes and formats font family names. * * - 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. * @link https://www.w3.org/TR/css-fonts-4/#font-family-prop * * @since 6.5.0 * @access private * * @see sanitize_text_field() * * @param string $font_family Font family name(s), comma-separated. * @return string Sanitized and formatted font family name(s). */ 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 ); } /** * Generates a slug from font face properties, e.g. `open sans;normal;400;100%;U+0-10FFFF` * * Used for comparison with other font faces in the same family, to prevent duplicates * that would both match according the CSS font matching spec. Uses only simple case-insensitive * matching for fontFamily and unicodeRange, so does not handle overlapping font-family lists or * unicode ranges. * * @since 6.5.0 * @access private * * @link https://drafts.csswg.org/css-fonts/#font-style-matching * * @param array $settings { * Font face settings. * * @type string $fontFamily Font family name. * @type string $fontStyle Optional font style, defaults to 'normal'. * @type string $fontWeight Optional font weight, defaults to 400. * @type string $fontStretch Optional font stretch, defaults to '100%'.Introduced in 6.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/fonts/class-wp-font-utils.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.