mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 14:50:29 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@46382 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -981,64 +981,6 @@ function wp_handle_sideload( &$file, $overrides = false, $time = null ) {
|
||||
return _wp_handle_upload( $file, $overrides, $time, $action );
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily stores the client upload reference in a transient.
|
||||
*
|
||||
* @since 5.3.0
|
||||
* @access private
|
||||
*
|
||||
* @param string $upload_ref The upload reference sent by the client.
|
||||
* @param int $attachment_id Attachment post ID.
|
||||
* @return bool Whether the transient was set.
|
||||
*/
|
||||
function _wp_set_upload_ref( $upload_ref, $attachment_id ) {
|
||||
$upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref );
|
||||
|
||||
if ( ! empty( $upload_ref ) ) {
|
||||
return set_transient( '_wp_temp_image_ref:' . $upload_ref, $attachment_id, HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachment post ID from an upload reference.
|
||||
*
|
||||
* @since 5.3.0
|
||||
* @access private
|
||||
*
|
||||
* @param string $upload_ref The upload reference sent by the client.
|
||||
* @return int The attachemtn post ID. Zero if the upload reference has expired or doesn't exist.
|
||||
*/
|
||||
function _wp_get_upload_ref_attachment_id( $upload_ref ) {
|
||||
$upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref );
|
||||
|
||||
if ( ! empty( $upload_ref ) ) {
|
||||
return (int) get_transient( '_wp_temp_image_ref:' . $upload_ref );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the transient that stores a temporary upload reference.
|
||||
*
|
||||
* @since 5.3.0
|
||||
* @access private
|
||||
*
|
||||
* @param string $upload_ref The upload reference sent by the client.
|
||||
* @return bool Whether the transient was removed.
|
||||
*/
|
||||
function _wp_clear_upload_ref( $upload_ref ) {
|
||||
$upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref );
|
||||
|
||||
if ( ! empty( $upload_ref ) ) {
|
||||
return delete_transient( '_wp_temp_image_ref:' . $upload_ref );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads a URL to a local temporary file using the WordPress HTTP API.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user