Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

J.C. Hiatt
J.C. Hiatt
9,393 Points

How to Manage Role Permissions and Search Custom Post Types

I'm creating an 'Equipment Locator' for a construction company. I've created the 'Equipment' Custom Post Type using WPMUDev's CustomPress plugin. I've added the appropriate Custom Fields to the Equipment post type.

Now, I need two things:

First, I need to assign capabilities to two specific roles I've created. I've created a 'Drivers' role and a 'Shop Workers' role. I've tried using Justin Tadlock's Members plugin, but it seems to not be specific enough for what I need.

I need to allow the Drivers role to create new Equipment posts (ONLY Equipment posts), edit existing ones, and that's it. I don't need them to see anything else on the WP dashboard when they login.

I need to allow the Shop Workers role to edit existing post types - that's it.

Secondly, I need a way for employees at the company to search through the Equipment post type - preferably from the admin dashboard (which would mean that's one other permission I need to give the Drivers and Shop Workers), or at least from a page. They need to be able to search by the name of the post as well as any of the custom fields I've defined for the Equipment post type.

The goal here is the have Drivers log locations and mileage of equipment, Shop workers to edit mileage data, admins to create/manage everything, and everybody to be able to search through the Equipment (preferably from the dashboard).

All help is greatly appreciated!! Thanks!

BONUS: Anyone have any code snippets I could insert to trigger an email to an admin once a 'mileage' custom field ('Current Mileage') for the Equipment post type comes within 50 miles of the mileage number when it needs servicing again (this is a custom field, too -- 'Mileage Next Serviced').

2 Answers

Mike Bronner
Mike Bronner
16,395 Points

Have you tried working with the "Members" plugin? It allows for very granular assigning of roles and capabilities. http://wordpress.org/plugins/members/

I imagine it will get you what you need with very little to no additional coding.

Matt Campbell
Matt Campbell
9,767 Points

There's a plugin called user role editors that let's you change a lot but, you're very much in the realm of totally unique and as such, you're going to be looking to build it yourself.

You'd probably be better creating a frontend admin area rather than trying to do these things in the WP admin areas.