Skip to content

Instantly share code, notes, and snippets.

@hyperframed
Created July 4, 2021 15:03
Show Gist options
  • Save hyperframed/9aaa4e953ace077ede8071344a6e6575 to your computer and use it in GitHub Desktop.
Save hyperframed/9aaa4e953ace077ede8071344a6e6575 to your computer and use it in GitHub Desktop.
Wordpress Minimum Image Dimension for Uploads
add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter');
function tc_handle_upload_prefilter($file)
{
$img=getimagesize($file['tmp_name']);
$minimum = array('width' => '400', 'height' => '400');
$width= $img[0];
$height =$img[1];
if ($width < $minimum['width'] )
return array("error"=>"Bildgröße zu klein. Das Minimum sind {$minimum['width']}px. Das hochgeladene Foto ist nur $width px breit.");
elseif ($height < $minimum['height'])
return array("error"=>"Bildgröße zu klein. Das Minimum sind {$minimum['height']}px. Das hochgeladene Foto ist nur $height px hoch.");
else
return $file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment