Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global styles: block background UI controls #6836

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Jun 17, 2024

Syncing source code changes from WordPress/gutenberg#60100

Enables background images for supported blocks in global styles.

Testing

This PR adds the backend functionality only, which means the editor UI isn't yet available.

To test, define some background images for blocks. Here's an example using some of the images in src/wp-content/themes/twentytwentyfour/

{
	"$schema": "../../schemas/json/theme.json",
	"version": 3,
	"settings": {
		"appearanceTools": true
	},
	"styles": {
		"blocks": {
			"core/verse": {
				"background": {
					"backgroundImage": {
						"url": "file:./assets/images/art-gallery.webp"
					}
				}
			},
			"core/quote": {
				"background": {
					"backgroundImage": {
						"url": "file:./assets/images/building-exterior.webp"
					}
				}
			},
			"core/pullquote": {
				"background": {
					"backgroundImage": {
						"url": "file:./assets/images/hotel-facade.webp"
					}
				}
			},
			"core/post-content": {
				"background": {
					"backgroundImage": {
						"url": "file:./assets/images/windows.webp"
					}
				}
			}
		}
	}
}

Here is some test HTML to create a test post:

<!-- wp:verse {"style":{"elements":{"link":{"color":{"text":"var:preset|color|base-2"}}},"spacing":{"padding":{"top":"var:preset|spacing|60","bottom":"var:preset|spacing|60","left":"var:preset|spacing|60","right":"var:preset|spacing|60"}}},"textColor":"base-2","fontSize":"x-large"} -->
<pre class="wp-block-verse has-base-2-color has-text-color has-link-color has-x-large-font-size" style="padding-top:var(--wp--preset--spacing--60);padding-right:var(--wp--preset--spacing--60);padding-bottom:var(--wp--preset--spacing--60);padding-left:var(--wp--preset--spacing--60)">Verse</pre>
<!-- /wp:verse -->

<!-- wp:pullquote {"style":{"elements":{"link":{"color":{"text":"var:preset|color|base-2"}}}},"textColor":"base-2","fontSize":"x-large"} -->
<figure class="wp-block-pullquote has-base-2-color has-text-color has-link-color has-x-large-font-size"><blockquote><p>Pullquote</p></blockquote></figure>
<!-- /wp:pullquote -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph {"style":{"spacing":{"padding":{"top":"var:preset|spacing|60","bottom":"var:preset|spacing|60","left":"var:preset|spacing|60","right":"var:preset|spacing|60"}},"elements":{"link":{"color":{"text":"var:preset|color|base-2"}}}},"textColor":"base-2","fontSize":"x-large"} -->
<p class="has-base-2-color has-text-color has-link-color has-x-large-font-size" style="padding-top:var(--wp--preset--spacing--60);padding-right:var(--wp--preset--spacing--60);padding-bottom:var(--wp--preset--spacing--60);padding-left:var(--wp--preset--spacing--60)">Quote</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->

The editor and frontend should display the background images:

Screenshot 2024-07-08 at 12 54 27 PM

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


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

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.

output any background styles, even if there's no background image - this is so users can extend/overwrite theme.json styles
@ramonjd ramonjd force-pushed the add/background-global-styles-panel-for-blocks branch from 210feca to 9b4a6eb Compare July 8, 2024 02:40
@ramonjd ramonjd self-assigned this Jul 8, 2024
@ramonjd ramonjd marked this pull request as ready for review July 8, 2024 02:58
Copy link

github-actions bot commented Jul 8, 2024

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 ramonopoly, aaronrobertshaw, noisysocks.

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

Copy link

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together @ramonjd 👍

✅ Theme.json defined background images display in editors and frontend
✅ Code changes match GB PR

Editor Frontend
Screenshot 2024-07-08 at 3 07 02 PM Screenshot 2024-07-08 at 3 07 14 PM

I left a few minor nits as inline comments.

src/wp-includes/class-wp-theme-json-resolver.php Outdated Show resolved Hide resolved
src/wp-includes/class-wp-theme-json-resolver.php Outdated Show resolved Hide resolved
@aaronrobertshaw
Copy link

Thanks for adding the @ticket comments, missed those in my review, sorry.

Latest changes LGTM 🚀

@ramonjd
Copy link
Member Author

ramonjd commented Jul 8, 2024

I appreciate the quick review!

@noisysocks
Copy link
Member

Committed in r58797.

@noisysocks noisysocks closed this Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants