/*
* This can still be pretty slow and cause timeout or out of memory errors.
* The js that handles the response would need to also handle HTTP 500 errors.
*/
wp_update_image_subsizes( $attachment_id );
if ( !
empty( $_POST['_legacy_support'
] ) ) { // The old (inline) uploader. Only needs the attachment_id.
$response = array
( 'id' =>
$attachment_id );
} else { // Media modal and Media Library grid view.
$response =
wp_prepare_attachment_for_js( $attachment_id );
if ( !
$response ) { wp_send_json_error( array
( 'message' =>
__( 'Upload failed.'
) ) );
} } // At this point the image has been uploaded successfully.
wp_send_json_success( $response );
}/**
* Handles uploading attachments via AJAX.
*
* @since 3.3.0
*/