{"id":66616,"date":"2011-12-14T13:00:07","date_gmt":"2011-12-14T18:00:07","guid":{"rendered":"http:\/\/wpmu.org\/?p=66616"},"modified":"2013-07-15T14:19:24","modified_gmt":"2013-07-15T18:19:24","slug":"restrict-wordpress-users-from-uploading-audio-video-media-file-types","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/restrict-wordpress-users-from-uploading-audio-video-media-file-types\/","title":{"rendered":"Restrict WordPress Users from Uploading Audio &amp; Video Media File Types"},"content":{"rendered":"<p><a rel=\"lightbox[66616]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/restrict-wordpress-users-from-uploading-audio-video-media-file-types\/stop-big\/\" rel=\"attachment wp-att-66619\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66619\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2011\/12\/stop-big.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"643\" height=\"499\" \/><\/a><br \/>\nNew 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 \u2013 the media uploader in the visual editor.<\/p>\n<p>The media uploader in old version of WordPress had separate buttons for each media type (images, audio, video).<\/p>\n<p><a rel=\"lightbox[66616]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/restrict-wordpress-users-from-uploading-audio-video-media-file-types\/old-media-uploader\/\" rel=\"attachment wp-att-66620\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66620\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2011\/12\/old-media-uploader.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"644\" height=\"398\" \/><\/a><\/p>\n<p>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\u2019t want them uploading audio or video. And so I used a plugin called <a href=\"http:\/\/wordpress.org\/extend\/plugins\/adminimize\/\" rel=\"noopener\" target=\"_blank\">Adminimize<\/a> that let me remove whatever media icons I wanted from the visual editor for certain users.<\/p>\n<h2><strong>The Problem with WordPress 3.3 <\/strong><\/h2>\n<p>In WordPress 3.3, however, the separate media buttons have all been combined into one button.<\/p>\n<p><a rel=\"lightbox[66616]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/restrict-wordpress-users-from-uploading-audio-video-media-file-types\/one-button-for-everything\/\" rel=\"attachment wp-att-66621\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66621\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2011\/12\/one-button-for-everything.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"644\" height=\"398\" \/><\/a><\/p>\n<p>Removing the one and only button wasn\u2019t an option, of course, and so I had to go in search for a solution.<\/p>\n<p>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).<\/p>\n\n<h2><strong>Plugin Solution<\/strong><\/h2>\n<p>The first option is a plugin called <a href=\"http:\/\/wordpress.org\/extend\/plugins\/restrict-uploads\/\" rel=\"noopener\" target=\"_blank\">Restrict Uploads<\/a>. 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 \u201cMIME\u201d types.<\/p>\n<p><a rel=\"lightbox[66616]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/restrict-wordpress-users-from-uploading-audio-video-media-file-types\/rejecting-upload\/\" rel=\"attachment wp-att-66622\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66622\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2011\/12\/rejecting-upload.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"644\" height=\"398\" \/><\/a><\/p>\n<h2><strong>Code Solution<\/strong><\/h2>\n<p>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 <a href=\"http:\/\/wpsnipp.com\/index.php\/functions-php\/restrict-uploads-to-specified-file-types-only-jpg-gif\/\" rel=\"noopener\" target=\"_blank\">this code<\/a> (from WPSnipp) will do the same thing as the plugin above.<\/p>\n<p>Put this at the bottom of the functions file in your theme &#8211; \u00a0<em>Appearance &gt;&gt; Editor &gt;&gt; Theme Functions (functions.php)<\/em><\/p>\n<p><code>add_filter('upload_mimes','restrict_mime');<\/code><\/p>\n<p><code>function restrict_mime($mimes) {<\/code><\/p>\n<p><code>$mimes = array(<\/code><\/p>\n<p><code>'jpg|jpeg|jpe' =&gt; 'image\/jpeg',<\/code><\/p>\n<p><code>'gif' =&gt; 'image\/gif',<\/code><\/p>\n<p><code>);<\/code><\/p>\n<p><code>return $mimes;<\/code><\/p>\n<p><code>}<\/code><\/p>\n<h2><strong>The Limitations of These Solutions<\/strong><\/h2>\n<p>Both of these solutions have the same limitation, however. Neither allows ANYONE to upload other file types, not even the Administrator.<\/p>\n<p>For some this won\u2019t matter. But if you need an Administrator or an Editor to have unlimited permission (\u201cunfiltered upload\u201d capability), then you\u2019re out of luck.<\/p>\n<p>I looked and looked for a solution that would allow more flexibility, but I haven\u2019t found one yet. If anyone knows of a solution, please mention it in the comments.<\/p>\n\n<p>Photo: <a href=\"http:\/\/www.bigstockphoto.com\/image-190335\/stock-photo-closed-area\" target=\"_blank\">Closed Area<\/a> from BigStock<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to prohibit users from uploading audio and video files.<\/p>\n","protected":false},"author":84404,"featured_media":66618,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[4],"tags":[3361,261],"tutorials_categories":[],"class_list":["post-66616","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-plugins","tag-media","tag-video"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/66616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=66616"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/66616\/revisions"}],"predecessor-version":[{"id":216216,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/66616\/revisions\/216216"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/66618"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=66616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=66616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=66616"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=66616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}