Created
December 25, 2014 19:45
-
-
Save cfxd/690016c7d59317198fb6 to your computer and use it in GitHub Desktop.
Restrict WordPress Media image upload dimensions
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 restrict_image_upload_size($file) { | |
if(!stristr($file['type'], 'image')) { // only run on images | |
return $file; | |
} | |
$img = getimagesize($file['tmp_name']); | |
$minimum = array('width' => '1024', 'height' => '768'); | |
$width = $img[0]; | |
$height = $img[1]; | |
if($file['error'] != '0') { // there's already an error | |
return $file; | |
} | |
if(defined('WP_IMPORTING')) { | |
return $file; | |
} | |
if($width < $minimum['width'] || $height < $minimum['height']) { | |
$file['error'] = "This image must be a minimum of {$minimum['width']}px x {$minimum['height']}px; the uploaded image is only {$width}px x {$height}px"; | |
} | |
return $file; | |
} | |
add_filter('wp_handle_upload_prefilter', 'restrict_image_upload_size'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment