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

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 - https://wordpress.stackexchange.com/a/60433/17968


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.

  • 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
    Commented Jan 29, 2012 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 Commented Jan 30, 2012 at 15:19
  • Thanks for update! :) No worries, just nudging you in right direction.
    – Rarst
    Commented Jan 30, 2012 at 17:18
  • Thank you very much Rarst, i use StackExchange only asking 'till now. Was time to start to try to answer ;) ;) ;) Commented Jan 30, 2012 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.

  • 1
    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
    Commented May 19, 2011 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
    Commented May 19, 2011 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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