mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Upload: Fix the method used to create image sub-sizes when uploading fails with a PHP fatal error. Use a custom header to send the new attachment post ID even in HTTP 500 responses instead of an upload reference sent by the client. Also add another cap check and remove the action when deleting an attachment post during a failed upload cleanup.
Props timothyblynjacobs, clorith, azaozz. Fixes #48200. git-svn-id: https://develop.svn.wordpress.org/trunk@46382 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -251,6 +251,12 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
|
||||
return $image_meta;
|
||||
}
|
||||
|
||||
// Set a custom header with the attachment_id.
|
||||
// Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
|
||||
if ( ! headers_sent() ) {
|
||||
header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
|
||||
}
|
||||
|
||||
// Resize the image
|
||||
$resized = $editor->resize( $threshold, $threshold );
|
||||
$rotated = null;
|
||||
@@ -273,6 +279,8 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
|
||||
if ( true === $rotated && ! empty( $image_meta['image_meta']['orientation'] ) ) {
|
||||
$image_meta['image_meta']['orientation'] = 1;
|
||||
}
|
||||
|
||||
wp_update_attachment_metadata( $attachment_id, $image_meta );
|
||||
} else {
|
||||
// TODO: handle errors.
|
||||
}
|
||||
@@ -289,6 +297,10 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
|
||||
return $image_meta;
|
||||
}
|
||||
|
||||
if ( ! headers_sent() ) {
|
||||
header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
|
||||
}
|
||||
|
||||
// Rotate the image
|
||||
$rotated = $editor->maybe_exif_rotate();
|
||||
|
||||
@@ -303,6 +315,8 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
|
||||
if ( ! empty( $image_meta['image_meta']['orientation'] ) ) {
|
||||
$image_meta['image_meta']['orientation'] = 1;
|
||||
}
|
||||
|
||||
wp_update_attachment_metadata( $attachment_id, $image_meta );
|
||||
} else {
|
||||
// TODO: handle errors.
|
||||
}
|
||||
@@ -386,6 +400,12 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ) {
|
||||
return $image_meta;
|
||||
}
|
||||
|
||||
// Set a custom header with the attachment_id.
|
||||
// Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
|
||||
if ( ! headers_sent() ) {
|
||||
header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
|
||||
}
|
||||
|
||||
// If stored EXIF data exists, rotate the source image before creating sub-sizes.
|
||||
if ( ! empty( $image_meta['image_meta'] ) ) {
|
||||
$rotated = $editor->maybe_exif_rotate();
|
||||
|
||||
Reference in New Issue
Block a user