title: Allow 'subscriber' to upload media files - “Sorry, you are not allowed to attach files to this post.”
body: <p>I am using the Wordpress plugin "User Submitted Posts" to allow certain user to write posts from the front-end.</p>
  
  <p>I don't want them to see other posts in the backend and I want them to have as little access rights as possible. Therefore I want them only to be "subscribers". </p>
  
  <p>The only problem I have now is that "subscribers" are not allowed to upload files and therefore the "Add Media" button was not visible. I solved this by adding this code:</p>
  
  <pre><code>if ( current_user_can('subscriber') &amp;&amp; !current_user_can('upload_files') )
  add_action('admin_init', 'allow_subscriber_uploads');
  function allow_subscriber_uploads() {
      $subscriber = get_role('subscriber');
      $subscriber-&gt;add_cap('upload_files');       
  }
  </code></pre>
  
  <p>With this code the "Add Media" Button is there, the "subscriber" can access the media librabry (which is fine) and he is not allowed to delete other files (also fine).</p>
  
  <p>But when I try to upload files in the front-end editor with a "subscriber" user the following error appears: "Sorry, you are not allowed to attach files to this post.".</p>
  
  <p>I already tried to add more roles like this:</p>
  
  <pre><code>if ( current_user_can('subscriber') &amp;&amp; !current_user_can('upload_files') )
  add_action('admin_init', 'allow_subscriber_uploads');
  function allow_subscriber_uploads() {
      $subscriber = get_role('subscriber');
      $subscriber-&gt;add_cap('upload_files');
      $subscriber-&gt;add_cap('edit_attachments');
      $subscriber-&gt;add_cap('edit_posts');
      $subscriber-&gt;add_cap('edit_published_pages');
      $subscriber-&gt;add_cap('edit_others_pages');
      $subscriber-&gt;add_cap('edit_others_posts');
      $subscriber-&gt;add_cap('level_0');
      $subscriber-&gt;add_cap('level_1');        
  }
  </code></pre>
  
  <p>Unfortunately this still doesn't work, the same error appears. Any ideas why this doesn't work and which roles are necessary to make this work? Any other ways to solve this?</p>
  
  <p>Another idea I had was to give them the "contributor" role and then make sure they can't access the backend but this seemed like the more complicated way than just allow a "subscriber" to upload media files.</p>