WP_Font_Library::register_font_collection
Register a new font collection.
Method of the class: WP_Font_Library{}
No Hooks.
Returns
WP_Font_Collection|WP_Error. A font collection if it was registered successfully, or WP_Error object on failure.
Usage
$WP_Font_Library = new WP_Font_Library(); $WP_Font_Library->register_font_collection( $slug, $args );
- $slug(string) (required)
- Font collection slug. May only contain alphanumeric characters, dashes, and underscores. See sanitize_title().
- $args(array) (required)
- Font collection data. See wp_register_font_collection() for information on accepted arguments.
Changelog
| Since 6.5.0 | Introduced. |
WP_Font_Library::register_font_collection() WP Font Library::register font collection code WP 7.0.2
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;
}