Quick Tip #9 – Change the default capabilities of WordPress users with ease

Posted on

In my latest WordPress project, the client wanted a user with the capabilities of a Contributor but they also wanted them to be able to upload files. This is where the problem arose, a Contributor can't upload files! I could upgrade them to an Author, which would allow them to upload files but in turn would allow them to publish posts too.

I'd used role manager plugins before (such as Role Scoper) and they seemed way to clunky and heavy for what I wanted, besides I only wanted to modify the property of one role ever so slightly.

So I did some digging and found this handy bit of code. In your plugins folder, create a file called edit_roles.php and add in the following code.

add_cap('upload_files');


?>

Activate the plugin through the Dashboard and voila, a Contributor will now be able to upload files.

Add more capabilities

Adding other capabilities is simple too, copy line 19 and change the argument in add_cap('argument') to one of the roles from this table.

$edit_contributor->add_cap('publish_pages');

$edit_contributor->add_cap('switch_themes');

// and so on

Removing capabilities

Simples!

$edit_contributor->remove_cap('delete_posts');

10 comments

  • Callum Chapman wrote on

    This would allow them to write and upload files but sort of, uh, submit the article for review, instead of posting it? I guess they wouldn’t have access to any other admin stuff either?

    Might have to do this on my Circlebox. :)

  • shaun wrote on

    This is really handy and definitely something I will look at for a project i have on at the minute.

    Is it possible to allow users to edit a page, but restrict it to just one page using that particular page’s ID?

    • Nouveller wrote on

      It might be possible to do something along the lines of:

      function page_block { 
      
      if($post->ID == '5') {
      
      ...add/remove cap
      
      }
      
      }
      
      add_action('admin_head', 'page_block');
      

      I haven’t tested it though but let me know if it works.
      :)

  • Niklas Olsson wrote on

    Thanks for this post, it was exactly what I was looking for. I found a couple of plugins for managing user roles but all of them was for a single blog in a multi site instance.

    I used your example to add some user credidentials to the default editor role so I don’t need to assign the blog owner for each blog (in my multi site instance) the administrator role which has too much credidentials in this case.

  • Kevin Abbott wrote on

    Thanks I needed the contributor to do exactly what you needed it to do. Very useful and easy to do! Thanks again!

  • DNA Test wrote on

    I’m sorry for the off-topic question but could you maybe tell me where I can get the template you are using? I would love to have the same website design or maybe one that is similar to yours. Can you say where you found it?

  • Krystina Franke wrote on

    I was suggested this web site via my cousin. I’m now not sure whether or not this put up is written through him as no one else understand such specified approximately my problem. You’re incredible! Thank you! Elite Connections, Babmaes House, 2 Babmaes Street, London, SW1Y 6HD, 020 3011 2943

  • Phebe Rodal wrote on

    Great write-up, I’m regular visitor of one’s web site, maintain up the excellent operate, and It is going to be a regular visitor for a lengthy time. SM London Escorts Agency, 33 Belgrave Road, Westminster, London, SW1V 2, 020 3011 7815

  • Pingback: Link esterno per immagini

Add your comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>