Skip to content

How To Allow Contributors To Upload Images In WordPress

Yesterday I posted an article about allowing your WordPress website’ users to post on your website at this link. If you choose contributor role as the default role for your users, then you should know that the users with contributor roles are not allowed to upload images to their WordPress posts. If you want to allow contributors to upload images in WordPress, then here’s a little snippet for that.

Add following snippet to your current theme’s functions.php file:

if ( current_user_can('contributor') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_contributor_uploads');

function allow_contributor_uploads() {
     $contributor = get_role('contributor');
     $contributor->add_cap('upload_files');
}

17 thoughts on “How To Allow Contributors To Upload Images In WordPress”

  1. What do I need to do to install this to my functions.php file? Do I just paste it at the bottom of all the content? Also can I change ‘contributor’ to ‘subscriber’?

  2. I just tested this, and it worked perfectly. However, it gives the contributors the ability to delete their own images even after the posts are published, which isn’t a good idea in my opinion. Any workaround to deal with this?

      1. I added it, but the contributors are still able to delete images from the media library. When a contributor accesses the media library, they still see the Edit | Delete Permanently | View links. They sure can’t edit the post itself though (which is the case with or without the $contributor->remove_cap(‘edit_files’); bit).

        1. I found another snippet that does just that, I’ll put it here so people with the same problem will find a solution:

          add_action('media_row_actions','users_own_attachments', 2, 1);
          function users_own_attachments( $wp_query_obj ) {
          if( !current_user_can( 'delete_plugins' ) ){
          unset($wp_query_obj['delete']);
          return $wp_query_obj;
          }

          Thank you, this article have been a great help!

          1. Amazing! Hope it’s not causing any problem with the author role. I guess it will also take the access from any role which can’t delete the plugins, such as author.

          2. Actually, and according to my test, the snippet hides the red “Delete Permanently” link for everyone, including admins (from Media Library). However, contributors still can select pictures they uploaded and bulk delete them through the bulk command list. So I guess the problem still persists, I was quick to the trigger there :D

    Leave a Reply to Dragonaut Cancel reply

    Your email address will not be published. Required fields are marked *