Repository navigation
Style variations: Add $schema when saving variations - #889
Closed
KhushalSainS wants to merge 1 commit into
Closed
KhushalSainS wants to merge 1 commit into
KhushalSainS wants to merge 1 commit into
Conversation
Style variations created via "Save as style variation" are written from WP_Theme_JSON::get_data() plus a title, so they never declare $schema. theme.json does, via CBT_Theme_JSON_Resolver::export_theme_data().
Extract the schema resolution and $schema/version ordering into CBT_Theme_JSON_Resolver::get_schema() and add_schema_to_data(), and route both export_theme_data() and add_theme_json_variation_to_local() through them. This also fixes a latent bug where the declared $schema was read under the wrong key ('schema' instead of '$schema').
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.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.Note: fixing the key bug means exported
theme.jsonnow honors the theme's declared$schemainstead of always falling back to the version-based URL. If you prefertheme.jsonoutput to stay byte-for-byte identical, the conservative variant keeps the old fallback and only applies the ordering helper.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