Skip to content

Theme JSON: Define preset CSS vars for blocks based on feature selectors#10869

Open
aaronrobertshaw wants to merge 5 commits into
WordPress:trunkfrom
aaronrobertshaw:add/block-support-preset-selectors
Open

Theme JSON: Define preset CSS vars for blocks based on feature selectors#10869
aaronrobertshaw wants to merge 5 commits into
WordPress:trunkfrom
aaronrobertshaw:add/block-support-preset-selectors

Conversation

@aaronrobertshaw

@aaronrobertshaw aaronrobertshaw commented Feb 5, 2026

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/64598

This PR brings the changes from the following Gutenberg PR to core:

WordPress/gutenberg#75226

Description

Updates the global styles engine and theme JSON processing to generate preset CSS custom properties (vars) for blocks based on their feature-specific selectors rather than only the block's root selector. This enables blocks whose root selector targets an inner element to have preset CSS vars output on the appropriate outer wrapper selector.

See: WordPress/gutenberg#74242

Testing

  1. Run the PHP unit tests: phpunit --filter=WP_Theme_JSON_Test
  2. Verify all existing tests continue to pass, including the new test_get_stylesheet_preset_css_vars_use_feature_selector test.
  3. For manual testing, register a block that defines a feature-level selector (e.g. a dimensions.root selector different from the block's root selector), define dimensionSizes presets for that block in theme.json, and confirm the CSS vars are output on the feature selector rather than the block's root selector.

@github-actions

github-actions Bot commented Feb 5, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props aaronrobertshaw, ramonopoly, westonruter, wildworks.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Feb 5, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@aaronrobertshaw

Copy link
Copy Markdown
Author

The test failure is related. This will need to be rebased after #10628 lands.

Alternatively, I might be able to update the test to use an older preset in theme json, e.g. aspect ratio or something.

If I go that route I'll update the Gutenberg PR to match

Comment thread src/wp-includes/class-wp-theme-json.php Outdated
Comment thread src/wp-includes/class-wp-theme-json.php Outdated
Comment thread src/wp-includes/class-wp-theme-json.php Outdated
Comment thread tests/phpunit/tests/theme/wpThemeJson.php Outdated
@aaronrobertshaw aaronrobertshaw force-pushed the add/block-support-preset-selectors branch from 81e988f to 027feba Compare February 11, 2026 07:23
Comment thread src/wp-includes/class-wp-theme-json.php Outdated
Comment thread src/wp-includes/class-wp-theme-json.php Outdated
@t-hamano

t-hamano commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

I would appreciate it if you could proceed with this PR and commit it in time for the 7.1 Beta1 release on July 15.

aaronrobertshaw and others added 4 commits July 14, 2026 16:17
Backport of WordPress/gutenberg#75226

Updates the global styles engine to generate preset CSS custom properties
on feature-specific selectors rather than only the block's root selector.
This enables blocks whose root selector targets an inner element to have
preset CSS vars output on the appropriate outer wrapper selector.
Co-authored-by: Weston Ruter <westonruter@gmail.com>
@ramonjd ramonjd force-pushed the add/block-support-preset-selectors branch from 9a2cf73 to 0cc2bf5 Compare July 14, 2026 06:17
Comment thread src/wp-includes/class-wp-theme-json.php Outdated
@ramonjd

ramonjd commented Jul 14, 2026

Copy link
Copy Markdown
Member

@aaronrobertshaw This was prepped before 7.0 and probably punted by default.

I've rebased and prepped things, but would like to know if it's okay to commit.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants