Make WordPress Core


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

    r46290 r46382  
    983983
    984984/**
    985  * Temporarily stores the client upload reference in a transient.
    986  *
    987  * @since 5.3.0
    988  * @access private
    989  *
    990  * @param string $upload_ref    The upload reference sent by the client.
    991  * @param int    $attachment_id Attachment post ID.
    992  * @return bool Whether the transient was set.
    993  */
    994 function _wp_set_upload_ref( $upload_ref, $attachment_id ) {
    995     $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref );
    996 
    997     if ( ! empty( $upload_ref ) ) {
    998         return set_transient( '_wp_temp_image_ref:' . $upload_ref, $attachment_id, HOUR_IN_SECONDS );
    999     }
    1000 
    1001     return false;
    1002 }
    1003 
    1004 /**
    1005  * Get attachment post ID from an upload reference.
    1006  *
    1007  * @since 5.3.0
    1008  * @access private
    1009  *
    1010  * @param string $upload_ref    The upload reference sent by the client.
    1011  * @return int The attachemtn post ID. Zero if the upload reference has expired or doesn't exist.
    1012  */
    1013 function _wp_get_upload_ref_attachment_id( $upload_ref ) {
    1014     $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref );
    1015 
    1016     if ( ! empty( $upload_ref ) ) {
    1017         return (int) get_transient( '_wp_temp_image_ref:' . $upload_ref );
    1018     }
    1019 
    1020     return 0;
    1021 }
    1022 
    1023 /**
    1024  * Remove the transient that stores a temporary upload reference.
    1025  *
    1026  * @since 5.3.0
    1027  * @access private
    1028  *
    1029  * @param string $upload_ref    The upload reference sent by the client.
    1030  * @return bool Whether the transient was removed.
    1031  */
    1032 function _wp_clear_upload_ref( $upload_ref ) {
    1033     $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref );
    1034 
    1035     if ( ! empty( $upload_ref ) ) {
    1036         return delete_transient( '_wp_temp_image_ref:' . $upload_ref );
    1037     }
    1038 
    1039     return false;
    1040 }
    1041 
    1042 /**
    1043985 * Downloads a URL to a local temporary file using the WordPress HTTP API.
    1044986 *
Note: See TracChangeset for help on using the changeset viewer.