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.

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');

Author: Benjamin Reid

My name is Benjamin Reid, I live in the UK and keep the magic locked into this site.

RSS Icon

Subscribe to the RSS feed some design goodness, get in on the upcoming software give-aways!

Digg Icon Share Quick Tip #9 - Change the default capabilities of WordPress users with ease to Twitter Share Quick Tip #9 - Change the default capabilities of WordPress users with ease to Delicious Share Quick Tip #9 - Change the default capabilities of WordPress users with ease to Facebook

Related post(s)

  • No Related Post
Comments left by other wizards

6 Responses | Make a comment

Leave your words of wisdom

Leave a Reply

This is a Gravatar

Your name