Skip Navigation

[Resolved] Give child post edit access to parent post author

This support ticket is created 3 years, 8 months 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 8 replies, has 3 voices.

Last updated by himanshuS 3 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1980325

I have two CPTs: endorsement request and endorsement in an O2O relationship
A user requests an endorsement and the expert gives an endorsement.

Once an expert gives the endorsement, I want the user to have an option to "add the endorsement" to their portfolio.

I am thinking of the following way to do this:
1) Allow experts to submit an endorsement with final status as a draft.
2) Somehow give access to parent post author( the user) access to the draft endorsement.
3) add a "add to portfolio" button using a CRED form to the endorsement and give parent post author access to the button. This button would change the status of endorsement from draft to published
4) add a "remove from portfolio" button using a CRED form to the endorsement and give parent post author access to the button. This button would change the status of endorsement from published to draft
5) hide the two buttons on (4) and (5) from everyone except parent post author

This way the endorsement would be added to the post only after the user has previewed and changed the status of endorsement to published.

I am able to do all these steps except step 2. I am not sure how to give a user (type subscriber) access to an endorsement post created by the expert while making sure no other subscriber can access the endorsement post until it is published by the parent post author.

#1980547

Hello,

In the single "endorsement" post, you can display related "endorsement request" post information with "item" attribute, see our document:
https://toolset.com/course-lesson/displaying-related-posts/

So you can try these:
1) In the single single "endorsement" post, display a post view:
- Query "endorsement request" posts
- Filter by:
a) post author is same as current logged-in user:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/
b) post type relationship between "endorsement" and "endorsement request"
https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items
- In view's loop, display related "endorsement" post information with a content template using "item" attribute
https://toolset.com/course-lesson/displaying-related-posts/#displaying-one-related-item-parent

2) In above content template display the editing "endorsement" post form, which can change the status of endorsement from draft to published
https://toolset.com/course-lesson/front-end-forms-for-editing-content/

#1980603

Thanks Luo. I will try this out. In the meantime, do you mind moving this ticket to the US timezone? I am on central US time and it would be easier to get this done that way.

#1980621

As your request, I have assigned this ticket to Christian, he is in US time-zone

#1981133

Hello, Luo assigned this ticket to me and I am standing by for your update.

#1981417
endorsement post.png

Christian,

Thanks for taking over the ticket. The problem I have is slightly different from the one that Luo solved for,

The thing is I want to have the two change post status forms ON the endorsement template itself. Why is that? Well, imagine you receive an endorsement from someone. You receive an email notification (using CRED form) that shows you the link to the endorsement itself. Now, the endorsement is not publically published yet so no one can see it except the post author (an expert) and you (which is the problem I want to solve). Now imagine you can open the endorsement, you see a button on the endorsement that says ... "Add to Portfolio". You review the endorsement and click on "add to portfolio" and boom.. the endorsement is published. Once that happens, another form button shows up that gives the endorsement requester an option to remove the post from the portfolio. When a user clicks on "remove from the portfolio" the post changes to draft again and the "add to portfolio" button pops up.

This way, the endorsement requester has full control over the endorsement ONCE it is received from the expert.

I have been able to create two forms with just a submit button form - "add to portfolio" and "remove from the portfolio". I have given the requester access to change post status even if they are not the author by using the Access Control for Forms in Toolset where you can say -- edit other posts.

However, I do not know how to get ONLY the requester (subscriber user type) access to a draft or private endorsement post submitted by an endorser (expert post type).

Important note: I am using elementor post template for endorsement.

The uploaded image shows the post when it has been added to the portfolio. Notice the red button to "remove the portfolio". I can access this post as an admin in preview mode as admin can preview any post. I don't want a subscriber user type to preview any post but maybe only the endorsement post whose related parent post (endorsement request) is published by the subscriber.

How can we do this? I saw a custom capability section in the Access Control on Toolset but I am not sure how that works. Maybe it is not relevant. Looking forward to solving this with you.

#1981457

I don't want a subscriber user type to preview any post but maybe only the endorsement post whose related parent post (endorsement request) is published by the subscriber.
I don't think custom capabilities will help here, they are not flexible enough to be effective at managing access per post. I think the best way to achieve this is to allow Subscribers access to preview any Endorsement post, but include a conditional in the Endorsement template. The conditional should test whether the current User role is administrator OR if the ID of the author of the parent Endorsement Request post is the same as the ID of the current logged-in User. If either of those conditions is true, display the contents of the Endorsement post. If neither of those conditions is true, display a message like "You do not have permission to view this post". It would not be a true 404 error, but the content of the Endorsement would be hidden by the conditional.

To get the current User's ID:

[wpv-current-user info="id"]

To get the User ID of the author of a related post, you can use the wpv-post-author shortcode:

[wpv-post-author item="@post-relationship-slug.parent" format="meta" meta="ID"]

In the context of an Endorsement post template, you would replace post-relationship-slug with the slug of the Endorsement Request - Endorsement post relationship. That would give you the User ID of the Endorsement Request author.

Post author shortcode:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-154504

Item attribute explained:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

#1981463

I was hoping you don't say that and come up with a more customized solution but this would work for now.

I am not sure how much of this conditional statement is hackable (as I am not using url params) but the thought of exposing someone else's review to all the other people even by mistake scares me.

I will test your solution and get back to you.

#1981507

My issue is resolved now. Thank you!