WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/04/2019 01:10:57 AM (3 months ago)
Author:
azaozz
Message:

Uploads: After an image is uploaded and PHP times out or runs out of memory during post-processing (the server response is HTTP 500 error), try to resize it three more times. Then, if all attempts fail, do a cleanup of any sub-sizes that may have been created and show an error message asking the user to scale the image and upload it again.

See #47872.

File:
1 edited

Legend:

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

    r45871 r45934  
    132132 *
    133133 * @param int $attachment_id The image attachment post ID.
    134  * @return array The updated image meta data array.
     134 * @return array|WP_Error The updated image meta data array or WP_Error object
     135 *                        if both the image meta and the attached file are missing.
    135136 */
    136137function wp_update_image_subsizes( $attachment_id ) {
     138    $image_meta = wp_get_attachment_metadata( $attachment_id );
     139    $image_file = get_attached_file( $attachment_id );
     140
     141    if ( empty( $image_meta ) || ! is_array( $image_meta ) ) {
     142        // Previously failed upload?
     143        // If there is an uploaded file, make all sub-sizes and generate all of the attachment meta.
     144        if ( ! empty( $image_file ) ) {
     145            return wp_create_image_subsizes( $image_file, array(), $attachment_id );
     146        } else {
     147            return new WP_Error( 'invalid_attachment', __( 'The attached file cannot be found.' ) );
     148        }
     149    }
     150
    137151    $missing_sizes = wp_get_missing_image_subsizes( $attachment_id );
    138     $image_meta    = wp_get_attachment_metadata( $attachment_id );
    139152
    140153    if ( empty( $missing_sizes ) ) {
    141154        return $image_meta;
    142155    }
    143 
    144     $image_file = get_attached_file( $attachment_id );
    145156
    146157    // This also updates the image meta.
Note: See TracChangeset for help on using the changeset viewer.