WP_Font_Collection::load_from_fileprivateWP 6.5.0

Loads the font collection data from a JSON file path.

Method of the class: WP_Font_Collection{}

No Hooks.

Returns

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

Usage

// private - for code of main (parent) class only
$result = $this->load_from_file( $file );
$file(string) (required)
File path to a JSON file containing the font collection data.

Changelog

Since 6.5.0 Introduced.

WP_Font_Collection::load_from_file() code WP 6.8.1

private function load_from_file( $file ) {
	$data = wp_json_file_decode( $file, array( 'associative' => true ) );
	if ( empty( $data ) ) {
		return new WP_Error( 'font_collection_decode_error', __( 'Error decoding the font collection JSON file contents.' ) );
	}

	return $this->sanitize_and_validate_data( $data, array( 'font_families' ) );
}