Allowing More File Extension Uploads in WordPress

On a site I recently helped get up and running, I wanted to upload a pgp key.  Doing so naturally was impossible, as pgp isn’t in the default approved list of file extensions.  All of my research on the matter told me to go to: http://chrismeller.com/2007/07/modifying-allowed-upload-types-in-wordpress.  While this may solve the problem, it seemed like more work than was necessary.  I mean, all I want to do is add one item to the list!

Well, in searching around, I found this function in the wp-includes/functions.php file:

function get_allowed_mime_types() {
        static $mimes = false;

        if ( !$mimes ) {
                // Accepted MIME types are set here as PCRE unless provided.
                $mimes = apply_filters( 'upload_mimes', array(
                'jpg|jpeg|jpe' => 'image/jpeg',
                'gif' => 'image/gif',
...(Line 2547)

In this list, you can simply add whatever extension you want, and the MIME type (google that). Much simpler than adding a function and doing the round about way!

Image Source: http://redriverpak.files.wordpress.com/2011/01/good-news-bad-news.jpg

Comments are closed