wp_send_json_error( array
( 'message' =>
__( 'Sorry, you are not allowed to upload files.'
) ) );
} if ( empty( $_POST['attachment_id'
] ) ) { wp_send_json_error( array
( 'message' =>
__( 'Upload failed. Please reload and try again.'
) ) );
} $attachment_id =
(int) $_POST['attachment_id'
];
if ( !
empty( $_POST['_wp_upload_failed_cleanup'
] ) ) { // Upload failed. Cleanup.
if ( wp_attachment_is_image( $attachment_id ) &&
current_user_can( 'delete_post',
$attachment_id ) ) { $attachment =
get_post( $attachment_id );
// Created at most 10 min ago.
if ( $attachment && ( time() -
strtotime( $attachment->post_date_gmt
) < 600
) ) { wp_delete_attachment( $attachment_id, true
);
wp_send_json_success();
} } } /*
* Set a custom header with the attachment_id.
* Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
*/