-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Site Editor: Add missing export endpoint #1936
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
Conversation
|
@TimothyBJacobs I'm not sure how to fix the |
|
@Mamaduka You need to run the REST API unit tests in PHP, and then a new version of that file will get generated! We should add an |
|
Thanks, @desrosj. Fixtures are updated now. |
| * | ||
| * @return string Updated wp_template content. | ||
| */ | ||
| function _remove_theme_attribute_in_block_template_content( $template_content ) { |
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.
I don't know how we organize things in general in Core but for me, I don't think we should change this file as the added functions are specific to the export behavior and could be moved to the export controller directly (private methods there) or their own file. WDYT?
I see this file as the API to fetch block templates and template parts.
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.
We can't test the private method in PHP, but we can make it public.
Also, make sense to have a remove method when we have an inject one.
I don't know how we organize things in general in Core
I'm also not sure about this. I talked with @noisysocks, and we decided to keep these methods in the utils file for now.
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.
Mmm, I don't like that we're kind of changing the role of the "utils" file but I can live with it. We should also do the same in the plugin if we go that road to keep the files similar to easy backports...
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.
Done - WordPress/gutenberg#36908
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.
Initially, I was planning to have these methods private, but then I got reminded that public API could be helpful for WP CLI and similar tools - WordPress/gutenberg#36559 (comment).
Maybe we can have a separate file for site export methods once API is more mature in the future.
youknowriad
left a comment
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.
Do you think there's a chance of things breaking in the Gutenberg plugin if we commit this? I guess we should potentially follow-up and move this code in the Gutenberg plugin into compat/wordpress-5.9
|
Thanks for the reminder. I need to rename the method in Gutenberg, and we should be good. All methods and files are in the compat folder and have the |
walbo
left a comment
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.
A few gutenberg texdomains that shouldn't be in core. Other than that it looks good to me 👍
src/wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Petter Walbø Johnsgård <[email protected]>
Co-authored-by: Petter Walbø Johnsgård <[email protected]>
…ort-controller.php Co-authored-by: Petter Walbø Johnsgård <[email protected]>
|
Thanks, @walbo. |
peterwilsoncc
left a comment
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.
I've added a few notes inline.
| * @return WP_Error|bool True if the request has access, or WP_Error object. | ||
| */ | ||
| public function permissions_check() { | ||
| if ( current_user_can( 'edit_theme_options' ) ) { |
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.
There is a capability export that is usually used for exporting site contents but I am wondering if it should be checked here too? If so, possibly in addition to edit_theme_options to make sure the has permission to view what they are exporting.
I'll need to consider this, I don't have an answer as to whether it's needed or not as yet.
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.
I'm also not sure, so I kept the cap that was used in the original code. I think we might need new caps for block theme exports in the long run.
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.
Yeah I don't have a solid answer either. As you said, I think export is more on the side of site data, whereas this is less about site content but appearance. It feels like it may be a candidate for a dedicated meta capability that maps to both by default?
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.
Thanks both. Let's consider this but not treat is as a blocker for getting this patch in. As is, I think the permission check is fit for purpose.
| if ( ! class_exists( 'ZipArchive' ) ) { | ||
| return new WP_Error( __( 'Zip Export not supported.' ) ); | ||
| } |
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.
Is the UI hidden if ZipArchive is unavailable?
This line will be needed even if it is but I just want to make sure it is.
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.
Currently, UI is always visible since we will have to make a new request to check if ZipArchive is available.
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.
In my testing, the export feature did not fail gracefully.
Screen.Recording.2021-11-30.at.16.33.44.mov
# Conflicts: # src/wp-includes/rest-api.php # src/wp-settings.php # tests/qunit/fixtures/wp-api-generated.js
|
@Mamaduka I've merged trunk in to your branch to resolve some merge conflicts |
Co-authored-by: Peter Wilson <[email protected]>
Co-authored-by: Peter Wilson <[email protected]>
Co-authored-by: Peter Wilson <[email protected]>
peterwilsoncc
left a comment
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.
Thanks for those changes, functional code changes all look good.
I missed a couple of docblocks that need a short summary in my review yesterday, sorry, have added some suggestions inline.
| /** | ||
| * Creates an export of the current templates and | ||
| * template parts from the site editor at the | ||
| * specified path in a ZIP file. | ||
| * | ||
| * @since 5.9.0 | ||
| * | ||
| * @return WP_Error|string Path of the ZIP file or error on failure. | ||
| */ |
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.
| /** | |
| * Creates an export of the current templates and | |
| * template parts from the site editor at the | |
| * specified path in a ZIP file. | |
| * | |
| * @since 5.9.0 | |
| * | |
| * @return WP_Error|string Path of the ZIP file or error on failure. | |
| */ | |
| /** | |
| * Generate export file for block templates. | |
| * | |
| * Creates an export of the current templates and | |
| * template parts from the site editor at the | |
| * specified path in a ZIP file. | |
| * | |
| * @since 5.9.0 | |
| * | |
| * @return WP_Error|string Path of the ZIP file or error on failure. | |
| */ |
| * @dataProvider data_remove_theme_attribute_in_block_template_content | ||
| */ | ||
| function test_remove_theme_attribute_in_block_template_content( $template_content, $expected ) { | ||
| $this->assertEquals( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) ); |
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->assertEquals( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) ); | |
| $this->assertSame( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) ); |
| /** | ||
| * Output a ZIP file with an export of the current templates |
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.
| /** | |
| * Output a ZIP file with an export of the current templates | |
| /** | |
| * Output ZIP archive of export. | |
| * | |
| * Output a ZIP file with an export of the current templates |
Another one that really needs a short summary ahead of the description.
The first line is pulled out as a short summary in the developer docs, for example https://developer.wordpress.org/reference/functions/wp_remote_get/
|
Thanks for the fantastic feedback, @peterwilsoncc. I always struggle with DocBlock comments. Now that API got merged, should I create separate PR for those. |
Part of WordPress/gutenberg#36559
Trac ticket: https://core.trac.wordpress.org/ticket/54448
/cc @TimothyBJacobs @desrosj
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.