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!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.