jeudi 5 mars 2015

Minimum Image Dimension not apply to every image


I found a way on this site to restrict authors from uploading images bellow specific dimensions. It looked perfect, till I reached the next problem; I need a workaround for certain images to be able to upload even if the images are smaller then the restricted dimensions. I was hoping to make this able through clicking a radio button that says 'don't used restricted dimensions' or something like that. But I can't find a way to make this possible...


The code now looks like this:


add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter'); function tc_handle_upload_prefilter($file) {



$img=getimagesize($file['tmp_name']);
$minimum = array('width' => '640', 'height' => '480');
$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 height is $height px");
else
return $file;


}


Anyone knows how to make this possible? Many thanks in advance.





Aucun commentaire:

Enregistrer un commentaire