Created
December 2, 2014 16:13
-
-
Save petenelson/c2ddfc72d3b3b8e71400 to your computer and use it in GitHub Desktop.
WordPress: Prevent large image uploads by dimension
This file contains 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 | |
add_filter( 'wp_handle_upload_prefilter', 'gga_filter_large_image_dimensions' ); | |
function gga_filter_large_image_dimensions( $file ) { | |
$maxsize = 2000; | |
if ( false !== strpos($file['type'], 'image/') ) { | |
$size = getimagesize( $file['tmp_name'] ); | |
if ( !empty( $size ) && count( $size ) > 1 ) { | |
if ( ($size[0] > 0 && $size[0] > $maxsize ) || ($size[1] > 0 && $size[1] > $maxsize ) ) { | |
$file['error'] = 'Image width or height cannot exceed ' . $maxsize . ' pixels.'; | |
return $file; | |
} | |
} | |
} | |
return $file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment