Several times recently in #wordpress, I’ve seen people asking how they could modify the list of allowed file types used in the file uploader on the Write Post page.
Since this information isn’t readily available (apparently) and to a lesser degree because I’m tired of not being able to find my previous code (causing me to re-type it all each time), I thought I’d throw together another quick WordPress hack guide.
Introduction
When you attempt to upload a file in WordPress (2.0+ I believe) that is not in the default list of acceptable file types, you will receive the following error:

As of WordPress 2.2, there are 35 allowed file types configured in the default install. While there’s no admin-based tool for editing this list (nor any plugins that I’m aware of), it’s not at all difficult to add your own…
The Code
Upload filetypes are checked by the function wp_check_filetype in wp-includes/functions.php (around line 1,000 in my current copy of trunk). Looking at the code, we see that the default array is passed into the upload_mimes filter, allowing you to easily add and remove types at will using a quick plugin hook.
So how do we do it? Well, first you need to add a new plugin hook. In your theme’s functions.php file, add this line:
[php]
add_filter(’upload_mimes’, ‘custom_upload_mimes’);
[/php]
You can, of course, replace custom_upload_mimes with your own preferred function name. Just make sure it’s something unique that ideally won’t cause any naming conflicts later on.
Now we’ve got a hook that tells WordPress to take the array of file types passed into the upload_mimes hook and hand it to the function custom_upload_mimes. Great, but where’s our function?
No problem, I’ve got it all ready for you. Open back up your theme’s functions.php file and toss in this code:
[php]
function custom_upload_mimes ( $existing_mimes=array() ) {
// add your ext => mime to the array
$existing_mimes['extension'] = ‘mime/type’;
// add as many as you like
// and return the new full result
return $existing_mimes;
}
[/php]
Note that the function accepts the $existing_mimes array, adds a new file type (with the extension “extension” and of the mime type “mime/type”), and then returns the whole array.
Replace extension with your extension (no period before it, just the textual extension) and then Google to find out its mime type.
Add as many new types as you like, simply by copying the example line and filling in your values. Also, make sure you name the function the same thing you used in the hook, assuming you don’t like my convention. Save your new functions.php file and you’re good to go!
Removing Existing Types
What if you want to remove an existing allowed type, instead of adding your own new type? Well, that’s even easier!
Replace the line $existing_mimes['extension'] = ‘mime/type’; with unset( $existing_mimes['extension'] ) and you’re done. For example, to prevent users from uploading .exe files, you would use:
[php]
unset( $existing_mimes['exe'] );
[/php]
Good luck, hope this helps!
Year-End Browser Stats
Ed Bott published fresh browser stats this morning, and I thought I would comment on some aspects…
The point that Ed makes about the lack of increase in Firefox’s market share is disappointing, but are we really surprised? I’ve said for quite some time that Firefox is geared towards the tech enthusiasts among us and that it really offers no hard benefits for your average every-day user.
Back when Mozilla was competing only with IE6 (we’ll continue ignoring Opera and Safari), it offered great benefits like tabbed browsing and native popup blocking, etc. Unfortunately, by the time it caught any ground, Microsoft had already usurped a great deal of its momentum by releasing the most-needed features in IE7. Sure, Firefox’s amazing extension support offers a lot of flexibility to those of us who consider ourselves power users on the web, but does the average person who only has one computer need 10 different bookmark syncing extensions or the inspection capabilities of Firebug? No…
The most interesting thing I see in these stats is the market penetration of IE7.
I run some basic stats on all our sites at work (mainly to let me know what cool stuff I can and cannot use), and IE6 still has an 80% lead over IE7 in our user base. Since we’re getting traffic from totally technically inept users, that’s a somewhat unfortunate statistic. Even more distressing is that IE has a 95% lead over all other browsers combined.
Clearly both Mozilla and Microsoft have done a fair job marketing their newer products to technical users who keep up with such things, but they’ve failed miserably at extolling the virtues to the average user — and that’s something that needs to change.
How do we do that? I haven’t a clue… I develop the stuff, I don’t market it.
The really interesting question, given the recent announcement that IE8 has passed the ACID2 test, is whether this will matter in a year. If all browsers follow standards properly, do we care which browser anyone uses? Of course if IE8 doesn’t drastically improve upon the market adoption of IE7 thus far, it may take another 10 years before everyone is seeing the web as it was intended to be seen…