Dear Sir/Madam,
Refer to ticket https://toolset.com/forums/topic/user-role-and-post-relationship/, I am sorry for my missing to the reply.
I don't know how to re-open the ticket, so I repost here.
I have merchant, advertiser and coupon custom posts, I want to have a custom user role "Manager", "Merchant" and "Advertiser", a "Manager" can create and manage its own merchant, advertiser and coupon custom post, "Merchant" and "Advertiser" are the users who can only manage their own merchant or advertiser custom post and related coupon custom post.
One Merchant User can have one merchant custom post and many coupons
One Advertiser User can have one advertiser custom post and many coupons
A manager can manage Merchant Users and Advertiser Users' merchant and advertiser custom post and all related coupons.
I tried to make the relationship in a diagram for your reference, could you please advise how I can create the user and post-relationship?
I plan to manage from wp-admin first, will it be easier?
Best regards,
Kelvin.
In wp-admin we can grant permissions to "Edit Any" or "Edit Own", "Publish Any" or "Publish Own", etc. The problem is that it's not possible for more than one User to "own" a post. If we make the Merchant User the author of his own Merchant post, then the Manager will not have the ability to edit the Merchant post unless we give the Manager role access to all Merchant posts. So setting up this type of system in wp-admin is more difficult than setting it up on the front-end, where you have the ability to use conditional HTML to show or hide posts based on many different criteria including custom fields and post relationships. I would try the CRED approach first.
I would create these post types:
- Manager - author is the manager User
- Merchant (child of Manager) - author is the merchant User
- Advertiser (child of Manager) - author is the advertiser User
- Coupon (child of Merchant and child of Advertiser) - author is the merchant User or advertiser User
I would create these CRED forms:
- Add Merchant post: Predefine the Manager parent post and hide the field.
- Edit Merchant post: Hide the Manager parent field.
- Add Advertiser post: Predefine the Manager parent post and hide the field.
- Edit Advertiser post: Hide the Manager parent field.
- Add Coupon post: Predefine the Merchant or Advertiser parent post field and hide the fields.
- Edit Coupon post: Hide the Merchant and Advertiser parent post fields.
From there, I would begin adding the forms to the front-end of the site.
For the Add Merchant and Add Advertiser forms, I would use inline toolset_access control shortcodes to restrict the forms to only Manager role Users:
https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/
For the Edit Merchant and Edit Advertiser forms, I would use conditional HTML to test if the current User is the post author, or if the current User's Manager post is a parent of the Merchant or Advertiser post being edited. If either of those is true, show the form. If not, hide the form. This is probably the most complex step.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
For the Add Coupon forms, I would use inline toolset_access control shortcodes again to restrict the form to only Merchant and Advertiser User roles. For the Edit Coupon form, I would use conditional HTML to test if the current User is the author of the Coupon post. If so, show the form.
Dear Christian Cox,
Thanks for your prompted reply and excellent suggestion to the CRED design. I will try your suggestion.
Best regards,
Kelvin.
Okay sure, keep me posted here. I will mark this ticket as pending an update from you. No need to reply right now.