Make WordPress Core


Ignore:
Timestamp:
09/19/2019 01:25:14 AM (6 years ago)
Author:
azaozz
Message:

Uploads: add helper functions for setting, getting, and deleting the temp upload reference used to the attachment_id when retrying to make image sub-sizes.

See #47872.

File:
1 edited

Legend:

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

    r46131 r46174  
    309309    $name = wp_basename( $name, ".$ext" );
    310310
    311     $url       = $file['url'];
    312     $type      = $file['type'];
    313     $file      = $file['file'];
    314     $title     = sanitize_text_field( $name );
    315     $content   = '';
    316     $excerpt   = '';
    317     $image_ref = false;
     311    $url     = $file['url'];
     312    $type    = $file['type'];
     313    $file    = $file['file'];
     314    $title   = sanitize_text_field( $name );
     315    $content = '';
     316    $excerpt = '';
     317    $_ref    = false;
    318318
    319319    if ( preg_match( '#^audio#', $type ) ) {
     
    377377        // Use image exif/iptc data for title and caption defaults if possible.
    378378    } elseif ( 0 === strpos( $type, 'image/' ) ) {
    379         // Image file reference passed by the uploader.
    380         if ( ! empty( $_POST['_wp_temp_image_ref'] ) ) {
    381             $image_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $_POST['_wp_temp_image_ref'] );
    382         }
    383 
    384379        $image_meta = wp_read_image_metadata( $file );
    385380
     
    416411    if ( ! is_wp_error( $attachment_id ) ) {
    417412        // If an image, keep the upload reference until all image sub-sizes are created.
    418         if ( $image_ref ) {
    419             set_transient( '_wp_temp_image_ref:' . $image_ref, $attachment_id, HOUR_IN_SECONDS );
     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 );
    420415        }
    421416
     
    426421        // At this point the image is uploaded successfully even if there were specific errors or some sub-sizes were not created.
    427422        // The transient is not needed any more.
    428         if ( $image_ref ) {
    429             delete_transient( '_wp_temp_image_ref:' . $image_ref );
     423        if ( $_ref ) {
     424            _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] );
    430425        }
    431426    }
Note: See TracChangeset for help on using the changeset viewer.