Is it possible to prevent users from uploading small images?

Here you go:

   if(!current_user_can('delete_others_posts')){
    /*Handling wp media uloads*/
    add_filter('wp_handle_upload_prefilter','lets_handle_img_width');
    function lets_handle_img_width($file)
    {
        $img = getimagesize($file['tmp_name']);
        $width = $img[0];

        if ($width < 350){
            $file['error'] = "Image is small too small. Get something of width more than 350px.";
        }
        return $file;
    }
}

Check official documentation about wp_handle_upload_prefilter.

Leave a Comment