WP_Font_Library::register_font_collection( string $slug, array $args ): WP_Font_Collection|WP_Error

In this article

Register a new font collection.

Parameters

$slugstringrequired
Font collection slug. May only contain alphanumeric characters, dashes, and underscores. See sanitize_title() .
$argsarrayrequired
Font collection data. See wp_register_font_collection() for information on accepted arguments.
More Arguments from wp_register_font_collection( … $args )Font collection data.
  • name string
    Required. Name of the font collection shown in the Font Library.
  • description string
    Optional. A short descriptive summary of the font collection. Default empty.
  • font_families array|string
    Required. Array of font family definitions that are in the collection, or a string containing the path or URL to a JSON file containing the font collection.
  • categories array
    Optional. Array of categories, each with a name and slug, that are used by the fonts in the collection. Default empty.

Return

WP_Font_Collection|WP_Error A font collection if it was registered successfully, or WP_Error object on failure.

Source

public function register_font_collection( string $slug, array $args ) {
	$new_collection = new WP_Font_Collection( $slug, $args );

	if ( $this->is_collection_registered( $new_collection->slug ) ) {
		$error_message = sprintf(
			/* translators: %s: Font collection slug. */
			__( 'Font collection with slug: "%s" is already registered.' ),
			$new_collection->slug
		);
		_doing_it_wrong(
			__METHOD__,
			$error_message,
			'6.5.0'
		);
		return new WP_Error( 'font_collection_registration_error', $error_message );
	}
	$this->collections[ $new_collection->slug ] = $new_collection;
	return $new_collection;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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