Skip Navigation

[Resolved] How to show toolset-edit-post-link for only Admin and Post Owner

This thread is resolved. Here is a description of the problem and solution.

Problem: I have created a Form to edit a post, and I would like to display the Edit Post Form link to only site admins and to the post author. Other site visitors should not see this link.

Solution: Use a combination of Access Control shortcodes and conditional HTML to handle the conditional display of this link.

[wpv-conditional if="( [wpv-post-author format='meta' meta='id'] eq [wpv-current-user format='meta' info='id'] )"]
Current User is post author. [toolset-edit-post-link layout_slug='program-edit-layout' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]
[/wpv-conditional]
[toolset_access role="Administrator" operator="allow"]
[wpv-conditional if="( [wpv-post-author format='meta' meta='id'] ne [wpv-current-user format='meta' info='id'] )"]
Current User is admin but not author: [toolset-edit-post-link layout_slug='program-edit-layout' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]
[/wpv-conditional]
[/toolset_access]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-author

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-current-user

This support ticket is created 5 years, 3 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)

Author
Posts
#1317047

Please review this ticket below

https://toolset.com/forums/topic/toolset-edit-post-link-does-not-work/

and this ticket

https://toolset.com/forums/topic/toolset-edit-post-link-does-not-work-for-post-owner/

If we disable edit_published_posts capability then no edit link is shown for the Post Owner.

If we enable edit_published_posts capability then edit link is shown for all users obtaining a specific Role (Practitioner).

We need to show toolset-edit-post-link for only Admin and Post Owner who is a Practitioner.

Thanks.

#1317139

Hi, a combined conditional and Access Control shortcode approach could work here, depending on how your capabilities for the Author role and this Form are set up in Access Control. For example :

[wpv-conditional if="( [wpv-post-author format='meta' meta='id'] eq [wpv-current-user format='meta' info='id'] )"]
Current User is post author. [toolset-edit-post-link layout_slug='program-edit-layout' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]
[/wpv-conditional]
[toolset_access role="Administrator" operator="allow"]
[wpv-conditional if="( [wpv-post-author format='meta' meta='id'] ne [wpv-current-user format='meta' info='id'] )"]
Current User is admin but not author: [toolset-edit-post-link layout_slug='program-edit-layout' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]
[/wpv-conditional]
[/toolset_access]

The nested conditional inside the toolset_access shortcode may not be necessary if Admins are never authors of these posts. Otherwise, it's necessary to prevent duplicate edit post links for Admins who are also the authors of these posts.

Let me know if I've misunderstood the requirements here and we can discuss other options.

Conditional HTML documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

Access Control shortcode documentation:
https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/

Post Author shortcode documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-author

Current User shortcode documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-current-user

#1317279

My issue is resolved now. Thank you!