Skip to content

Instantly share code, notes, and snippets.

@dipakcg
Created August 16, 2020 07:08
Show Gist options
  • Save dipakcg/0fbf24daffd8e6279239558f43c4be15 to your computer and use it in GitHub Desktop.
Save dipakcg/0fbf24daffd8e6279239558f43c4be15 to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Front-End Submissions - Allow only specific mime types 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment