wppaste
WordPress

WP_Font_Face

Since
6.4.0
Source
wp-includes/fonts/class-wp-font-face.php:15
Font Face generates and prints @font-face styles for given fonts.

Compatibility

WordPress
since 6.4.0
  • 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).

Properties · 3

$font_face_property_defaultsstring[]private
The font-face property defaults.
$valid_font_face_propertiesstring[]private
Valid font-face property names.
$valid_font_displaystring[]private
Valid font-display values.

Methods · 8

Source code

class WP_Font_Face { 	/**	 * The font-face property defaults.	 *	 * @since 6.4.0	 *	 * @var string[]	 */	private $font_face_property_defaults = array(		'font-family'  => '',		'font-style'   => 'normal',		'font-weight'  => '400',		'font-display' => 'fallback',	); 	/**	 * Valid font-face property names.	 *	 * @since 6.4.0	 *	 * @var string[]	 */	private $valid_font_face_properties = array(		'ascent-override',		'descent-override',		'font-display',		'font-family',		'font-stretch',		'font-style',		'font-weight',		'font-variant',		'font-feature-settings',		'font-variation-settings',		'line-gap-override',		'size-adjust',		'src',		'unicode-range',	); 	/**	 * Valid font-display values.	 *	 * @since 6.4.0	 *	 * @var string[]	 */	private $valid_font_display = array( 'auto', 'block', 'fallback', 'swap', 'optional' ); 	/**	 * Generates and prints the `@font-face` styles for the given fonts.	 *	 * @since 6.4.0	 *	 * @param array[][] $fonts Optional. The font-families and their font variations.	 *                         See {@see wp_print_font_faces()} for the supported fields.	 *                         Default empty array.	 */	public function generate_and_print( array $fonts ) {		$fonts = $this->validate_fonts( $fonts ); 		// Bail out if there are no fonts are given to process.		if ( empty( $fonts ) ) {			return;		} 		$css = $this->get_css( $fonts ); 		/*		 * The font-face CSS is contained within <style> tags and can only be interpreted		 * as CSS in the browser. Using wp_strip_all_tags() is sufficient escaping		 * to avoid malicious attempts to close </style> and open a <script>.		 */		$css = wp_strip_all_tags( $css ); 		// Bail out if there is no CSS to print.		if ( empty( $css ) ) {			return;		}

Changelog

Introduced in 6.4.0. 3 changes between 6.7.7 and 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.

7.0.4
Method __construct() removed.verified against source
7.0.4
Method get_style_element() removed.verified against source
7.0.4
Method generate_style_element_attributes() removed.verified against source
6.4.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/fonts/class-wp-font-face.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.