Support » Plugins » Hacks » I can't remove capability from specific user

  • I’ve been having trouble removing ‘publish posts’ capability from a specific user.

    if ($violations >= $bans){
    		$user = new WP_User($userid);
Viewing 3 replies - 1 through 3 (of 3 total)
  • This is broke. Try it out yourself.

    specifically, the remove_cap, add_cap to WP_User ability.
    If you follow this it will still not work.

    I’m giving up at this point, I wrote a little more of the summary of the problem and posted the problem plugin here if anyone can solve the problem.

    Tim Smith


    I wanted to remove a capability from a user (leaving it in the role) as well and after a lot of experimenting and browsing through the WP core I have found this works:


    What happens is that $user->add_cap() puts an entry into the user capability overrides and $user->remove_cap(), deletes an entry from the overrides. To actually remove a capability the user inherits from their role(s) you have to use add_cap with a grant value of false. Basically the function names would be better called add_override and remove_override.

    If you find that still isn’t producing the result you want, it may be that you need to be using get_user_to_edit($id) to generate your user object.

    This works in 3.1.4, I haven’t tried out 3.2 yet.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I can't remove capability from specific user’ is closed to new replies.