Loads font collection data from a JSON file or URL.
Parameters
$file_or_url
stringrequired- File path or URL to a JSON file containing the font collection data.
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. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.