'font/otf', 'ttf' => 'font/ttf', 'woff' => 'font/woff', 'woff2' => 'font/woff2', ); /** * Font collections. * * @since 6.4.0 * * @var array */ private static $collections = array(); /** * Register a new font collection. * * @since 6.4.0 * * @param string $id Font collection id. * @param array $config Font collection config options. * @return WP_Font_Collection|WP_Error A font collection is it was registered succesfully and a WP_Error otherwise. */ public static function register_font_collection( $id, $config ) { if ( isset( self::$collections[ $id ] ) ) { return new WP_Error( 'font_collection_registration_error', 'Font collection already registered.' ); } $new_collection = new WP_Font_Collection( $id, $config ); if ( is_wp_error( $new_collection ) ) { return $new_collection; } self::$collections[ $id ] = $new_collection; return $new_collection; } /** * Gets all the font collections available. * * @since 6.4.0 * * @return array List of font collections. */ public static function get_font_collections() { return self::$collections; } /** * Gets a font collection. * * @since 6.4.0 * * @param string $id Font collection id. * @return array List of font collections. */ public static function get_font_collection( $id ) { if ( array_key_exists( $id, self::$collections ) ) { return self::$collections[ $id ]; } return new WP_Error( 'font_collection_not_found', 'Font collection not found.' ); } /** * Gets the upload directory for fonts. * * @since 6.4.0 * * @return string Path of the upload directory for fonts. */ public static function get_fonts_dir() { return wp_upload_dir()['basedir'] . '/fonts'; } /** * Sets the upload directory for fonts. * * @since 6.4.0 * * @param array $defaults { * Default upload directory. * * @type string $path Path to the directory. * @type string $url URL for the directory. * @type string $subdir Sub-directory of the directory. * @type string $basedir Base directory. * @type string $baseurl Base URL. * } * @return array Modified upload directory. */ public static function set_upload_dir( $defaults ) { $defaults['subdir'] = '/fonts'; $defaults['path'] = $defaults['basedir'] . $defaults['subdir']; $defaults['url'] = $defaults['baseurl'] . $defaults['subdir']; return $defaults; } }