3

I have a WordPress-Site where some people (non-expert clients) need to create/manage users. The site uses multiple custom post types and each user is assigned permissions for one or several of those cpt's. At the moment i see two ways to handle this and i'm not very happy with any of them.

(1) User roles: If i have four custom post types (A,B,C,D) then i would need a lot of User Roles to cover all combinations of capabilities. (Role A, Role AB, Role ABD ...). That's not very convenient for the client to manage.

(2) Capability Management Plugin: If it was me to manage the users i would use a plugin like "User Role Editor". But that is quite complicated to handle for my non-expert clients and the risk of messing up the system is high.

What i think of is to have simple checkboxes (at least when creating a new user) where the client can choose the custom post types the new user should be able to access. Like: this user will be able to do everything with cpt A and B and D.

Is there a way to do this and is this even something you should do with WordPress?


UPDATE

@RyanLoremIpsum pointed me in the right direction so i was able to write a little plugin that is as simple as i need it to be. Looks something like that:

choose the cpt's a user should be able to access

3
  • That's great! Thanks for posting the final product. – iyrin Feb 15 '14 at 10:11
  • whats the name of your plugin and if its available for download – user54289 Jan 7 '15 at 1:15
  • @user54289 The plugin is not public, not really finished, not well written, not localized... But you can have a look at the code for a starting point: DNI User Permissions – Christoph Jan 7 '15 at 11:41
0

You don't necessarily have to assign roles to manage the user's capabilities.

First, register your custom post types with their respective capabilities. See capabilities under Function Reference/register post type - Parameters

Managing User Capabilities

You can use add_cap or remove_cap to add or remove user capabilities for a specific user.

// Add capability to a specific user  
$user = new WP_User( $user_id );  
$user->add_cap( 'can_edit_posts');  

// Remove a capability from a specific user.
$user = new WP_User( $user_id );
$user->remove_cap( 'read_private_posts' );

This is handy because it allows you to grant a user capabilities that do not belong to the user's assigned role.

For example, you may create a form with check boxes for each post type like you were saying. For each box checked, it would grant a given user ID the capabilities you created when you registered that post type. Likewise, unchecking a box could remove the capabilities.

1
  • You can also use the plugin "Members", that give you a UI for change roles and capabilities. – bueltge May 21 '14 at 9:50

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