Skip to content

Block Supports: Add PHP helpers for block support classes and styles - #14094

Draft
aaronrobertshaw wants to merge 2 commits into
WordPress:trunkfrom
aaronrobertshaw:backport/php-support-style-helpers
Draft

aaronrobertshaw wants to merge 2 commits into
WordPress:trunkfrom
aaronrobertshaw:backport/php-support-style-helpers

Conversation

@aaronrobertshaw

Copy link
Copy Markdown

Backport of Gutenberg PRs

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

Adds PHP helpers that turn block attributes into a block support's classes and styles, like the JS get*ClassesAndStyles() functions, and moves the block supports onto them.

This PR backports:

  • wp_get_border_classes_and_styles(), wp_get_shadow_classes_and_styles(), wp_get_spacing_classes_and_styles(), wp_get_color_classes_and_styles() and wp_get_background_classes_and_styles(),
  • wp_apply_border_support(), wp_apply_shadow_support(), wp_apply_spacing_support(), wp_apply_colors_support() and wp_render_background_support() built on them,
  • and the accompanying block supports tests.

The block changes that call these helpers (Avatar, Post Featured Image, Icon, Post Navigation Link, Navigation Submenu, Comment Author Avatar, Calendar and Button) arrive later with the Gutenberg package update.

Dependency: #13491 (background clip). This branch is based on it, so it shows that commit until #13491 merges.

Testing instructions

The block support output should be identical to #13491 on its own. To compare, register a dynamic test block and render it on each branch:

npm run env:cli -- eval "register_block_type( 'test/helpers', array( 'api_version' => 3, 'supports' => array( 'color' => array( 'text' => true, 'background' => true ), '__experimentalBorder' => array( 'color' => true, 'radius' => true, 'style' => true, 'width' => true ), 'shadow' => true, 'spacing' => array( 'padding' => true, 'margin' => true ), 'background' => array( 'backgroundImage' => true, 'gradient' => true ) ), 'render_callback' => static function () { return '<div ' . get_block_wrapper_attributes() . '></div>'; } ) ); echo do_blocks( '<!-- wp:test/helpers {\"borderColor\":\"contrast\",\"textColor\":\"base\",\"backgroundColor\":\"accent\",\"style\":{\"border\":{\"radius\":\"8px\",\"width\":\"2px\",\"style\":\"solid\",\"top\":{\"width\":\"4px\",\"color\":\"#3858e9\",\"style\":\"dashed\"}},\"shadow\":\"6px 6px 9px #00000033\",\"spacing\":{\"padding\":{\"top\":\"20px\",\"left\":\"var:preset|spacing|40\"},\"margin\":{\"top\":\"10px\"}},\"background\":{\"backgroundImage\":{\"url\":\"https://example.com/image.jpg\"},\"backgroundSize\":\"contain\"}}} /-->' );"

Both branches output:

<div style="border-radius:8px;border-style:solid;border-width:2px;border-top-width:4px;border-top-color:#3858e9;border-top-style:dashed;padding-top:20px;padding-left:var(--wp--preset--spacing--40);margin-top:10px;box-shadow:6px 6px 9px #00000033;background-image:url(&apos;https://example.com/image.jpg&apos;);background-position:50% 50%;background-size:contain;" class="wp-block-test-helpers has-text-color has-base-color has-background has-accent-background-color has-border-color has-contrast-border-color"></div>

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.

Adds a background.backgroundClip block support, so a block can set which
box its background is painted into: border-box, padding-box, content-box,
or the text itself. Clipping to the text is what gives blocks a gradient
text fill.

Registers the property in the style engine and theme.json, allows the
declarations through KSES, and skips the has-background class when the
background is clipped to the text.

Props aaronrobertshaw.
See #66094.
@github-actions

github-actions Bot commented Oct 8, 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

Copy link
Copy Markdown
Author

I've been held up on some other priorities so this one will now be aimed for WP 7.3

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.

1 participant