0

I'm looking to create a membership-only site which will serve to display logged-in users their company's stored documents.

  • I have a custom post type named Boxes.
  • I have a custom taxonomy called Company (non-hierarchal in case that matters)

What I wish to accomplish, is to be able to create custom roles for users that will give them access to any items within the taxonomy associated with their role.

Essentially, Users with the role ACME Corp would be allowed to access posts within the Boxes post type that have the taxonomy acme-corp assigned to them. I mean on the front end. The Dashboard will be blocked for all except Admins.

Creating taxonomies and custom post types isn't a big deal, but I don't know where to begin when it comes to A) creating custom roles and B) to allow those roles to only access the specified taxonomy/taxonomies.

Note: I use ACF5 PRO quite a bit, so a solution that involves ACF5 PRO is acceptable.

Edit: Made the goal a bit clearer

2 Answers 2

1

First I have a question, what you want to give them access to. Editing posts that have a certain category or seeing it on the site?

When it comes to Roles, as is the case usually the codex is a great place to start - http://codex.wordpress.org/Roles_and_Capabilities. Specifically http://codex.wordpress.org/Function_Reference/add_role.

2
  • Oh right, sorry. I want them to be able to read the post types, so not the Dashboard. I'll block Dashboard access. Commented Nov 18, 2014 at 10:25
  • I've amended my question. Commented Nov 18, 2014 at 10:28
1

Okay! :)

Where you OK with the answer for A) ? You can figure out how to add/modify roles with the help of Codex?

B) is a bit trickier or there are several ways of accomplishing this. Unfortunately I don't have time atm to write lots of code examples but some ideas!

  • If you've created new roles or added capabilities, in the loop you could check if the current user has role/cap - if not don't print the post. There should be some filter also where you could do this, can't remember right now.
  • Maybe it would be possible to name the role and category the same, do above check in loop?
  • A totally different way could be to create different post_types for the different companies and limit users access to a post_type instead of a category?

Sorry for the diffuse answer, hope it helps any.

2
  • You could look at how this plugin is done - wordpress.org/plugins/allow-categories Commented Nov 18, 2014 at 11:06
  • I haven't had time to look into the first yet, but I will :). Regarding B), each user should be able to have several roles, i.e. access to multiple companies. Which means that the second is out. Third is out as well because I can't add hundreds of post types :). Yes, I was also thinking about the loop. I will have to find some half-decent way of giving each user the correct access from an admin perspective though. Thanks for your suggestions. Commented Nov 18, 2014 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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