WP_Font_Collection::load_from_json( string $file_or_url ): array|WP_Error

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Loads font collection data from a JSON file or URL.

Parameters

$file_or_urlstringrequired
File path or URL to a JSON file containing the font collection data.

Return

array|WP_Error An array containing the font collection data on success, else an instance of WP_Error on failure.

Source

private function load_from_json( $file_or_url ) {
	$url  = wp_http_validate_url( $file_or_url );
	$file = file_exists( $file_or_url ) ? wp_normalize_path( realpath( $file_or_url ) ) : false;

	if ( ! $url && ! $file ) {
		// translators: %s: File path or URL to font collection JSON file.
		$message = __( 'Font collection JSON file is invalid or does not exist.' );
		_doing_it_wrong( __METHOD__, $message, '6.5.0' );
		return new WP_Error( 'font_collection_json_missing', $message );
	}

	$data = $url ? $this->load_from_url( $url ) : $this->load_from_file( $file );

	if ( is_wp_error( $data ) ) {
		return $data;
	}

	$data = array(
		'name'          => $this->data['name'],
		'font_families' => $data['font_families'],
	);

	if ( isset( $this->data['description'] ) ) {
		$data['description'] = $this->data['description'];
	}

	if ( isset( $this->data['categories'] ) ) {
		$data['categories'] = $this->data['categories'];
	}

	return $data;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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