Make WordPress Core


Ignore:
Timestamp:
09/19/2019 01:25:14 AM (4 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/ajax-actions.php

    r46155 r46174  
    24232423    }
    24242424
    2425     // Using Plupload `file.id` as ref.
    2426     if ( ! empty( $_POST['_wp_temp_image_ref'] ) ) {
    2427         $image_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $_POST['_wp_temp_image_ref'] );
     2425    if ( ! empty( $_POST['_wp_temp_upload_ref'] ) ) {
     2426        // Uploading of images usually fails while creating the sub-sizes, either because of a timeout or out of memory.
     2427        // At this point the file has been uploaded and an attachment post created, but because of the PHP fatal error
     2428        // the cliend doesn't know the attachment ID yet.
     2429        // To be able to find the new attachment_id in these cases we temporarily store an upload reference sent by the client
     2430        // in the original upload request. It is used to save a transient with the attachment_id as value.
     2431        // That reference currently is Plupload's `file.id` but can be any sufficiently random alpha-numeric string.
     2432        $attachment_id = _wp_get_upload_ref_attachment_id( $_POST['_wp_temp_upload_ref'] );
    24282433    } else {
    24292434        wp_send_json_error( array( 'message' => __( 'Invalid file reference.' ) ) );
    24302435    }
    2431 
    2432     // Uploading of images usually fails while creating the sub-sizes, either because of a timeout or out of memory.
    2433     // At this point the file has been uploaded and an attachment post created, but because of the PHP fatal error
    2434     // the cliend doesn't know the attachment ID yet.
    2435     // To be able to find the new attachment_id in these cases we temporarily store an upload reference sent by the client
    2436     // in the original upload request. It is used to save a transient with the attachment_id as value.
    2437     // That reference currently is Plupload's `file.id` but can be any sufficiently random alpha-numeric string.
    2438     $attachment_id = get_transient( '_wp_temp_image_ref:' . $image_ref );
    24392436
    24402437    if ( empty( $attachment_id ) ) {
     
    24822479
    24832480    // At this point the image has been uploaded successfully.
    2484     delete_transient( '_wp_temp_image_ref:' . $image_ref );
     2481    _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] );
    24852482
    24862483    wp_send_json_success( $response );
Note: See TracChangeset for help on using the changeset viewer.