Upload: Set custom header with the attachment ID for all uploads from media_handle_upload()
. Let the REST API endpoint set it separately.
Props timothyblynjacobs. Fixes #48200. git-svn-id: https://develop.svn.wordpress.org/trunk@46421 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
fd7240cab0
commit
022119d1a6
@ -2441,6 +2441,12 @@ function wp_ajax_media_create_image_subsizes() {
|
||||
}
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// This can still be pretty slow and cause timeout or out of memory errors.
|
||||
// The js that handles the response would need to also handle HTTP 500 errors.
|
||||
wp_update_image_subsizes( $attachment_id );
|
||||
|
@ -252,12 +252,6 @@ 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;
|
||||
@ -298,10 +292,6 @@ 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();
|
||||
|
||||
@ -401,12 +391,6 @@ 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();
|
||||
|
@ -408,6 +408,12 @@ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrid
|
||||
$attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true );
|
||||
|
||||
if ( ! is_wp_error( $attachment_id ) ) {
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// The image sub-sizes are created during wp_generate_attachment_metadata().
|
||||
// This is generally slow and may cause timeouts or out of memory errors.
|
||||
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
|
||||
|
Loading…
Reference in New Issue
Block a user