Skip to content

Instantly share code, notes, and snippets.

@itzmekhokan
Last active June 30, 2019 14:58
Show Gist options
  • Save itzmekhokan/87817016c954baee318fa43abefccba1 to your computer and use it in GitHub Desktop.
Save itzmekhokan/87817016c954baee318fa43abefccba1 to your computer and use it in GitHub Desktop.
Restrict wp media modal image sizes upload
<?php
function wp_handle_upload_prefilter( $file ){
$tempImg = getimagesize( $file['tmp_name'] );
$width= $img[0];
$height =$img[1];
// lets restrict image size (width*height) 400*640 minimum
if ( $minimum['width'] < 400 )
return array( "error" => "Image dimensions are too small. Minimum width is 400px. Uploaded image width is 400 px" );
elseif ( $minimum['height'] < 640 )
return array( "error" => "Image dimensions are too small. Minimum height is 640px. Uploaded image height is 640 px" );
else
return $file;
}
add_filter( 'wp_handle_upload_prefilter', 'wp_handle_upload_prefilter' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment