Skip to content

Block Supports: Add background gradient support that can combine with background image - #11384

Closed
aaronrobertshaw wants to merge 8 commits into
WordPress:trunkfrom
aaronrobertshaw:add/background-gradient-support
Closed

aaronrobertshaw wants to merge 8 commits into
WordPress:trunkfrom
aaronrobertshaw:add/background-gradient-support

Conversation

@aaronrobertshaw

@aaronrobertshaw aaronrobertshaw commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

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

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

WordPress/gutenberg#75859

Description

Adds background.gradient as a new block support, enabling blocks to combine a background gradient with a background image via comma-separated
background-image CSS values (e.g., background-image: linear-gradient(...), url(...)).

Currently, the only way to apply a gradient is through color.gradient, which renders as a background CSS shorthand and conflicts with background image
properties. By introducing background.gradient (stored at style.background.gradient), gradients become part of the background style group, allowing the
style engine to combine gradient and image values without conflict.

See: WordPress/gutenberg#32787 and WordPress/gutenberg#75859

Testing

  1. Ensure PHP unit tests pass: npm run test:php -- --filter="Tests_Block_Supports_WpRenderBackgroundSupport|Tests_Block_Supports_Colors|Tests_wpStyleEngine|test_get_background_gradient|test_remove_insecure_p roperties_allows_combined|test_remove_insecure_properties_allows_background_gradient|test_get_settings_appearance_true"
  2. In a theme.json file, define a background gradient for the Group block using the new styles.blocks.core/group.background.gradient property (e.g.,
    "gradient": "linear-gradient(135deg, #000 0%, #fff 100%)"). Verify the gradient renders correctly on the frontend.
  3. Also set a backgroundImage on the same Group block and confirm both values combine into a single background-image CSS declaration.
  4. Verify existing style.color.gradient support continues to work on blocks that don't opt into background.gradient.
  5. On a block that supports both, set both style.color.gradient and style.background.gradient — confirm background.gradient takes precedence and the
    color.gradient shorthand is suppressed.

@github-actions

github-actions Bot commented Mar 28, 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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @1178653+wordpress-develop-pr-bot[bot]@users.noreply.github.com.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Props aaronrobertshaw, ramonopoly, wildworks.

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

@github-actions

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.

@ramonjd

ramonjd commented Jun 30, 2026

Copy link
Copy Markdown
Member

Sorry I've kept this waiting for so long. Just rediscovered after working on #12361

I can give it a test tomorrow - is there anything we're waiting on to get this?

@aaronrobertshaw

Copy link
Copy Markdown
Contributor Author

I believe everything should be good to go with this but as it has sat for a while, I'll need to give it a rebase first

@aaronrobertshaw
aaronrobertshaw force-pushed the add/background-gradient-support branch from af7cdca to 626797e Compare June 30, 2026 23:28
@aaronrobertshaw

Copy link
Copy Markdown
Contributor Author

Actually, turns out I missed updating the core function to allow combined gradients and backgrounds properly via kses.

I've updated that now but the original Gutenberg PR only allowed modern color functions within gradients when combined with a background. I've tweaked that here so that it is consistent and they are supported for standalone gradients as well.

This will need backporting to Gutenberg so I'll spin up a PR doing that this evening or tomorrow.

@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 files check out against WordPress/gutenberg#75859

Test ticket annotations LGTM

I manually tested this (the latest GB release has been merged into Core already) and it's working as expected:

  • existing gradients and images behave
  • migrates existing color.gradient to background.gradient on save
  • image and gradient values combined in background-image

Tested theme.json in TT5 e.g.,

			"core/group": {
				"background": {
					"backgroundImage": {
						"url": "file:./assets/images/book-image-landing.webp"
					},
					"gradient": "linear-gradient(135deg,rgba(0,0,0,0.48) 1%,rgba(255,255,255,0.47) 100%)"
				}
			},

@aaronrobertshaw

Copy link
Copy Markdown
Contributor Author

I've backported to Gutenberg the changes here allowing modern color definitions within standalone gradients in WordPress/gutenberg#79791

@ramonjd

ramonjd commented Jul 3, 2026

Copy link
Copy Markdown
Member

This one good to go you reckon?

@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.

@ramonjd

ramonjd commented Jul 13, 2026

Copy link
Copy Markdown
Member

@aaronrobertshaw do you need help landing this one?

@ramonjd
ramonjd force-pushed the add/background-gradient-support branch from f73f017 to c3100dc Compare July 13, 2026 02:28
@ramonjd

ramonjd commented Jul 13, 2026

Copy link
Copy Markdown
Member

I rebased this and retested. I think it's good to go.

Comment thread src/wp-includes/block-supports/colors.php
Comment thread src/wp-includes/kses.php Outdated
aaronrobertshaw and others added 8 commits July 14, 2026 11:36
… tests

Add `@since 7.1.0` notes to `safecss_filter_attr()` and
`wp_apply_colors_support()`, clarify the inline comment on the gradient
matching in `safecss_filter_attr()`, and extend the
`data_safecss_filter_attr()` provider to cover combined gradient + image
values, modern colour functions, bounded nesting, and the widened
single-level nested-function allowance.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ramonjd
ramonjd force-pushed the add/background-gradient-support branch from f1410ad to 13b9f5b Compare July 14, 2026 01:36
@ramonjd

ramonjd commented Jul 14, 2026

Copy link
Copy Markdown
Member

I'll go ahead and commit this today

@ramonjd

ramonjd commented Jul 14, 2026

Copy link
Copy Markdown
Member

Comitted in r62718 / 6b190c6

@ramonjd ramonjd closed this Jul 14, 2026
ramonjd added a commit to ramonjd/wordpress-develop that referenced this pull request Jul 14, 2026
…g PR 79568.

Assumes background gradient support from WordPress#11384.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@aaronrobertshaw

Copy link
Copy Markdown
Contributor Author

Thank you very much for picking this up and getting it committed @ramonjd 🙇

@ramonjd

ramonjd commented Jul 14, 2026

Copy link
Copy Markdown
Member

No worries. It's a long time coming, thanks for working on it and fixing it

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.

3 participants