Global Styles: Make theme.json extensible#30259
Conversation
| * @return array Contents that adhere to the theme.json schema. | ||
| */ | ||
| private static function read_json_file( $file_path ) { | ||
| public static function read_json_file( $file_path ) { |
There was a problem hiding this comment.
I'm not sure this change is ok. It makes things easier for child themes, as they can just call this function directly, but if this change is not OK we can do without it.
| public static function get_theme_data( $theme_support_data = array() ) { | ||
| if ( null === self::$theme ) { | ||
| $theme_json_data = self::read_json_file( self::get_file_path_from_theme( 'experimental-theme.json' ) ); | ||
| $theme_json_data = apply_filters( 'theme_json_data', $theme_json_data ); |
There was a problem hiding this comment.
I couldn't find other filters in this file so I wasn't sure if there was a reason we don't have them, or if there's a better alternative.
|
Size Change: 0 B Total Size: 1.42 MB ℹ️ View Unchanged
|
|
👋 We do plan to add some hooks to this so others can extend/modify/etc, see #27504 However, this is not a good moment to add hooks. I'm about to share a PR for #29891 and there are a few other things to stabilize. When that's ready when can add hooks. This said I'm super interested in hearing use cases: what's what you want to do? |
|
The use case is to have one theme extend the theme.json of another theme without having to redeclare all the properties. |
|
I'm a bit worried about providing extensibility for theme.json "format" now whether it's with this new filter or the existing In both cases though, if we do it naively, the format of the theme.json will be exposed without "version" handling. In other words, unless we force plugin authors to explicitly handle versions in their filters, the versioning of the file (for future changes) is useless. |
|
Closing this until theme.json is more stable. |
Description
Make it possible to filter the theme.json file provided by the theme, so themes can do other things with it, like generate the values on the server.
This is an alternative approach to #30147.
How has this been tested?
Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: