wppaste
WordPress

WP_Font_Face_Resolver

Source
wp-includes/fonts/class-wp-font-face-resolver.php:19
The Font Face Resolver abstracts the processing of different data sources (such as theme.json) for processing within the Font Face.

Description

This class is for internal core usage and is not supposed to be used by extenders (plugins and/or themes).

Compatibility

WordPress
core
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Methods · 7

Source code

class WP_Font_Face_Resolver { 	/**	 * Gets fonts defined in theme.json.	 *	 * @since 6.4.0	 *	 * @return array Returns the font-families, each with their font-face variations.	 */	public static function get_fonts_from_theme_json() {		$settings = wp_get_global_settings(); 		// Bail out early if there are no font settings.		if ( empty( $settings['typography']['fontFamilies'] ) ) {			return array();		} 		return static::parse_settings( $settings );	} 	/**	 * Gets fonts defined in style variations.	 *	 * @since 6.7.0	 *	 * @return array Returns an array of font-families.	 */	public static function get_fonts_from_style_variations() {		$variations = WP_Theme_JSON_Resolver::get_style_variations();		$fonts      = array(); 		if ( empty( $variations ) ) {			return $fonts;		} 		foreach ( $variations as $variation ) {			if ( ! empty( $variation['settings']['typography']['fontFamilies']['theme'] ) ) {				$fonts = array_merge( $fonts, $variation['settings']['typography']['fontFamilies']['theme'] );			}		} 		$settings = array(			'typography' => array(				'fontFamilies' => array(					'theme' => $fonts,				),			),		); 		return static::parse_settings( $settings );	} 	/**	 * Parse theme.json settings to extract font definitions with variations grouped by font-family.	 *	 * @since 6.4.0	 *	 * @param array $settings Font settings to parse.	 * @return array Returns an array of fonts, grouped by font-family.	 */	private static function parse_settings( array $settings ) {		$fonts = array(); 		foreach ( $settings['typography']['fontFamilies'] as $font_families ) {			foreach ( $font_families as $definition ) { 				// Skip if "fontFace" is not defined, meaning there are no variations.				if ( empty( $definition['fontFace'] ) ) {					continue;				} 				// Skip if "fontFamily" is not defined.				if ( empty( $definition['fontFamily'] ) ) {					continue;				} 				$font_family_name = static::maybe_parse_name_from_comma_separated_list( $definition['fontFamily'] ); 				// Skip if no font family is defined.				if ( empty( $font_family_name ) ) {

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/fonts/class-wp-font-face-resolver.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.