Restrict file type uploads by user name

Adding this snippet to the functions.php of your worpress theme will let you restrict file uploads by type for specific users only. When a username is not in the users array they will only be able to upload jpg, and gif images.

 

 

add_filter('upload_mimes','restrict_mime');
function restrict_mime($mimes) {
global $current_user;
get_currentuserinfo();
// change users in list
$users = array(
"ryan",
"steven",
"larry",
"jerry"
);
if (!in_array($current_user->user_login, $users)) {
$mimes = array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
);
}
return $mimes;
}

Leave a comment