Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to create dynamic capabilities using WP_Role::add_cap(), something like

$author_role = get_role('author');

foreach ($sections as $section) {
    $author_role->add_cap( "edit_{$section}_pages", /* grant= */ false );
}

and then let administrators grant certain of those capabilities to certain authors only (e.g., Jane can edit_school_pages) in wp-admin (not programmatically, via WP_User::add_cap()).

I assume a plugin can help with this, but those I've found (e.g., Capability Manager) seem to emphasize creating new Roles or Capabilities and adding/moving Capabilities among Roles, not granting capabilities directly to users (though I could be wrong).

Advice? Thanks, s

share|improve this question

3 Answers 3

you can assign capabilities directly to user using the class WP_user::add_cap()

//to remove capability from user
$user = new WP_User( $user_id );
$user->remove_cap( 'can_email');

//to add capability to user
$user = new WP_User( $user_id );
$user->add_cap( 'can_email');

Source - http://wordpress.stackexchange.com/a/60433/17968

share|improve this answer

I there, i'm starting to use this plugin.

I'm editing 'cause was a poor answer. So, the plugin that i'm starting to use is 'Role Scoper for Wordpress'. I need to have different roles, but, first all, I need to assign right 'per post'. This plugin seems to do it, with just a little bit trick. I'll try further more so i'll can write much better.

share|improve this answer
    
Lone link is considered a poor answer since it is meaningless by itself and target resource is not guaranteed to be alive in the future. Please try to include at least summary of information you are linking to. –  Rarst Jan 29 '12 at 18:41
    
True. I'm really sorry. I was writing with my IPhone with some battery problem. I'll write a correct answer when i'll use my computer. Thank you. Francesco –  Francesco Di Candia Jan 30 '12 at 15:19
    
Thanks for update! :) No worries, just nudging you in right direction. –  Rarst Jan 30 '12 at 17:18
    
Thank you very much Rarst, i use StackExchange only asking 'till now. Was time to start to try to answer ;) ;) ;) –  Francesco Di Candia Jan 30 '12 at 18:15

Capabilities are permissions for roles. Those roles are then extended to the users, which determines what a user can do. The reason you use roles is to avoid managing permissions per user.

The best way to accomplish what you want is to create a new role for each set of capabilities that you want and assign the user to each role with a member management plugin.

share|improve this answer
    
Thanks, @MatthewMuro. In most cases, I would try a Role-focused approach, but here managing permissions per user seems to be exactly what I need to do: given any Author or Editor user, add or remove her capability to edit any (1 or more) of certain content sections, represented by 1 or more capabilities determined at runtime (e.g., edit_school_pages, edit_staff_pages, edit_contact_pages…). –  sam May 19 '11 at 21:37
    
… I thought about using Roles, but I can only imagine creating a Role for each section ("Author of Section 1", "Editor of Section 1", …), and even then, I wouldn't be able to grant permissions to edit multiple sections. Essentially, I think I'm looking for a wp-admin interface to WP_User::add_cap(). –  sam May 19 '11 at 21:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.