4
Feb
Quick Tip #9 - Change the default capabilities of WordPress users with ease
Posted by Nouveller in Quick Tips
Posted by Nouveller in Quick Tips
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?php /* Plugin Name: Role Edit Plugin URI: http://www.nouveller.com/ Description: Edits the default WordPress roles Author: Nouveller Author URI: http://www.nouveller.com/ */ // store the 'Contributor' role $edit_contributor = get_role('contributor'); // add a capability of 'upload_files' $edit_contributor->add_cap('upload_files'); ?> |
Activate the plugin through the Dashboard and voila, a Contributor will now be able to upload files.
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
Simples!
$edit_contributor->remove_cap('delete_posts');
My name is Benjamin Reid, I live in the UK and keep the magic locked into this site.
This entry was posted on Thursday, February 4th, 2010 at 2:08 pm and is filed under Quick Tips & tagged with . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Callum Chapman wrote on February 11, 2010
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.
Nouveller wrote on February 12, 2010
Do it!
shaun wrote on February 15, 2010
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 February 15, 2010
It might be possible to do something along the lines of:
I haven’t tested it though but let me know if it works.
Tyron Bundette wrote on July 31, 2010
Exactly where will it be, i’d prefer to read more about this posting, thank you.