From 43227bbb45e4365a87ec4a154171b348dedd0333 Mon Sep 17 00:00:00 2001 From: Hugh Downer Date: Tue, 3 May 2022 20:29:16 +0100 Subject: [PATCH] Add the file extension on to the filename if it is missing This is required within the upload logic of wordpress to determine the mimetype, and whether to allow the file to be uploaded Files without this extension fail this validation check. --- includes/classes/sync/pull.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/classes/sync/pull.php b/includes/classes/sync/pull.php index 70727e49..0f9cb996 100644 --- a/includes/classes/sync/pull.php +++ b/includes/classes/sync/pull.php @@ -10,6 +10,7 @@ use GatherContent\Importer\Mapping_Post; use GatherContent\Importer\API; +use Mimey\MimeTypes; use WP_Error; /** @@ -881,6 +882,12 @@ protected function maybe_sideload_file( $media, $post_id ) { protected function sideload_file( $file_name, $download_url, $post_id, $alt_text = '' ) { if ( ! empty( $download_url ) ) { $file_array = $this->tmp_file( $file_name, $download_url ); + $file_array['type'] = mime_content_type($file_array['tmp_name']); + $extension = '.' . (new MimeTypes())->getExtension($file_array['type']); + $hasExtension = substr($file_array['name'], 0 - strlen($extension)) === $extension; + if (!$hasExtension) { + $file_array['name'] = $file_array['name'] . $extension; + } if ( is_wp_error( $file_array ) ) { return $file_array;