Repository navigation
Conversation
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 #885
Recursively strips null values from theme data before serializing it to JSON.
Why?
When the user's global styles contain null values, saving changes or exporting the theme writes them directly into
theme.jsonand style variation files.The
theme.jsonschema rejectsnullfor these properties, and WordPress core ignores them anyway. They create schema validation errors and noisy clutter that theme authors currently have to clean up manually.How?
In
includes/create-theme/resolver_additions.php:CBT_Theme_JSON_Resolver::strip_null_values(): A recursive helper method that traverses array data and drops keys containing null values, while preserving valid falsy values (false,0,"") and empty arrays ([]).CBT_Theme_JSON_Resolver::stringify(): Invokesself::strip_null_values( $data )before encoding. Becausestringify()is the shared funnel for all theme JSON exports (export_theme_data(), variation creation, theme zip export, save changes, and cloned/blank/child themes), this protects all output paths in a centralized place.In
tests/test-theme-utils.php:test_stringify_strips_null_values: Checks that nested null values (such as unlinked border shorthand properties) are dropped when stringifying theme data, while remaining valid properties (like left) are retained.test_strip_null_values_preserves_falsy_values: Checks that non-null falsy values (false,0,"", and empty arrays[]) are preserved and not unintentionally discarded.Testing Instructions
Unit tests:
npm run test:unit:php:setupto start wp-env.npm run test:unit:php:base -- --filter Test_Create_Block_Theme_Utils.Manual test:
theme.json. Understyles.blocks["core/quote"].border, verify that onlyleftis present and nonullfields (color,style,width) exist.Use of AI Tools