wppaste
WordPress

WP_Font_Collection

Since
6.5.0
Source
wp-includes/fonts/class-wp-font-collection.php:19
Font Collection class.

Compatibility

WordPress
since 6.5.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

$slugstringpublic
The unique slug for the font collection.
$dataarray|WP_Error|nullprivate
Font collection data.
$srcstring|nullprivate
Font collection JSON file path or URL.

Methods · 7

Source code

final class WP_Font_Collection {	/**	 * The unique slug for the font collection.	 *	 * @since 6.5.0	 * @var string	 */	public $slug; 	/**	 * Font collection data.	 *	 * @since 6.5.0	 * @var array|WP_Error|null	 */	private $data; 	/**	 * Font collection JSON file path or URL.	 *	 * @since 6.5.0	 * @var string|null	 */	private $src; 	/**	 * WP_Font_Collection constructor.	 *	 * @since 6.5.0	 *	 * @param string $slug Font collection slug. May only contain alphanumeric characters, dashes,	 *                     and underscores. See sanitize_title().	 * @param array  $args Font collection data. See wp_register_font_collection() for information on accepted arguments.	 */	public function __construct( string $slug, array $args ) {		$this->slug = sanitize_title( $slug );		if ( $this->slug !== $slug ) {			_doing_it_wrong(				__METHOD__,				/* translators: %s: Font collection slug. */				sprintf( __( 'Font collection slug "%s" is not valid. Slugs must use only alphanumeric characters, dashes, and underscores.' ), $slug ),				'6.5.0'			);		} 		$required_properties = array( 'name', 'font_families' ); 		if ( isset( $args['font_families'] ) && is_string( $args['font_families'] ) ) {			// JSON data is lazy loaded by ::get_data().			$this->src = $args['font_families'];			unset( $args['font_families'] ); 			$required_properties = array( 'name' );		} 		$this->data = $this->sanitize_and_validate_data( $args, $required_properties );	} 	/**	 * Retrieves the font collection data.	 *	 * @since 6.5.0	 *	 * @return array|WP_Error An array containing the font collection data, or a WP_Error on failure.	 */	public function get_data() {		if ( is_wp_error( $this->data ) ) {			return $this->data;		} 		// If the collection uses JSON data, load it and cache the data/error.		if ( isset( $this->src ) ) {			$this->data = $this->load_from_json( $this->src );		} 		if ( is_wp_error( $this->data ) ) {			return $this->data;		} 		// Set defaults for optional properties.

Changelog

Introduced in 6.5.0. 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-collection.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.