-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Got error message "There has been a critical error on this website". when I pushed "Save Changes to Theme" button after I changed font setting in the chilid theme. #659
Comments
There has been a critical error on this website.
when I pushed Save Changes to Theme
after I changed font setting in the chilid theme.
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 {
"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. |
I was working on #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. |
* Check if theme fonts present before removing Fixes: #659 * make sure remove_deactivated_font_assets is static * use correct condition for asset removal ie. bail on null * remove unused variable * add comments and reword some of the existing ones
* Check if theme fonts present before removing Fixes: WordPress/create-block-theme#659 * make sure remove_deactivated_font_assets is static * use correct condition for asset removal ie. bail on null * remove unused variable * add comments and reword some of the existing ones
Steps
Displaying error
error log
The text was updated successfully, but these errors were encountered: