Last active
June 30, 2019 14:58
-
-
Save itzmekhokan/87817016c954baee318fa43abefccba1 to your computer and use it in GitHub Desktop.
Restrict wp media modal image sizes upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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