W3cubDocs

/WordPress

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

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

Version Description
6.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_font_collection/load_from_json