Skip to content

Conversation

@Mamaduka
Copy link
Member

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.

@Mamaduka
Copy link
Member Author

@TimothyBJacobs I'm not sure how to fix the fixtures/wp-api-generated.js error. Can you point me to developer documentation on how to fix this?

@desrosj
Copy link
Member

desrosj commented Nov 24, 2021

@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 npm script to make that easier and more clear how to accomplish that.

@Mamaduka
Copy link
Member Author

Thanks, @desrosj.

Fixtures are updated now.

*
* @return string Updated wp_template content.
*/
function _remove_theme_attribute_in_block_template_content( $template_content ) {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

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.

Copy link
Contributor

@youknowriad youknowriad left a 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

@Mamaduka
Copy link
Member Author

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 function_exists guard clause.

Copy link
Member

@walbo walbo left a 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 👍

Mamaduka and others added 3 commits November 29, 2021 05:02
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]>
@Mamaduka
Copy link
Member Author

Thanks, @walbo.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a 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' ) ) {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Contributor

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.

Comment on lines +886 to +888
if ( ! class_exists( 'ZipArchive' ) ) {
return new WP_Error( __( 'Zip Export not supported.' ) );
}
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member

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
@peterwilsoncc
Copy link
Contributor

@Mamaduka I've merged trunk in to your branch to resolve some merge conflicts

Mamaduka and others added 4 commits November 30, 2021 05:20
Co-authored-by: Peter Wilson <[email protected]>
Co-authored-by: Peter Wilson <[email protected]>
Co-authored-by: Peter Wilson <[email protected]>
@spacedmonkey spacedmonkey self-requested a review November 30, 2021 13:44
@spacedmonkey spacedmonkey self-assigned this Nov 30, 2021
Copy link
Contributor

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

Comment on lines +902 to +910
/**
* 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.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* 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 ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$this->assertEquals( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) );
$this->assertSame( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) );

Comment on lines +67 to +68
/**
* Output a ZIP file with an export of the current templates
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* 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/

@Mamaduka
Copy link
Member Author

Mamaduka commented Dec 5, 2021

Thanks for the fantastic feedback, @peterwilsoncc.

I always struggle with DocBlock comments. Now that API got merged, should I create separate PR for those.

@Mamaduka Mamaduka deleted the add/edit-site-export branch April 7, 2022 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants