Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active October 28, 2022 13:48
Show Gist options
  • Save yuriinalivaiko/daf38aa1f8c9a4333bcad924d662fcce to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/daf38aa1f8c9a4333bcad924d662fcce to your computer and use it in GitHub Desktop.
This code snippet extends the "File upload" field type to allow the vCard (also known as VCF) file types.
<?php
/**
* Allow to upload vCard files via the "File Upload" field type.
* Add this code to the file functions.php in the active theme directory.
*/
function um_add_vcard_file_types( $allowed_types ) {
if( is_array( $allowed_types ) ) {
$vcard_types = array(
'vcf' => 'vcf - vCard',
'vcard' => 'vcard - vCard',
);
$allowed_types = array_merge( $vcard_types, $allowed_types );
}
return $allowed_types;
}
add_filter( 'um_allowed_file_types', 'um_add_vcard_file_types' );
function um_add_vcard_check_filetype_and_ext( $wp_filetype, $file, $filename, $mimes ){
if ( empty( $wp_filetype['type'] ) && preg_match( '!\.(vcf|vcard)$!i', $filename ) ) {
$mimes['vcf|vcard'] = 'text/vcard';
$filetype = wp_check_filetype( $filename, $mimes );
$wp_filetype['ext'] = $filetype['ext'];
$wp_filetype['type'] = $filetype['type'];
}
return $wp_filetype;
}
add_filter( 'wp_check_filetype_and_ext', 'um_add_vcard_check_filetype_and_ext', 10, 4 );
@yuriinalivaiko
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment