Skip to content

Commit

Permalink
Add the file extension on to the filename if it is missing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HughbertD committed May 4, 2022
1 parent 0b753bd commit 43227bb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions includes/classes/sync/pull.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use GatherContent\Importer\Mapping_Post;
use GatherContent\Importer\API;
use Mimey\MimeTypes;
use WP_Error;

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 43227bb

Please sign in to comment.