Support » Plugins » Hacks » Individual capabilities without role

  • I feel like this should be fairly simple, but I can’t figure out where to start. I want to create new capabilities such as “add_wiki_post” and “invite_others” that are linked to certain custom made plugins for my site. That way, I can use current_user_can(“add_wiki_post”) and all will be peachy. My issue is that I don’t want these capabilities to be assigned to a specific role. I want them to be free floating so I can assign them to users individual. Thus one contributor may have “add_wiki_post” but another may not.

    Is this possible with capabilities, or would it be better to create my own set of usermeta and kinda make a second caps system?

    Thanks! I’d love some creative solutions. And, I will release this code as a plugin. I’m adding capabilities to badges.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    Yes, you can have capabilities independent of roles. If you have the user_id, just do this:

    $user = new WP_User( $user_id );
    $user->add_cap( 'add_wiki_post' );

    You then could see the capability added to the ‘wp_capabilities’ usermeta along with the user’s role and if the user were to log in, the function current_user_can('add_wiki_post') would return true.

    The problem is the admin screens are setup to only manage users by role. You’ll more than likely need a custom section on the user profile screen where you can easily assign or remove capabilities independent of roles. This is certainly doable, but it’ll take more than 2 lines 🙂

    That is perfect. I’m attaching capabilities to earned badges and have the system set up to automatically assign the badges. I can attach the capabilities to that action easily enough.


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Individual capabilities without role’ is closed to new replies.