Skip to content
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

FSE: Allow child theme.json to be merged with parent theme.json #35459

Merged
merged 9 commits into from Oct 18, 2021
14 changes: 13 additions & 1 deletion lib/class-wp-theme-json-resolver-gutenberg.php
Expand Up @@ -273,7 +273,19 @@ 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( 'theme.json' ) );
$theme_json_data = self::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
self::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data );
self::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data );

// If this is a child theme we want to combine the theme.json from the child with the theme.json with the parent.
scruffian marked this conversation as resolved.
Show resolved Hide resolved
if ( is_child_theme() ) {
scruffian marked this conversation as resolved.
Show resolved Hide resolved
// Get parent theme.json.
$parent_theme_json_data = self::read_json_file( get_template_directory() . '/theme.json' );
$parent_theme_json_data = self::translate( $parent_theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
$parent_theme_json_class_instance = new WP_Theme_JSON_Gutenberg( $parent_theme_json_data );
scruffian marked this conversation as resolved.
Show resolved Hide resolved

// Merge the child theme.json into the parent theme.json.
$parent_theme_json_class_instance->merge( self::$theme );
self::$theme = $parent_theme_json_class_instance;
}
}

if ( empty( $theme_support_data ) ) {
Expand Down