debugging fixes
This commit is contained in:
parent
fda7bd1d12
commit
c44c49a836
1 changed files with 75 additions and 45 deletions
|
|
@ -282,24 +282,41 @@ function mlf_get_capability() {
|
||||||
* @return WP_Theme_JSON_Data Modified theme.json data.
|
* @return WP_Theme_JSON_Data Modified theme.json data.
|
||||||
*/
|
*/
|
||||||
function mlf_add_fonts_to_theme_json($theme_json) {
|
function mlf_add_fonts_to_theme_json($theme_json) {
|
||||||
|
// Wrap in try-catch to prevent breaking Site Editor if something goes wrong
|
||||||
|
try {
|
||||||
$registry = new MLF_Font_Registry();
|
$registry = new MLF_Font_Registry();
|
||||||
$fonts = $registry->get_imported_fonts_with_src();
|
$fonts = $registry->get_imported_fonts_with_src();
|
||||||
|
|
||||||
if (empty($fonts)) {
|
if (empty($fonts) || !is_array($fonts)) {
|
||||||
return $theme_json;
|
return $theme_json;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build our font families
|
// Build our font families
|
||||||
$font_families = [];
|
$font_families = [];
|
||||||
$font_dir = wp_get_font_dir();
|
$font_dir = wp_get_font_dir();
|
||||||
|
|
||||||
|
if (empty($font_dir['url'])) {
|
||||||
|
return $theme_json;
|
||||||
|
}
|
||||||
|
|
||||||
$font_base_url = trailingslashit($font_dir['url']);
|
$font_base_url = trailingslashit($font_dir['url']);
|
||||||
|
|
||||||
foreach ($fonts as $font) {
|
foreach ($fonts as $font) {
|
||||||
|
// Validate required font properties
|
||||||
|
if (empty($font['name']) || empty($font['slug']) || empty($font['variants'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$font_faces = [];
|
$font_faces = [];
|
||||||
|
|
||||||
foreach ($font['variants'] as $variant) {
|
foreach ($font['variants'] as $variant) {
|
||||||
$weight = $variant['weight'];
|
// Validate variant data
|
||||||
$style = $variant['style'];
|
if (empty($variant['filename'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$weight = !empty($variant['weight']) ? $variant['weight'] : '400';
|
||||||
|
$style = !empty($variant['style']) ? $variant['style'] : 'normal';
|
||||||
$filename = $variant['filename'];
|
$filename = $variant['filename'];
|
||||||
|
|
||||||
// Use direct file URL
|
// Use direct file URL
|
||||||
|
|
@ -314,6 +331,8 @@ function mlf_add_fonts_to_theme_json($theme_json) {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only add font if it has valid faces
|
||||||
|
if (!empty($font_faces)) {
|
||||||
$font_families[] = [
|
$font_families[] = [
|
||||||
'name' => $font['name'],
|
'name' => $font['name'],
|
||||||
'slug' => $font['slug'],
|
'slug' => $font['slug'],
|
||||||
|
|
@ -321,6 +340,12 @@ function mlf_add_fonts_to_theme_json($theme_json) {
|
||||||
'fontFace' => $font_faces,
|
'fontFace' => $font_faces,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only update if we have valid fonts
|
||||||
|
if (empty($font_families)) {
|
||||||
|
return $theme_json;
|
||||||
|
}
|
||||||
|
|
||||||
// Use update_with to merge - WordPress handles the merging logic
|
// Use update_with to merge - WordPress handles the merging logic
|
||||||
$new_data = [
|
$new_data = [
|
||||||
|
|
@ -333,6 +358,11 @@ function mlf_add_fonts_to_theme_json($theme_json) {
|
||||||
];
|
];
|
||||||
|
|
||||||
return $theme_json->update_with($new_data);
|
return $theme_json->update_with($new_data);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Log error but don't break the Site Editor
|
||||||
|
error_log('MLF theme.json filter error: ' . $e->getMessage());
|
||||||
|
return $theme_json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
add_filter('wp_theme_json_data_user', 'mlf_add_fonts_to_theme_json', 10);
|
add_filter('wp_theme_json_data_user', 'mlf_add_fonts_to_theme_json', 10);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue