Support

Account

Home Forums Add-ons Gallery Field Exclude videos

Solving

Exclude videos

  • Hi,

    When adding images or others in the gallery field, I want to know if it is possible to exlure some mime types. I found nothing in the options.

    Thank you in advance.

  • This one is a bit old but I just came across the need to do this. I don’t exclude videos, but I like to exclude PNGs and TIFFs on Image fields because their file sizes can be wildly large. Here’s how I do it:

    
    function prevent_certain_image_uploads($errors, $file, $attachment, $field, $context) {
    	$disallowed_formats = array('png', 'tiff');
    	if(in_array(strtolower($file['type']), $disallowed_formats)) {
    		$errors['mime_types'] = sprintf(__('File type may not be %s.', 'acf'), strtoupper($file['type']));
    	}
    	return $errors;
    }
    add_filter('acf/validate_attachment/type=image', __NAMESPACE__.'\\prevent_certain_image_uploads', 10, 5);
    

    It’s pretty easy to adapt this to your use case, just add the file extensions you want to exclude to the $disallowed_formats array and you should be good to go!

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Exclude videos’ is closed to new replies.