Home › Forums › Add-ons › Gallery Field › Server-Side Validation for Image and Gallery Fields
The recent 6.8.7 update has killed the ability to upload MP4 and MOV files to the gallery field. Does anyone have a workaround for this?
Support got back to me very quickly! The fix is as follows:
/**
* Allow PDFs in ACF Gallery fields (ACF 6.8.7+).
*
* ACF 6.8.7 added server-side enforcement that restricts Image and Gallery
* fields to image files only. These three filters restore PDF support while
* leaving the image-only restriction in place for every other file type.
*
* To target a single gallery field instead of all gallery fields, replace
* /type=gallery with /key=field_XXXXXXXX in all three filter tags.
*/
add_filter( ‘acf/get_image_mime_types/type=gallery’, function( $mimes ) {
return $mimes + array( ‘mp4’ => ‘video/mp4’ );
} );add_filter( ‘acf/validate_is_image_attachment/type=gallery’, function( $errors, $file, $attachment ) {
$type = ! empty( $attachment[‘id’] )
? get_post_mime_type( $attachment[‘id’] )
: ( wp_check_filetype( $attachment[‘name’] ?? ” )[‘type’] ?? ( $attachment[‘mime’] ?? $attachment[‘type’] ?? ” ) );if ( ‘video/mp4’ === $type ) {
unset( $errors[‘invalid_image’] );
}return $errors;
}, 10, 3 );add_filter( ‘acf/validate_value/type=gallery’, function( $valid, $value, $field, $input ) {
if ( true === $valid || ! is_array( $value ) ) {
return $valid;
}foreach ( $value as $id ) {
if ( ! is_numeric( $id ) ) {
return $valid;
}if ( ! wp_attachment_is_image( $id ) && ‘video/mp4’ !== get_post_mime_type( $id ) ) {
return $valid;
}
}$min = (int) ( $field[‘min’] ?? 0 );
if ( $min && count( $value ) < $min ) {
return sprintf(
_n( ‘%1$s requires at least %2$s selection’, ‘%1$s requires at least %2$s selections’, $min, ‘acf’ ),
$field[‘label’],
$min
);
}return true;
}, 20, 4 );
Hi!
Thank you for sharing this workaround, but this really shouldn’t be the official way to handle it.
The Gallery field still has a “Allowed file types” (mime_types) setting option in the field configuration. It makes no sense for server-side validation to hardcode an image check while completely ignoring this field setting, or at least without providing a native filter to override it.
This completely breaks existing enterprise setups where galleries are used for document bundles (like PDFs, brochures, etc.).
I’m stuck on version 6.8.6 for now to avoid breaking client sites. I’ve also opened a ticket with support—hopefully, they will address this regression properly in an upcoming release.
I agree with Akhela. This seems like a problem that didn’t need resolution. Can you please reconsider this PDF restriction on the Gallery field?
Thumbs up with @akhela. We have configured both image and video file types in **Allow file types** (jpg, jpeg, mov, mp4), but this no longer works after upgrading to ACV 6.8.7.
Please consider implementing a proper fix for this issue instead of hard-coding the image file types, so the configured file types continue to work correctly.
This is a disaster. Somebody pushed out a “security” update without considering how thousands of sites are configured to use this field. Using gallery fields for pdfs and mp4s is a super common practice. Needs to be reverted or fixed asap.
What kind of update is this?
Forcing people paying for the Pro version to use this awful do-it-yourself workaround?
There’s a field for MIME types and yet it’s completely ignored in some sort of last-minute fix. If there’s a possibility to set other file types – they MUST be taken into account.
@wfinley could you remove the “solved” status ? It’s not solved at all…
Already 3 new versions and no status on this..
Don’t think I have the ability to do that.
That said – technically my ask for a workaround is solved. Someone else can open a ticket asking for a revert.
You must be logged in to reply to this topic.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.