How To Allow Contributors To Upload Images In WordPress

WordPress comes bundled with a contributor role which has capabilities to read, edit, and delete posts. However, WordPress doesn't allow the users that belong to this particular role to upload images. You could easily bypass this problem by upgrading the user to an author or editor role. But, this will also give additional and much more powerful capabilites to the user like deleting or editing published posts, managing categories, moderating comments, etc. Also, this will be a problem if you wish to give all of your contributors the ability to upload the images.
 
There are a number of plugins out there that will enable this capability for the contributor role. However, if you're more comfortable with code then this tiny code snippet will help you ditch those plugins.
 
In order to allow contributors to upload images all you need to do is paste and copy the following code snippet and paste it inside your functions.php file located inside the root of your active theme folder.
  1. if ( current_user_can('contributor') && !current_user_can('upload_files') )  
  2.       add_action('admin_init''allow_contributor_img_uploads');
  3.       function allow_contributor_img_uploads() {  
  4.           $contributor = get_role('contributor');  
  5.           $contributor->add_cap('upload_files');  
  6.      }