Repository navigation
Fix: preserve parent presets when saving child theme changes - #893
Open
CookieDarb wants to merge 1 commit into
Open
CookieDarb wants to merge 1 commit into
CookieDarb wants to merge 1 commit into
Conversation
CookieDarb
marked this pull request as ready for review
October 21, 2026 12:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Closes #813
Fixes an issue where saving changes to a child theme in the Site Editor completely wipes out the parent theme's color palette (and other indexed presets like gradients or font sizes).
Why?
When saving changes to a child theme, Create Block Theme exports its
theme.jsonin'current'mode so the child theme only writes its deltas rather than cloning the parent theme.While WordPress Core recursively merges associative dictionaries (e.g., layout and block style overrides), Core treats indexed preset arrays (
settings.color.palette,settings.typography.fontSizes, etc.) as complete replacements. When a user adds or modifies a single color in a child theme, CBT previously wrote only that user's entries into the child'stheme.json, leading Core to drop all parent theme presets at runtime.How?
includes/create-theme/resolver_additions.php:CBT_Theme_JSON_Resolver::export_theme_data(), when exporting in'current'mode and the active theme is a child theme, read the raw parenttheme.jsonand backfill parent preset entries viamerge_parent_preset_arrays().merge_parent_preset_arrays(): recursively traverses the child data. For any slug-keyed preset lists, it merges parent entries with child entries. Child overrides replace parent entries by slug in-place, new child presets are appended, and non-preset objects (layout, block styles) remain untouched child deltas.is_preset_list()andis_list()to safely identify slug-keyed preset arrays while supporting PHP 7.4+.tests/test-resolver-preset-merge.php:palette: []), and non-preset delta preservation.Testing Instructions
theme.jsonon disk or refresh the Site Editor.Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Adding tests, documentation and aligning implementation.