From 3b65584f356d79056bb3c3ac7293dcae05d96ab6 Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Wed, 3 Sep 2014 21:30:50 +0200 Subject: [PATCH] Fixes upload of non-images --- .../aktiv2014/dist/images/icon-menu.svg | 2 +- wp-content/themes/aktiv2014/functions.php | 36 +++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/wp-content/themes/aktiv2014/dist/images/icon-menu.svg b/wp-content/themes/aktiv2014/dist/images/icon-menu.svg index 69bbae3..fe5bf2d 100644 --- a/wp-content/themes/aktiv2014/dist/images/icon-menu.svg +++ b/wp-content/themes/aktiv2014/dist/images/icon-menu.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wp-content/themes/aktiv2014/functions.php b/wp-content/themes/aktiv2014/functions.php index 28be0c0..86162c9 100644 --- a/wp-content/themes/aktiv2014/functions.php +++ b/wp-content/themes/aktiv2014/functions.php @@ -30,27 +30,35 @@ add_action( 'wp_enqueue_scripts' , 'neuf_enqueue_scripts' ); /** * Force large uploaded images. - * * Denies uploads of images smaller (in pixels) than given width and height values. */ function neuf_handle_upload_prefilter( $file ) { - $width = 640; - $height = 480; + /* Only check files with mime type 'image/*' */ + $is_not_image = strpos($file['type'], 'image/') !== 0; + if( $is_not_image ) { + return $file; + } + $errors = array(); + $minimum = array( 'width' => 640, 'height' => 480); - $img = getimagesize( $file['tmp_name'] ); - $minimum = array( 'width' => $width , 'height' => $height ); - $width = $img[0]; - $height =$img[1]; + $img = getimagesize( $file['tmp_name'] ); + $width = $img[0]; + $height = $img[1]; - if ( $width < $minimum['width'] ) - return array( "error" => "Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px" ); - elseif ($height < $minimum['height']) - return array( "error" => "Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image width is $width px" ); - else - return $file; + if ( $width < $minimum['width'] ) { + $errors[] = "Minimum width is {$minimum['width']} px. Uploaded image wid th is $width px"; + } + if ($height < $minimum['height']) { + $errors[] = "Minimum height is {$minimum['height']} px. Uploaded image h eight is $height px"; + } + + if( count($errors) > 0 ) { + return array( "error" => "Image dimensions are too small: ".implode(", " , $errors)."."); + } + + return $file; } -// Commenting out for testing purposes add_filter( 'wp_handle_upload_prefilter' , 'neuf_handle_upload_prefilter' ); /* Gets nicely the regular and member price nicely formated */