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

Site Export: ensure that the export endpoint uses Gutenberg theme classes #61561

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented May 10, 2024

What?

Extending the WP_REST_Edit_Site_Export_Controller endpoint to use Gutenberg theme methods.

Note

This PR doesn't require backporting - the code is taken from existing Core methods/functions from 6.0/5.9. The references to Core classes and functions have been changed to _Gutenberg/gutenberg_ only.

Why?

Like it says in the title, ensure that the export endpoint uses Gutenberg theme classes.

It makes sure that theme exports get the benefit of the latest changes to theme json and resolver.

For example, style.background is a new theme.json style property, but it won't be exported by the Core endpoint until version 6.6.

This endpoint hasn't had any backwards compat extensions in Gutenberg for the last few releases and probably further back so it's probably worth doing.

How?

Copying over the public methods and swapping WP functions/methods with Gutenberg ones 😄

The changes live in the /lib folder because none of the changes are backwards compat specific. Props to @andrewserong for pointing this out 😄

Having this extension permanently in Gutenberg means that theme.json exporting will always use the latest version of the Theme JSON family of classes.

Testing Instructions

Add a background image to a site in the site editor.

Screenshot 2024-05-10 at 5 18 15 pm

Save the site

Export your theme

Screenshot 2024-05-10 at 5 18 23 pm

Check the exported theme.json - your background styles should be featured in style.background.

Example snippet from my exported theme.json:

	"styles": {
		"background": {
			"backgroundImage": {
				"id": 26,
				"source": "file",
				"title": "pizza1",
				"url": "http://localhost:8888/wp-content/uploads/2024/05/pizza1.jpg"
			}
		},
		"color": {
			"text": "#333"
		}
	},

@ramonjd ramonjd added [Type] Bug An existing feature does not function as intended [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") labels May 10, 2024
@ramonjd ramonjd self-assigned this May 10, 2024
Copy link

github-actions bot commented May 10, 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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>

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

*
* @return WP_Error|string Path of the ZIP file or error on failure.
*/
function gutenberg_generate_block_templates_export_file() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is all just copy paste and swapping out the WP functions for the Gutenberg juicy goodness.

*
* @return WP_Error|void
*/
public function export() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Also a 1:1 copy but using gutenberg_generate_block_templates_export_file()

lib/load.php Outdated Show resolved Hide resolved
Copy link

github-actions bot commented May 10, 2024

Flaky tests detected in ccd2ac4.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9199960175
📝 Reported issues:

@ramonjd ramonjd force-pushed the update/rest-edit-site-export-controller branch from 672abbf to 08755b1 Compare May 10, 2024 22:27
@ramonjd
Copy link
Member Author

ramonjd commented May 13, 2024

Example snippet from my exported theme.json:

Gutenberg preserves the id/source/title props added by block upload.

				"id": 26,
				"source": "file",
				"title": "pizza1",

I guess they should be reflected in theme.json at some point.

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

This is testing well for me, with the output containing the uploaded image and metadata stored via the uploaded version of the image:

	"styles": {
		"background": {
			"backgroundImage": {
				"id": 4727,
				"source": "file",
				"title": "neuschwastein-castle-5",
				"url": "http://a-toule-site.local/wp-content/uploads/2024/01/neuschwastein-castle-5.jpg"
			}
		},

One thought while looking at the code change — is there anything about this change that's particular to 6.6 or requires backporting? If not, would it be better to include these changes in either /lib or /lib/experimental to both flag that no backporting is required, and so that the GB versions are still present for subsequent releases? Otherwise, we might wind up needing to re-add the files further down the track when the 6.6 compat directory is eventually removed 🤔

@ramonjd
Copy link
Member Author

ramonjd commented May 13, 2024

One thought while looking at the code change — is there anything about this change that's particular to 6.6 or requires backporting? If not, would it be better to include these changes in either /lib or /lib/experimental to both flag that no backporting is required, and so that the GB versions are still present for subsequent releases? Otherwise, we might wind up needing to re-add the files further down the track when the 6.6 compat directory is eventually removed

Oh yeah, that's a very good point 😄

I think I was hypnotized by the fact that background images in theme.json is a 6.6 feature, but you're right, this will be an ongoing concern so it should be maybe in lib, next to global styles controller? What do you reckon?

@andrewserong
Copy link
Contributor

so it should be maybe in lib, next to global styles controller

Yep, that sounds good to me. I'd lean toward lib if it's identical to wordpress-develop except for calling GB versions of things, and lib/experimental if it's making changes that aren't present in core.

@ramonjd ramonjd requested a review from youknowriad May 13, 2024 05:24
@ramonjd ramonjd added the Backwards Compatibility Issues or PRs that impact backwards compatability label May 13, 2024
@ramonjd
Copy link
Member Author

ramonjd commented May 20, 2024

Yep, that sounds good to me. I'd lean toward lib if it's identical to wordpress-develop except for calling GB versions of things, and lib/experimental if it's making changes that aren't present in core.

Done!

@ramonjd ramonjd force-pushed the update/rest-edit-site-export-controller branch from 7392963 to 25b71f0 Compare May 20, 2024 21:47
Copy link

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/block-template-utils.php
❔ lib/class-wp-rest-edit-site-export-controller-gutenberg.php
❔ lib/load.php
❔ lib/rest-api.php

…ards compat specific.

Having this extension permanently in Gutenberg means that theme.json exporting will always use the latest version of the Theme JSON family of classes.
@ramonjd ramonjd force-pushed the update/rest-edit-site-export-controller branch from 25b71f0 to ccd2ac4 Compare May 22, 2024 23:58
@ramonjd ramonjd added Backport from WordPress Core Pull request that needs to be backported to the a Gutenberg release from WordPress Core Backwards Compatibility Issues or PRs that impact backwards compatability No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core and removed Backwards Compatibility Issues or PRs that impact backwards compatability Backport from WordPress Core Pull request that needs to be backported to the a Gutenberg release from WordPress Core labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants