Fixes upload of non-images

This commit is contained in:
nikolark committed 2014-09-03 21:30:50 +02:00
1 parent 29872fba9e
commit 3b65584f35
2 files changed
+23 -15

No files matched your search

+1 -1
View File
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="12" viewBox="0 0 18 12"><g fill="#fff"><path d="M0 0h18v2H0zM0 5h18v2H0zM0 10h18v2H0z"/></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="12" viewBox="0 0 18 12"><g fill="#fff"><path d="M0 0h18v2h-18zM0 5h18v2h-18zM0 10h18v2h-18z"/></g></svg>

Before

Width:  |  Height:  |  Size: 157 B

After

Width:  |  Height:  |  Size: 163 B

+22 -14
View File
@@ -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 */