Closed megane9988 closed 4 weeks ago
Thanks for the report.
I think this problem occurs when a child theme is created based on a theme that has not been customized in any way, and the following theme.json file is generated for the child theme:
{
"version": 2,
"$schema": "https://schemas.wp.org/wp/6.6/theme.json"
}
And the error is caused by the value here not being an array.
The error itself can be addressed by making the following changes:
diff --git a/includes/create-theme/theme-fonts.php b/includes/create-theme/theme-fonts.php
index 0e403b6..315f56d 100644
--- a/includes/create-theme/theme-fonts.php
+++ b/includes/create-theme/theme-fonts.php
@@ -175,12 +175,13 @@ class CBT_Theme_Fonts {
}
$font_families_to_not_remove = $user_settings['typography']['fontFamilies']['theme'];
+ $theme_font_families = $theme_json['settings']['typography']['fontFamilies'] ?? array();
// Remove font assets from theme
$theme_font_asset_location = get_stylesheet_directory() . '/assets/fonts/';
$font_families_to_remove = array_values(
array_filter(
- $theme_json['settings']['typography']['fontFamilies'],
+ $theme_font_families,
function( $theme_font_family ) use ( $font_families_to_not_remove ) {
return ! in_array( $theme_font_family['slug'], array_column( $font_families_to_not_remove, 'slug' ), true );
}
@@ -207,7 +208,7 @@ class CBT_Theme_Fonts {
// Remove user fonts from theme
$theme_json['settings']['typography']['fontFamilies'] = array_values(
array_filter(
- $theme_json['settings']['typography']['fontFamilies'],
+ $theme_font_families,
function( $theme_font_family ) use ( $font_families_to_not_remove ) {
return in_array( $theme_font_family['slug'], array_column( $font_families_to_not_remove, 'slug' ), true );
}
However, I don't think this is a fundamental solution. If we make the above changes and save the child theme, for example, the child theme's theme.json
will have the following data:
{
"settings": {
"typography": {
"fontFamilies": [
{
"fontFace": [
{
"fontFamily": "ABeeZee",
"fontStyle": "normal",
"fontWeight": "400",
"src": [
"file:./assets/fonts/esDR31xSG-6AGleN6teukbcHCpE.woff2"
]
},
{
"fontFamily": "ABeeZee",
"fontStyle": "italic",
"fontWeight": "400",
"src": [
"file:./assets/fonts/esDT31xSG-6AGleN2tCkkJUCGpG-GQ.woff2"
]
}
],
"fontFamily": "ABeeZee, sans-serif",
"name": "ABeeZee",
"slug": "abeezee"
}
]
}
},
"version": 2,
"$schema": "https://schemas.wp.org/wp/6.6/theme.json"
}
There are two problems here:
Perhaps it is necessary to add a process that takes into account whether it is a child theme or not when regenerating the font file and theme.json.
However, I don't think this is a fundamental solution. If we make the above changes and save the child theme, for example, the child theme's
theme.json
will have the following data...There are two problems here:
- The parent theme's font families are missing
- The font file pointed to by the font face path does not exist in the child theme
I was working on https://github.com/WordPress/create-block-theme/pull/660 which deals with these concerns. The changes make sure that we're only deactivating and removing assets if they're actually present. The child theme's theme.json file is not modified when it does not have theme fonts, and the child theme still relies on the parent's fonts and their assets instead of trying to set them.
Steps
Displaying error
error log