Skip Navigation

[Resolved] Assign permission to a user which owns a post related to it's parent

This support ticket is created 3 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 2.24 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Jamal 3 years ago.

Assisted by: Jamal.

Author
Posts
#2002463

This is a bit tricky to explain, will try to do my best.

Im planning to use toolset cred forms to register NORMAL users(members) and PARTNER users, with toolset api create a post of the cpt "MEMBER" and "PARTNER" and populate data inherited by the creds register form.

There are 3 CPT's envolved in this process. MEMBERS, PARTNERS and REQUESTS.

1 - I believe that these 3 to be interlinked than REQUESTS should be the intermediary CPT? A member can insert a REQUEST (partner can't), member can see only his own requests, partner can see all the requests. This would be a many-to-many.

All views are protected to registered users only.

I know i can define relationships within a cred form (show the dropdown select to choose), all the actions memtioned below are to be implemented on the FRONTEND. This is the workflow:

- a user that is the author of MEMBER post (also from the member userrole) creates a REQUEST and becomes the author of that request. He will be able to see only its own requests. PARTNERS will not be able to see this request until they are assigned to them (threw relationship).
- Me as admin can assign a PARTNER to that REQUEST (on the frontend) and this action will fire an e-mail to the author of the PARTNER POST assigned to warn him with the content of the REQUEST fields.

2 - Is this possible with toolset? Toolset does not allow USER to be connected to a post by a relationship so the MEMBERS and PARTNERS and required, and the information goes always to the authors.
For a perhaps more practical use consider a APPOINTMENT, CLINIC, USER point of view.

User submits an appointment which only clinics can see if i choose that way (assign relationship), assigned clinics receive an e-mail notification and login and see the appointments assigned to them, they confirm the appointment by some action and user gets notified.

Of course there are other issues in between (file uploads) but i believe i can set field conditionals with the aid of generic fields.

Hope i was clear enough to know if this is possible with toolset.

#2002777

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

I don't think that a many-to-many relationship is a correct approach here. Because, once you connect a Member with a Partner, through the intermediary post, you won't be able to create another link. For example, once you set an appointment between a user and a clinic, you can create other similar appointments.

Instead, go with a one-to-many relationship between the REQUEST and the PARTNER. A partner can have multiple requests, but a request is only assigned to one partner. The request's author is the member user who has created it. And there will be no need to create a relationship between the member post and the request post. Unless you have some other use cases that will require such a relationship.

Regarding the notification to be sent to the assigned partner, it will depend on how you do the assignment. A Toolset form notification can be sent on one or more of the following options:
- Send notification to a WordPress user - Send notification to an email specified in an email field included in the form
- Send notification to a WordPress user with an ID coming from a generic field in the form
- Send notification to a specific email address
- Send notification to the post author

I assume that you will perform the assignment using an edit form for the request post. In that case, none of the above options can help. You can still implement a custom PHP code, that will hook into the notification recipients and programmatically pull the assigned partner email as a recipient. Read more about the hook and its example here https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

Check an example of the usage here https://toolset.com/forums/topic/email-notification-to-parent-post-author-when-child-form-is-submitted-2/#post-1995977
This code shows how to use the toolset_get_related_post function to get the related/assigned post(partner), and pull the email from its author. Please note that you will need to adapt it to your relationship's slug.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

I hope this helps. Let me know if you have any questions.

#2004453

Thank you Jamal for your time.

I still have some questions:

1 - So you believe the best way is a one-to-many relationship between the REQUEST and the PARTNER. A partner can have multiple requests, but a request is only assigned to one partner. The request's author is the member user who has created it.
I see what you say about the member profile not beeing needed since he's already the author of the request.

But for example, as an admin and on the frontend, if i assign a partner to a request using the relationship select... will i be able with php to check if relantionship select value was changed? Something like this (focusing on the logic, ignore the fact that it's not really code).

on cred_save_data {
$previous_value = get_relationship_select_previous_value() 
$actual_value = get_relationship_select_actual_value()
if $previous_value == $actual_value {
  do_nothing
}
else {
wp_mail(fire notification to the new partner assigned to the request)
}
}

I see threw the link you provided that we can pull the e-mail from the related CPT (Partner in this case) which is great. im planning on using default wp_mail function instead of cred form notifications.

2 - "I assume that you will perform the assignment using an edit form for the request post. In that case, none of the above options can help."

Yes, the request cred form will have the possibility to assign relationships. But i was thinking about one thing. Can i on the frontend list requests made users and edit them? I mean... this will be a view (with a search) that lists cred forms and i would be able to edit... otherwise the relationship select won't show up correct? Perhaps manually editing the link so that instead of clicking and going to the readonly version of the requests i could go to the edit cred form of that request? Is this possible?

3 - I will need later to perform a search for example... Search for user first name "John" and toolset to list all the users named "John". "Search First Name" will be a search text field. I've searched and i see that in a view i can include a custom field to a parametric search... but this search won't be %LIKE% is that correct? So if i search for JOH, JOHN won't appear?

I dont know if with the wpv_filter_query_post_process we can change the way the view searches works.

Thanks

#2005063

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Regarding the 1st point. There is no such function as "get_relationship_select_previous_value" and "get_relationship_select_actual_value". What we have instead are:
- toolset_association_created
- toolset_before_association_delete
Check their documentation here https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created
You can use toolset_before_association_delete to store the old related post in a custom field using updat_post_meta. And then use toolset_association_created and check if an old related post is saved in the field, then run your code.

Regarding the 2nd point. Yes, you can put an edit link inside the view's loop. So, it will redirect you to that post's edit form. Note, that an edit form needs to be put inside a separate content template. Check this article https://toolset.com/course-lesson/front-end-forms-for-editing-content/

Regarding the 3rd point, Toolset search text is performed against the post's title or/and content, using like %joh% for example. You can use the Relevanssi plugin to perform text search on custom fields https://toolset.com/course-lesson/searching-texts-in-custom-fields-with-toolset-and-relevanssi/
If you don't want to use Relevanssi, and you want to search with like %% in a custom field, you can hook into wpv_filter_query to change the underlying WP_Query object.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

I hope this helps. However, for support rules, we are able to handle only one issue at a time. This helps us to bring you a better service and also helps other users to find all the information here exposed. If you believe that the original question of this topic has been answered, I have to kindly ask you to open a new thread if you need further assistance with this.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.