Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@ public static function get_theme_data( $deprecated = array(), $options = array()
} else {
$theme_json_data = array();
}
// BEGIN OF EXPERIMENTAL CODE. Not to backport to core.
$theme_json_data = gutenberg_add_registered_fonts_to_theme_json( $theme_json_data );
// END OF EXPERIMENTAL CODE.

/**
* Filters the data provided by the theme for global styles and settings.
Expand All @@ -266,10 +263,7 @@ public static function get_theme_data( $deprecated = array(), $options = array()
if ( '' !== $parent_theme_json_file ) {
$parent_theme_json_data = static::read_json_file( $parent_theme_json_file );
$parent_theme_json_data = static::translate( $parent_theme_json_data, $wp_theme->parent()->get( 'TextDomain' ) );
// BEGIN OF EXPERIMENTAL CODE. Not to backport to core.
$parent_theme_json_data = gutenberg_add_registered_fonts_to_theme_json( $parent_theme_json_data );
// END OF EXPERIMENTAL CODE.
$parent_theme = new WP_Theme_JSON_Gutenberg( $parent_theme_json_data );
$parent_theme = new WP_Theme_JSON_Gutenberg( $parent_theme_json_data );

/*
* Merge the child theme.json into the parent theme.json.
Expand All @@ -279,6 +273,11 @@ public static function get_theme_data( $deprecated = array(), $options = array()
static::$theme = $parent_theme;
}
}

// BEGIN OF EXPERIMENTAL CODE. Not to backport to core.
static::$theme = gutenberg_add_registered_fonts_to_theme_json( static::$theme );
// END OF EXPERIMENTAL CODE.

}

if ( ! $options['with_supports'] ) {
Expand Down
26 changes: 16 additions & 10 deletions lib/experimental/fonts-api/register-fonts-from-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ function gutenberg_register_fonts_from_theme_json() {
*/
function gutenberg_add_registered_fonts_to_theme_json( $data ) {
$font_families_registered = wp_fonts()->get_registered_font_families();
$font_families_from_theme = ! empty( $data['settings']['typography']['fontFamilies'] )
? $data['settings']['typography']['fontFamilies']

$raw_data = $data->get_raw_data();

$font_families_from_theme = ! empty( $raw_data['settings']['typography']['fontFamilies']['theme'] )
? $raw_data['settings']['typography']['fontFamilies']['theme']
: array();

/**
Expand Down Expand Up @@ -157,21 +160,24 @@ function gutenberg_add_registered_fonts_to_theme_json( $data ) {

// Make sure the path to settings.typography.fontFamilies.theme exists
// before adding missing fonts.
if ( empty( $data['settings'] ) ) {
$data['settings'] = array();
if ( empty( $raw_data['settings'] ) ) {
$raw_data['settings'] = array();
}
if ( empty( $raw_data['settings']['typography'] ) ) {
$raw_data['settings']['typography'] = array();
}
if ( empty( $data['settings']['typography'] ) ) {
$data['settings']['typography'] = array();
if ( empty( $raw_data['settings']['typography']['fontFamilies'] ) ) {
$raw_data['settings']['typography']['fontFamilies'] = array();
}
if ( empty( $data['settings']['typography']['fontFamilies'] ) ) {
$data['settings']['typography']['fontFamilies'] = array();
if ( empty( $raw_data['settings']['typography']['fontFamilies'] ) ) {
$raw_data['settings']['typography']['fontFamilies']['theme'] = array();
}

foreach ( $to_add as $font_family_handle ) {
$data['settings']['typography']['fontFamilies'][] = wp_fonts()->to_theme_json( $font_family_handle );
$raw_data['settings']['typography']['fontFamilies']['theme'][] = wp_fonts()->to_theme_json( $font_family_handle );
}

return $data;
return new WP_Theme_JSON_Gutenberg( $raw_data );
}
}

Expand Down