Make WordPress Core


Ignore:
Timestamp:
10/03/2019 09:00:10 PM (4 years ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image.php

    r46368 r46382  
    252252        }
    253253
     254        // Set a custom header with the attachment_id.
     255        // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
     256        if ( ! headers_sent() ) {
     257            header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
     258        }
     259
    254260        // Resize the image
    255261        $resized = $editor->resize( $threshold, $threshold );
     
    274280                    $image_meta['image_meta']['orientation'] = 1;
    275281                }
     282
     283                wp_update_attachment_metadata( $attachment_id, $image_meta );
    276284            } else {
    277285                // TODO: handle errors.
     
    288296            // This image cannot be edited.
    289297            return $image_meta;
     298        }
     299
     300        if ( ! headers_sent() ) {
     301            header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
    290302        }
    291303
     
    304316                    $image_meta['image_meta']['orientation'] = 1;
    305317                }
     318
     319                wp_update_attachment_metadata( $attachment_id, $image_meta );
    306320            } else {
    307321                // TODO: handle errors.
     
    385399        // The image cannot be edited.
    386400        return $image_meta;
     401    }
     402
     403    // Set a custom header with the attachment_id.
     404    // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
     405    if ( ! headers_sent() ) {
     406        header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
    387407    }
    388408
Note: See TracChangeset for help on using the changeset viewer.