WpCode.net

Daily Wordpress Code Snippet

How to allow file upload for specific author

| 1 Comment

Pin It

If you have a multi authors blog you may allow upload only for specifics authors and disallow for other, to do this you just need to paste the following code to your wordpress’s theme function.php file, editing the $user array. Continue reading

add_filter('upload_mimes','wpc_permetti_upload');
function wpc_permetti_upload($mimes) {
    global $current_user;
    get_currentuserinfo();
    // change users in list
    $users = array(
                              "pigi",
                              "gino",
                              "giovanni",
                              "antonio"
                            );
    if (!in_array($current_user->user_login, $users)) {
	$mimes = array(
	                'jpg|jpeg|jpe' => 'image/jpeg',
	                'gif' => 'image/gif',
	);
	}
	return $mimes;
}

One Comment

  1. Thanks for posting my snippet glad to see that you like it. Posting a source for the snippet is a small way to show your appreciation.

Leave a Reply

Required fields are marked *.

*