Home Forums Add-ons Gallery Field Exclude videos Reply To: Exclude videos

  • 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!