WordPress: Allow users to upload images by role without a plugin

If you allow guest blogging on your WordPress installation, or you want someone to act as a contributor to your site – by contributor I mean create post for review adding images and files at the same time – some WordPress roles have restriction on file uploads.

The most obvious solution is to install a roles plugin, but if you don’t want to mananage a lot  of capabilities and roles you just want this one feature to be active, just copy and paste the following code in your WordPress theme functions.php file. Be sure to change the role.

//change the role to fit your needs
function enable_file_uploads_by_role( ) {
  $role = 'contributor';
  if(!current_user_can($role) || current_user_can('upload_files'))
    $contributor = get_role( $role );
} add_action('admin_init', 'enable_file_uploads_by_role');