Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
FalkoJoseph committed Jun 29, 2021
1 parent 76b0500 commit d74a115
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions modules/class-wp-sweepbright-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions wp-sweepbright.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit d74a115

Please sign in to comment.