-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
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() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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()
Flaky tests detected in ccd2ac4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9199960175
|
672abbf
to
08755b1
Compare
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. |
08755b1
to
89579ac
Compare
There was a problem hiding this 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 🤔
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? |
Yep, that sounds good to me. I'd lean toward |
Done! |
7392963
to
25b71f0
Compare
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 |
…nges to theme json and resolver.
…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.
25b71f0
to
ccd2ac4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is testing nicely for me in a WP 6.5.3 testing environment, with the background image data now included in the export:
Also double-checked that the diffs between the included functions and those in wordpress-develop
match, aside from the changes here that reference Gutenberg versions of classes and functions.
LGTM 🚀
I appreciate the thorough review @andrewserong This is a good one to get in 👍🏻 |
…sses (WordPress#61561) * This ensures that any theme exports get the benefit of the latest changes to theme json and resolver. * check for function exists. * Moving changes to `/lib` folder because none of the changes are backwards 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. * Add to version control would help * Added i18n domain Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Should this be backported for WP 6.6? If so, please add the |
This one is just Gutenberg - it's got the label "No Core Sync Required" 👍🏻 |
…sses (WordPress#61561) * This ensures that any theme exports get the benefit of the latest changes to theme json and resolver. * check for function exists. * Moving changes to `/lib` folder because none of the changes are backwards 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. * Add to version control would help * Added i18n domain Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
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.
Save the site
Export your theme
Check the exported theme.json - your background styles should be featured in
style.background
.Example snippet from my exported theme.json: