Last active
October 28, 2022 13:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is a part of the article um_allowed_file_types.
Documentation: https://docs.ultimatemember.com/
Support forum: https://wordpress.org/support/plugin/ultimate-member/