diff --git a/modules/class-wp-sweepbright-helpers.php b/modules/class-wp-sweepbright-helpers.php index 77758a1b..7fe81e82 100644 --- a/modules/class-wp-sweepbright-helpers.php +++ b/modules/class-wp-sweepbright-helpers.php @@ -157,27 +157,34 @@ public static function insert_attachment_from_url($file, $post_id = null) // Detect images if ($ext === 'jpg' || $ext === 'JPG' || $ext === 'jpeg' || $ext === 'JPEG' || $ext === 'png' || $ext === 'PNG' || $ext === 'gif' || $ext === 'GIF') { - $is_image = true; - // Detect HEIC $file = new SplFileObject($file_name); $detector = new ImageTypeDetector(); $detector->addProvider(new RasterProvider()); - $imageType = $detector->getImageTypeFromFile($file); - if ($imageType->getMimeType() === 'image/heic' || $imageType->getMimeType() === 'image/heif') { + try { + $is_image = true; + $imageType = $detector->getImageTypeFromFile($file); + + if ($imageType->getMimeType() === 'image/heic' || $imageType->getMimeType() === 'image/heif') { + $is_heic = true; + } + } catch (Exception $e) { $is_heic = true; + error_log(print_r('Prevented incorrect file from running `getImageTypeFromFile()`', true)); + error_log(print_r($e, true)); } } if (!$is_heic) { + // Allow uploading PDFs $attach_id = wp_insert_attachment($attachment, $file_name, $post_id); + // Resize images if ($is_image) { // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it. require_once(ABSPATH . 'wp-admin/includes/image.php'); - // Resize the large image. $image = wp_get_image_editor($file_name); if (!is_wp_error($image)) { diff --git a/wp-sweepbright.php b/wp-sweepbright.php index 30eebbfc..df167aff 100644 --- a/wp-sweepbright.php +++ b/wp-sweepbright.php @@ -10,7 +10,7 @@ * Author: Compagnon Agency * Author URI: https://compagnon.agency/ * Text Domain: wp-sweepbright - * Version: 1.7.15 + * Version: 1.7.16 */ // If this file is called directly, abort. @@ -23,7 +23,7 @@ * Start at version 1.0.0 and use SemVer - https://semver.org * Rename this for your plugin and update it as you release new versions. */ -define('WP_SWEEPBRIGHT_VERSION', '1.7.15'); +define('WP_SWEEPBRIGHT_VERSION', '1.7.16'); /** * The code that runs during plugin activation.