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

Screen Shot 2013-08-29 at 8.41.12 PM

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'))
    return;
    $contributor = get_role( $role );
    $contributor->add_cap('upload_files');
} add_action('admin_init', 'enable_file_uploads_by_role');

Leave a Reply

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