Automattic / Automattic/jetpack
WPCOM API: restoring an image to original in Calypso fails.
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
After editing (cropping) an image in Calypso an attempt to restore it to its original state fails.
#### Steps to reproduce the issue
1. Go to the media library in Calypso for a Jetpack site.
2. Click on any image (upload one if there's none).
3. Crop it in the editor.
4. Click the "Restore original" button.
#### What I expected
An image to be restored to its original dimensions.
#### What happened instead
The request fails, the spinner never stops spinning, the image is not restored. The UI is locked, only a refresh helps. If you're looking at the logs, you'll see something like this:
```
NOTICE: PHP message: PHP Fatal error: Uncaught Error: Call to undefined function wpcom_get_private_file() in /var/dev/wordpress/wp-content/plugins/jetpack/json-endpoints/class.wpcom-json-api-edit-media-v1-2-endpoint.php:296
Stack trace:
#0 /var/dev/wordpress/wp-content/plugins/jetpack/json-endpoints/class.wpcom-json-api-edit-media-v1-2-endpoint.php(370): WPCOM_JSON_API_Edit_Media_v1_2_Endpoint->build_file_array_from_url('8051', 'https://lousy.s...')
#1 /var/dev/wordpress/wp-content/plugins/jetpack/class.json-api.php(346): WPCOM_JSON_API_Edit_Media_v1_2_Endpoint->callback('/sites/10281254...', 1, '8051')
#2 /var/dev/wordpress/wp-content/plugins/jetpack/class.json-api.php(330): WPCOM_JSON_API->process_request(Object(WPCOM_JSON_API_Edit_Media_v1_2_Endpoint), Array)
#3 /var/dev/wordpress/wp-content/plugins/jetpack/packages/connection/legacy/class-jetpack-xmlrpc-server.php(914): WPCOM_JSON_API->serve(false)
#4 /var/dev/wordpress/wp-includes/IXR/class-IXR-server.php(127): Jetpack_XMLRPC_Server->json_api(Array)...
```
Contributor guide
Research direction
Start in wp-content/plugins/jetpack/json-endpoints/class.wpcom-json-api-edit-media-v1-2-endpoint.php, especially build_file_array_from_url() around line 296, then follow callback() around line 370. Reproduce the Restore original flow for a Jetpack site and inspect why the request fails. Done means the original dimensions are restored, the request completes, and the spinner stops without requiring a refresh.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100