Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#54448 closed defect (bug) (fixed)

Missing rest api endpoint when exporting templates and template parts

Reported by: walbo's profile walbo Owned by: timothyblynjacobs's profile TimothyBlynJacobs
Milestone: 5.9 Priority: normal
Severity: normal Version: 5.9
Component: Editor Keywords: has-patch has-unit-tests
Focuses: rest-api Cc:

Description

In the Gutenberg plugin a rest api endpoint wp-json/__experimental/edit-site/v1/export are added and used when you export your templates.

This endpoint are missing in 5.9 and the export function isn't working.

Steps to reproduce:

  1. Active twenty twenty two theme.
  2. Goto: Appearance > Editor (beta)
  3. Click on "More tools & options" (the menu in the top right corner)
  4. Click on "Export"
  5. Nothing happends. Check network and confirm the endpoint it tries to use doesn't exist.

Change History (31)

#1 @TimothyBlynJacobs
3 years ago

  • Focuses rest-api added
  • Milestone changed from Awaiting Review to 5.9

Cc: @noisysocks. We should stabilize this endpoint first as well. Probably also should go into wp-block-editor/v1.

#2 @hellofromTonya
3 years ago

  • Keywords needs-patch added

@TimothyBlynJacobs Rob (@noisysocks) likely isn't online in time for 5.9 Beta 1 release today. Is this something that can be fixed before today's release?

#3 @TimothyBlynJacobs
3 years ago

This is being worked on in https://github.com/WordPress/gutenberg/issues/36515. I'll handle the commit for it if it is ready in time.

#4 @desrosj
2 years ago

Looks like this was fixed in GB-36559. @TimothyBlynJacobs are you able to sync that trunk at some point today?

#5 @TimothyBlynJacobs
2 years ago

  • Owner set to TimothyBlynJacobs
  • Status changed from new to assigned

Yep, can do!

This ticket was mentioned in PR #1936 on WordPress/wordpress-develop by Mamaduka.


2 years ago
#6

  • Keywords has-patch has-unit-tests added; needs-patch removed

Mamaduka commented on PR #1936:


2 years ago
#7

@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 commented on PR #1936:


2 years ago
#8

@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 commented on PR #1936:


2 years ago
#9

Thanks, @desrosj.

Fixtures are updated now.

Mamaduka commented on PR #1936:


2 years ago
#10

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.

Mamaduka commented on PR #1936:


2 years ago
#11

Thanks, @walbo.

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


2 years ago

peterwilsoncc commented on PR #1936:


2 years ago
#13

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

This ticket was mentioned in Slack in #core-restapi by hellofromtonya. View the logs.


2 years ago

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


2 years ago

#16 @hellofromTonya
2 years ago

  • Keywords commit added

@TimothyBlynJacobs shared in Slack:

Looks good to me. I’d say go ahead and commit it.

Marking PR 1936 for commit.

#17 @spacedmonkey
2 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 52286:

Site Editor: Add site export REST API endpoint.

Add a REST API to export site templates and template part as html files. When the REST API is requested, it responds by downloading a single ZIP file and exits early, without completing full request. To create the exported zip, the ZipArchive class is required. If this class is not present then the export will gracefully fail, returning a WP_Error object and 500 status error code.

Props spacedmonkey, youknowriad, Mamaduka, walbo, peterwilsoncc.
Fixes #54448 .

Mamaduka commented on PR #1936:


2 years ago
#18

Thanks for the fantastic feedback, @peterwilsoncc.

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

#19 @dlh
2 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

[52286] doesn't return the error in \WP_REST_Edit_Site_Export_Controller::permissions_check(), only creates it. The method always returns true. The error code also appears to be copied from \WP_REST_URL_Details_Controller.

#22 @spacedmonkey
2 years ago

Good catch @dlh .

I created a patch and added some much needed until tests in #2008.

spacedmonkey commented on PR #2008:


2 years ago
#23

CC @dlh01

dlh01 commented on PR #2007:


2 years ago
#24

Now #2008.

spacedmonkey commented on PR #2008:


2 years ago
#25

CC @Mamaduka

Mamaduka commented on PR #2008:


2 years ago
#26

Thanks for the follow-up, @spacedmonkey. The code looks good to me.

TimothyBJacobs commented on PR #2008:


2 years ago
#27

Great catch @dlh01, thanks for that!

This looks fine to me @spacedmonkey. If you wanted, we could consider instead making an OPTIONS request and checking the Allow header. That way, if the test fails, it doesn't kill the test suite execution because of the die() call. But I think this is fine as is.

#28 @hellofromTonya
2 years ago

  • Keywords commit removed

Resetting the commit keyword which applied to the patch before the ticket was reopened.

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


2 years ago

#30 @spacedmonkey
2 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 52340:

REST API: Ensure that the export template endpoint returns a valid WP_Error object.

Ensure that the export template endpoint returns a WP_Error object, including code and message, so that the site editor can display an error message.
Add some basic unit tests to ensure that permission checks are working as expected.

Follow-up to [52286].

Props Spacedmonkey, dlh, hellofromTonya , Mamaduka, TimothyBlynJacobs.
Fixes #54448.

This ticket was mentioned in Slack in #core by costdev. View the logs.


2 years ago

Note: See TracTickets for help on using tickets.