Skip to content

Block Supports: Add a helper that returns every support's classes and styles - #15485

Open
aaronrobertshaw wants to merge 15 commits into
WordPress:trunkfrom
aaronrobertshaw:backport/block-supports-classes-and-styles-helper
Open

aaronrobertshaw wants to merge 15 commits into
WordPress:trunkfrom
aaronrobertshaw:backport/block-supports-classes-and-styles-helper

Conversation

@aaronrobertshaw

@aaronrobertshaw aaronrobertshaw commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Backport of Gutenberg PR WordPress/gutenberg#86337

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

Adds wp_get_block_supports_classes_and_styles(), which returns the combined classes and styles of the background, color, border, shadow and spacing helpers. An optional list limits it to the supports a block applies to one element.

This PR backports:

  • wp_get_block_supports_classes_and_styles(), next to the other block support utilities,
  • and the accompanying block supports tests.

The Avatar and Post Navigation Link changes that call it arrive later with the Gutenberg package update.

Dependency: stacked on #14094, which adds the five helpers this one calls. Once #14094 is committed, this branch should be rebased onto trunk.

Testing instructions

Nothing renders differently, because no block calls the helper in Core yet. To check its output:

npm run env:cli -- eval "var_export( wp_get_block_supports_classes_and_styles( array( 'borderColor' => 'contrast', 'style' => array( 'border' => array( 'width' => '2px' ), 'shadow' => 'var:preset|shadow|natural', 'spacing' => array( 'padding' => array( 'top' => '10px' ) ) ) ), array( 'border', 'shadow' ) ) );"

It outputs only the border and shadow, without the padding:

array (
  'class' => 'has-border-color has-contrast-border-color',
  'style' => 'border-width:2px;box-shadow:var(--wp--preset--shadow--natural);',
)

Without this PR the command fails with a fatal error for an undefined function.

Use of AI

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: the port from Gutenberg and the tests; I reviewed and edited them.

@github-actions

github-actions Bot commented Nov 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

  • 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
aaronrobertshaw marked this pull request as ready for review November 5, 2026 07:12
@github-actions

github-actions Bot commented Nov 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.

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

Props aaronrobertshaw, westonruter.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport is accurate. I smoke tested a bunch of blocks on the frontend, checked the CSS and classnames.

Tests pass locally.

Might be worth holding off until 7.2 is stable to avoid clashes?

Thanks!

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.

3 participants