diff --git a/upload-mime-types.php b/upload-mime-types.php new file mode 100644 index 0000000000000000000000000000000000000000..e8c8c9b5485a72e1d3ab84d5dde557959f381a32 --- /dev/null +++ b/upload-mime-types.php @@ -0,0 +1,31 @@ +<?php +/* + * Plugin Name: A/I - Upload MIME types + * Description: Changes the list of allowed MIME types for uploads + * Version: 0.1.0 + * Author: Autistici/Inventati + * Author URI: https://autistici.org + */ + +/* Allow application/pgp-keys mime type + * + * If the file type associated to the filename extension and the one detected by fileinfo do not match + * wordpress will set $types['ext'] and $types['type'] to false. + * In order to accept the file we need to set these values to something not false. +*/ +add_filter( 'wp_check_filetype_and_ext', function( $types, $file, $filename, $mimes, $real_mime ){ + // Check if the file type was detected (by fileinfo) to be application/pgp-keys + if ( $real_mime == 'application/pgp-keys'){ + // get the extention and file type associated to it (most probably 'text/plain') + $wp_filetype = wp_check_filetype( $filename, $mimes ); + + // only accept the file if the extension is one of the allowed ones for text/plain and application/pgp-keys + if (in_array($wp_filetype['type'], array('text/plain', 'application/pgp-keys'), true)){ + $types['ext'] = $wp_filetype['ext']; + $types['type'] = $wp_filetype['type']; + } + } + return $types; +}, 1, 5); + +?>