Skip to content

Instantly share code, notes, and snippets.

@eksiscloud
Last active June 22, 2020 10:20
Show Gist options
  • Save eksiscloud/ea02470d59421fccde6e1231b78d2d85 to your computer and use it in GitHub Desktop.
Save eksiscloud/ea02470d59421fccde6e1231b78d2d85 to your computer and use it in GitHub Desktop.
Wordpress: Allow/disallow uploading different type/mime files
add_filter( 'upload_mimes', 'my_mime_types', 1, 1 );
function my_mime_types( $mime_types ) {
$mime_types['jpg|jpeg|jpe'] = 'image/jpeg';
$mime_types['gif'] = 'image/gif';
$mime_types['png'] = 'image/png';
$mime_types['bmp'] = 'image/bmp';
$mime_types['tiff|tif'] = 'image/tiff';
$mime_types['ico'] = 'image/x-icon';
$mime_types['asf|asx'] = 'video/x-ms-asf';
$mime_types['wmv'] = 'video/x-ms-wmv';
$mime_types['wmx'] = 'video/x-ms-wmx';
$mime_types['wm'] = 'video/x-ms-wm';
$mime_types['avi'] = 'video/avi';
$mime_types['divx'] = 'video/divx';
$mime_types['flv'] = 'video/x-flv';
$mime_types['mov|qt'] = 'video/quicktime';
$mime_types['mpeg|mpg|mpe'] = 'video/mpeg';
$mime_types['mp4|m4v'] = 'video/mp4';
$mime_types['ogv'] = 'video/ogg';
$mime_types['webm'] = 'video/webm';
$mime_types['mkv'] = 'video/x-matroska';
$mime_types['3gp|3gpp'] = 'video/3gpp';
$mime_types['3g2|3gp2'] = 'video/3gpp2';
$mime_types['txt|asc|c|cc|h|srt'] = 'text/plain';
$mime_types['csv'] = 'text/csv';
$mime_types['tsv'] = 'text/tab-separated-values';
$mime_types['ics'] = 'text/calendar';
$mime_types['rtx'] = 'text/richtext';
$mime_types['css'] = 'text/css';
$mime_types['htm|html'] = 'text/html';
$mime_types['vtt'] = 'text/vtt';
$mime_types['dfxp'] = 'application/ttaf+xml';
$mime_types['mp3|m4a|m4b'] = 'audio/mpeg';
$mime_types['aac'] = 'audio/aac';
$mime_types['ra|ram'] = 'audio/x-realaudio';
$mime_types['wav'] = 'audio/wav';
$mime_types['ogg|oga'] = 'audio/ogg';
$mime_types['flac'] = 'audio/flac';
$mime_types['mid|midi'] = 'audio/midi';
$mime_types['wma'] = 'audio/x-ms-wma';
$mime_types['wax'] = 'audio/x-ms-wax';
$mime_types['mka'] = 'audio/x-matroska';
$mime_types['rtf'] = 'application/rtf';
$mime_types['js'] = 'application/javascript';
$mime_types['pdf'] = 'application/pdf';
$mime_types['class'] = 'application/java';
$mime_types['tar'] = 'application/x-tar';
$mime_types['zip'] = 'application/zip';
$mime_types['gz|gzip'] = 'application/x-gzip';
$mime_types['rar'] = 'application/rar';
$mime_types['7z'] = 'application/x-7z-compressed';
$mime_types['psd'] = 'application/octet-stream';
$mime_types['xcf'] = 'application/octet-stream';
$mime_types['doc'] = 'application/msword';
$mime_types['pot|pps|ppt'] = 'application/vnd.ms-powerpoint';
$mime_types['wri'] = 'application/vnd.ms-write';
$mime_types['xla|xls|xlt|xlw'] = 'application/vnd.ms-excel';
$mime_types['mdb'] = 'application/vnd.ms-access';
$mime_types['mpp'] = 'application/vnd.ms-project';
$mime_types['docx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
$mime_types['docm'] = 'application/vnd.ms-word.document.macroEnabled.12';
$mime_types['dotx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template';
$mime_types['dotm'] = 'application/vnd.ms-word.template.macroEnabled.12';
$mime_types['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
$mime_types['xlsm'] = 'application/vnd.ms-excel.sheet.macroEnabled.12';
$mime_types['xlsb'] = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12';
$mime_types['xltx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template';
$mime_types['xltm'] = 'application/vnd.ms-excel.template.macroEnabled.12';
$mime_types['xlam'] = 'application/vnd.ms-excel.addin.macroEnabled.12';
$mime_types['pptx'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
$mime_types['pptm'] = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12';
$mime_types['ppsx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow';
$mime_types['ppsm'] = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12';
$mime_types['potx'] = 'application/vnd.openxmlformats-officedocument.presentationml.template';
$mime_types['potm'] = 'application/vnd.ms-powerpoint.template.macroEnabled.12';
$mime_types['ppam'] = 'application/vnd.ms-powerpoint.addin.macroEnabled.12';
$mime_types['sldx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slide';
$mime_types['sldm'] = 'application/vnd.ms-powerpoint.slide.macroEnabled.12';
$mime_types['onetoc|onetoc2|onetmp|onepkg'] = 'application/onenote';
$mime_types['oxps'] = 'application/oxps';
$mime_types['xps'] = 'application/vnd.ms-xpsdocument';
$mime_types['odt'] = 'application/vnd.oasis.opendocument.text';
$mime_types['odp'] = 'application/vnd.oasis.opendocument.presentation';
$mime_types['ods'] = 'application/vnd.oasis.opendocument.spreadsheet';
$mime_types['odg'] = 'application/vnd.oasis.opendocument.graphics';
$mime_types['odc'] = 'application/vnd.oasis.opendocument.chart';
$mime_types['odb'] = 'application/vnd.oasis.opendocument.database';
$mime_types['odf'] = 'application/vnd.oasis.opendocument.formula';
$mime_types['wp|wpd'] = 'application/wordperfect';
$mime_types['key'] = 'application/vnd.apple.keynote';
$mime_types['numbers'] = 'application/vnd.apple.numbers';
$mime_types['pages'] = 'application/vnd.apple.pages';
$mime_types['svg'] = 'image/svg+xml';
$mime_types['ttf'] = 'application/font-ttf';
$mime_types['woff'] = 'application/font-woff';
$mime_types['eot'] = 'application/vnd.ms-fontobject';
$mime_types['epub'] = 'application/epub+zip';
$mime_types['woff2'] = 'application/font-woff2';
# Normally not allowed
$mime_types['svg'] = 'image/svg+xml';
$mime_types['epub'] = 'application/epub+zip';
# Mime-types can disallow too
# unset( $mime_types['xls'] );
# unset( $mime_types['xlsx'] );
return $mime_types;
}
@eksiscloud
Copy link
Author

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