Skip to content

Style variations: add $schema when saving variations - #890

Open
KhushalSainS wants to merge 1 commit into
WordPress:trunkfrom
KhushalSainS:fix/style-variation-schema-886
Open

KhushalSainS wants to merge 1 commit into
WordPress:trunkfrom
KhushalSainS:fix/style-variation-schema-886

Conversation

@KhushalSainS

@KhushalSainS KhushalSainS commented Oct 16, 2026 •

Copy link
Copy Markdown

What?

Make style variations declare $schema, matching theme.json and core default-theme variations, and unify the two code paths that write theme.json-shaped data.

Why?

Style variations created with "Create Theme Variation" were built from WP_Theme_JSON::get_data() plus a title, so they never declared $schema, while theme.json did. 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 $schema in each variation (e.g. Twenty Twenty-Five styles/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?

  • Extract 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.
  • Extract CBT_Theme_JSON_Resolver::add_schema_to_data() to order $schema, version, and title first.
  • Delegate export_theme_data() to the shared helpers so the export and variation paths cannot drift.
  • Route CBT_Theme_JSON::add_theme_json_variation_to_local() through add_schema_to_data() before writing.
  • Fix a latent key bug: the declared schema was read with array_key_exists( 'schema', ... ) instead of '$schema', so the theme's declared schema was effectively never used.
  • Add tests/test-theme-json.php covering the ordering and asserting the variation's $schema matches theme.json.

Testing Instructions

  1. Install dependencies with npm ci and composer install.
  2. Start the test environment with npx wp-env start.
  3. Run npm run test:unit:php.
  4. Confirm Test_Create_Block_Theme_JSON passes, verifying that add_schema_to_data() orders $schema, version, and title first and that a created variation's $schema equals the one written to theme.json.
  5. Run composer lint.
  6. Manual check: in the Site Editor open Create Block Theme, create a theme variation, and confirm styles/<slug>.json starts with $schema then version.

Use of AI Tools

AI assistance: Yes
Tool: OpenAI Codex

Unify the two `theme.json` writing paths so style variations get the same `$schema` as `theme.json`.

Fixes WordPress#886.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Style variations are saved without $schema

1 participant