Repository navigation
Style variations: add $schema when saving variations - #890
Open
KhushalSainS wants to merge 1 commit into
Open
KhushalSainS wants to merge 1 commit into
KhushalSainS wants to merge 1 commit into
Conversation
Unify the two `theme.json` writing paths so style variations get the same `$schema` as `theme.json`. Fixes WordPress#886.
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?
Make style variations declare
$schema, matchingtheme.jsonand core default-theme variations, and unify the two code paths that writetheme.json-shaped data.Why?
Style variations created with "Create Theme Variation" were built from
WP_Theme_JSON::get_data()plus atitle, so they never declared$schema, whiletheme.jsondid. Without$schema, editors cannot validate or autocomplete the file and theme validators warn about it, and it is inconsistent with every core default theme, which declares$schemain each variation (e.g. Twenty Twenty-Fivestyles/01-evening.json).The root cause is that two independent code paths write
theme.json-shaped data and only one of them added the schema. Unifying them removes the drift instead of duplicating the logic.Fixes #886.
How?
CBT_Theme_JSON_Resolver::get_schema()to resolve the schema URL: the theme's declared$schema, then the parent theme's for child themes, then the version-based URL.CBT_Theme_JSON_Resolver::add_schema_to_data()to order$schema,version, andtitlefirst.export_theme_data()to the shared helpers so the export and variation paths cannot drift.CBT_Theme_JSON::add_theme_json_variation_to_local()throughadd_schema_to_data()before writing.array_key_exists( 'schema', ... )instead of'$schema', so the theme's declared schema was effectively never used.tests/test-theme-json.phpcovering the ordering and asserting the variation's$schemamatchestheme.json.Testing Instructions
npm ciandcomposer install.npx wp-env start.npm run test:unit:php.Test_Create_Block_Theme_JSONpasses, verifying thatadd_schema_to_data()orders$schema,version, andtitlefirst and that a created variation's$schemaequals the one written totheme.json.composer lint.styles/<slug>.jsonstarts with$schemathenversion.Use of AI Tools
AI assistance: Yes
Tool: OpenAI Codex