Allow vendors to upload only specific file types in EDD Frontend Submissions

Allow vendors to upload only specific file types in EDD Frontend Submissions

Frontend Submissions is an add-on that turns Easy Digital Downloads powered WordPress website into a complete multi-vendor marketplace. Based on your marketplace, you may need to restrict certain file type uploads or allow specific file types upload only for your vendors.

I am sharing a code snippet that I just have written, and implemented on one of my client's EDD FES websites. Inserting it into WordPress theme's functions.php will restrict vendors to upload any other file types and allow only zip file type upload.

// FES form field name : Prices and Files

add_filter( 'upload_mimes', 'dcg_restrict_mime_types', 1, 1 );
function dcg_restrict_mime_types( $mime_types )
{
    
    $user = wp_get_current_user(); // get the current user
    // if user is shop vendor or a shop manager
    if ( in_array( 'shop_vendor', (array) $user->roles ) || in_array( 'shop_manager', (array) $user->roles ) ) {
        
        // add the mime types you want to allow to upload
        $mime_types = array(
            'zip' => 'application/zip',
        );
        
        // Use unset to remove specific mime types uploads.
        // unset( $mime_types['xls'] );  // Remove .xls extension
        // unset( $mime_types['xlsx'] ); // Remove .xlsx extension
        // unset( $mime_types['docx'] ); // Remove .docx extension
    
        return $mime_types;
    }
}
View above code on Github Gist

Have you any better solution? I would love to read your comments on Github Gist.