diff --git a/lib/class-wp-rest-image-editor-controller.php b/lib/class-wp-rest-image-editor-controller.php index 76afc5edc9a563..66c8531e02d7ed 100644 --- a/lib/class-wp-rest-image-editor-controller.php +++ b/lib/class-wp-rest-image-editor-controller.php @@ -300,6 +300,12 @@ public function apply_edits( $request ) { return $new_attachment_id; } + if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { + // Set a custom header with the attachment_id. + // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. + header( 'X-WP-Upload-Attachment-ID: ' . $new_attachment_id ); + } + // Generate image sub-sizes and meta. $new_image_meta = wp_generate_attachment_metadata( $new_attachment_id, $saved['path'] ); diff --git a/packages/block-library/src/image/image-editor.js b/packages/block-library/src/image/image-editor.js index 361355ee8d9a5d..d3bc19f6ee98dc 100644 --- a/packages/block-library/src/image/image-editor.js +++ b/packages/block-library/src/image/image-editor.js @@ -195,7 +195,7 @@ export default function ImageEditor( { attrs.src = url; apiFetch( { - path: `wp/v2/media/${ id }/edit`, + path: `/wp/v2/media/${ id }/edit`, method: 'POST', data: attrs, } )