WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/03/2019 09:00:10 PM (2 months 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/media.php

    r46359 r46382  
    315315    $content = '';
    316316    $excerpt = '';
    317     $_ref    = false;
    318317
    319318    if ( preg_match( '#^audio#', $type ) ) {
     
    410409
    411410    if ( ! is_wp_error( $attachment_id ) ) {
    412         // If an image, keep the upload reference until all image sub-sizes are created.
    413         if ( ! empty( $_POST['_wp_temp_upload_ref'] ) && wp_attachment_is_image( $attachment_id ) ) {
    414             $_ref = _wp_set_upload_ref( $_POST['_wp_temp_upload_ref'], $attachment_id );
    415         }
    416 
    417411        // The image sub-sizes are created during wp_generate_attachment_metadata().
    418412        // This is generally slow and may cause timeouts or out of memory errors.
    419413        wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
    420 
    421         // At this point the image is uploaded successfully even if there were specific errors or some sub-sizes were not created.
    422         // The transient is not needed any more.
    423         if ( $_ref ) {
    424             _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] );
    425         }
    426414    }
    427415
Note: See TracChangeset for help on using the changeset viewer.