Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 3f5efed

Browse files
authored
Merge pull request #9 from creode/feature/correct_wordpress_core_font_size_bug
Added code to correct WordPress core issue where font-size presets ar…
2 parents 35d1ef3 + af42621 commit 3f5efed

4 files changed

Lines changed: 112 additions & 0 deletions

File tree

includes/bug-fixes/all.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Bug Fixes - Load All
4+
*
5+
* This file loads all bug fixes for WordPress core issues.
6+
*
7+
* @package Creode Theme
8+
*/
9+
10+
// Prevent direct access.
11+
if ( ! defined( 'ABSPATH' ) ) {
12+
exit;
13+
}
14+
15+
// Load all bug fixes.
16+
require_once __DIR__ . '/fix-wordpress-theme-json-font-sizes.php';
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* WordPress Theme.json Font Size Bug Fix
4+
*
5+
* Workaround for WordPress 6.8.2 bug where theme.json font size presets
6+
* are not properly loaded. Intercepts default font size processing and
7+
* applies theme's intended font size values.
8+
*
9+
* @package Creode Theme
10+
*/
11+
12+
// Prevent direct access.
13+
if ( ! defined( 'ABSPATH' ) ) {
14+
exit;
15+
}
16+
17+
/**
18+
* Fix WordPress 6.8.2 theme.json font size loading bug.
19+
*
20+
* Loads theme.json file directly and extracts font sizes to ensure they
21+
* are properly applied. Uses wp_theme_json_data_default filter with high
22+
* priority because wp_theme_json_data_theme filter is not working in WordPress 6.8.2.
23+
*/
24+
add_filter(
25+
'wp_theme_json_data_default',
26+
function ( WP_Theme_JSON_Data $theme_json ) {
27+
// Load theme.json file directly using WordPress API.
28+
$wp_theme = wp_get_theme();
29+
$theme_json_file = $wp_theme->get_file_path( 'theme.json' );
30+
31+
// Ensure theme.json file exists and is readable.
32+
if ( ! $theme_json_file || ! is_readable( $theme_json_file ) ) {
33+
return $theme_json;
34+
}
35+
36+
// Parse theme.json file.
37+
$theme_json_data = json_decode( file_get_contents( $theme_json_file ), true );
38+
39+
// Validate JSON parsing and structure.
40+
if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $theme_json_data ) ) {
41+
return $theme_json;
42+
}
43+
44+
// Extract font sizes from theme.json if they exist.
45+
$theme_font_sizes = null;
46+
47+
if ( isset( $theme_json_data['settings']['typography']['fontSizes'] ) && is_array( $theme_json_data['settings']['typography']['fontSizes'] ) && ! empty( $theme_json_data['settings']['typography']['fontSizes'] ) ) {
48+
$theme_font_sizes = $theme_json_data['settings']['typography']['fontSizes'];
49+
}
50+
51+
// Only proceed if we found font sizes in theme.json.
52+
if ( null === $theme_font_sizes ) {
53+
return $theme_json;
54+
}
55+
56+
$data = $theme_json->get_data();
57+
58+
// Initialize settings structure if needed.
59+
if ( ! isset( $data['settings'] ) ) {
60+
$data['settings'] = array();
61+
}
62+
if ( ! isset( $data['settings']['typography'] ) ) {
63+
$data['settings']['typography'] = array();
64+
}
65+
66+
// Apply font sizes from theme.json file.
67+
$data['settings']['typography']['fontSizes'] = $theme_font_sizes;
68+
69+
$theme_json->update_with( $data );
70+
71+
return $theme_json;
72+
}
73+
);

plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
require_once __DIR__ . '/includes/commands/all.php';
2929
require_once __DIR__ . '/includes/class-asset-enqueue.php';
3030
require_once __DIR__ . '/includes/register-js-libraries.php';
31+
require_once __DIR__ . '/includes/bug-fixes/all.php';
3132

3233
// Register commands.
3334
Install_Theme_Command::register();

theme-template/theme.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@
3737
"name": "Standard",
3838
"slug": "standard"
3939
}
40+
],
41+
"fontSizes": [
42+
{
43+
"name": "Small",
44+
"slug": "small",
45+
"size": "0.8125rem"
46+
},
47+
{
48+
"name": "Medium",
49+
"slug": "medium",
50+
"size": "1.25rem"
51+
},
52+
{
53+
"name": "Large",
54+
"slug": "large",
55+
"size": "2.25rem"
56+
},
57+
{
58+
"name": "Extra Large",
59+
"slug": "x-large",
60+
"size": "2.625rem"
61+
}
4062
]
4163
},
4264
"shadow": {

0 commit comments

Comments
 (0)