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.

Is there any way to assign custom capabilities to user, I'm NOT talking about User Role.

I'm running a multi author blog where I assigned user role of "Author" to all of my authors. But I need a plugin or function.php snippet that remove a capability(not the role) from USER-ID

NOTE -

I dont want to assign/revoke capabilities to role ( administrator/author etc) I want to assign/revoke them to specific user using that users ID.

UPDATE - 08/01/2012

I have blog with suppose 50 authors, A author have capabilities to do post, comment, edit, update, send emails, share etc. but when a user misuses one of this feature I want to revoke that capability/capabilities from that user.

But If I decide to using roles I'd have to create so many user roles with different capabilities such as

  • cannot send
  • cannot send & comment
  • cannot send & comment & post etc.

Is there a way to revoke a capability from user(not the USER-ROLE)

share|improve this question
    
add comment

3 Answers

up vote 1 down vote accepted

Finally, I've figured out a way to do it using WP_user Class.

Snippet to add/remove capability to/from specific user -

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

There is special function in capabilities.php in the wp_user class to assign/revoke capability to/from user.

share|improve this answer
add comment

you can create a new role with required capabilities and then assign the user to it.

you can use add_role() and pass the capabilities needed.

share|improve this answer
    
thanks for your reply, but I was looking to add/remove a capability from user not from role.. However I've figured out a way to do it. See answer. –  amit Aug 1 '12 at 9:19
add comment

If what you want is to assign capabilities to already existing roles or (already created custom roled) then there is global variables called $wp_roles

//suppose you have a custom role called 'architect' and you want to add a capability called `can access architect zone`
global $wp_roles;
$wp_roles->add_cap( 'architect', 'can_access_architect_zone' );
//add to default roles
$wp_roles->add_cap( 'administrator', 'monitor_architect' );
share|improve this answer
    
thanks, but using wp_user I can assign/revoke a capability to user.. added my answer for others. –  amit Aug 1 '12 at 9:20
add comment

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.