Restrict WordPress Users from Uploading Audio & Video Media File Types

Restrict WordPress Users from Uploading Audio & Video Media File Types


New versions of WordPress are usually a good thing. They bring improvements and new features. But when I saw the changes that came in WP 3.3 recently, I knew it was going to cause me problems in one area – the media uploader in the visual editor.

The media uploader in old version of WordPress had separate buttons for each media type (images, audio, video).

This was a good thing for me because I have site where users are allowed to post content. I was fine with having them upload images but didn’t want them uploading audio or video. And so I used a plugin called Adminimize that let me remove whatever media icons I wanted from the visual editor for certain users.

The Problem with WordPress 3.3

In WordPress 3.3, however, the separate media buttons have all been combined into one button.

Removing the one and only button wasn’t an option, of course, and so I had to go in search for a solution.

In the process, I found a lot of people had this request to restrict audio and video uploads. I also came across a few options that would seem to do the trick (with limitations).

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

Plugin Solution

The first option is a plugin called Restrict Uploads. This plugin restricts uploads to image files (jpg, gif, png). This plugin has no settings page. Simply activate it, and it will begin restricting file uploads to those three “MIME” types.

Code Solution

I also found a number of snippets of code across the web that would do the same thing. And so if you prefer adding code to your functions file, then this code (from WPSnipp) will do the same thing as the plugin above.

Put this at the bottom of the functions file in your theme –  Appearance >> Editor >> Theme Functions (functions.php)

add_filter('upload_mimes','restrict_mime');

function restrict_mime($mimes) {

$mimes = array(

'jpg|jpeg|jpe' => 'image/jpeg',

'gif' => 'image/gif',

);

return $mimes;

}

The Limitations of These Solutions

Both of these solutions have the same limitation, however. Neither allows ANYONE to upload other file types, not even the Administrator.

For some this won’t matter. But if you need an Administrator or an Editor to have unlimited permission (“unfiltered upload” capability), then you’re out of luck.

I looked and looked for a solution that would allow more flexibility, but I haven’t found one yet. If anyone knows of a solution, please mention it in the comments.

Photo: Closed Area from BigStock

Tags: