Skip Navigation

[Resolved] Designate specific users to see restricted content from front end

This support ticket is created 5 years, 11 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
- 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: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 5 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1220399

I am trying to implement the following:
1) Set Access to only allow view of content for post author
2) Post author can (via the front end) select specific other users and grant them access to the content as well.

Is that possible with Toolset?

#1220618

Hello,

Q1) Set Access to only allow view of content for post author

Yes, it is possible with shortcode [wpv-conditional], for example, in a single post content:
You can get current logged-in user's ID with shortcode:
[wpv-current-user info='id']

Get current post author's ID with shortcode:
[wpv-post-author format='meta' meta='ID']

Us above shortcode as condition of shortcode [wpv-conditional], like this:

[wpv-conditional if=" ('[wpv-current-user info='id']' eq '[wpv-post-author format='meta' meta='ID']') "]
    //the content you want to hide goes here
[/wpv-conditional]

Q2) Post author can (via the front end) select specific other users and grant them access to the content as well.
There isn't such a built-in feature within Toolset, as a workaround, you can try these:
1) Create custom post type "member"
Each member post's author is different user, each user has only one member post

2) Setup many-to-many relationship between Post and "member"
https://toolset.com/documentation/post-relationships/

3) In single post content, display a relationship form for author to connect current post with other "member" posts:
https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/

4) In single post content, display a post view:
- query "member" posts
- filter by
a) Post type relationship between between Post and "member"
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
b) post's author is current logged-in user:
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

- in section "Loop Editor", within shortcodes [wpv-items-found] ... [/wpv-items-found], display current post information, for example:

...
[wpv-items-found] 
[wpv-post-link item="$current_page"]
[/wpv-items-found]
...

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/item-attribute/
$current_page is used to retrieve data from the current page being rendered. It can be used inside a View loop to obtain data from the page on which the View is being rendered.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-items-found
Meta HTML wrapped in [wpv-items-found][/wpv-items-found] will be output if there are any posts | taxonomies | users returned by the View.

https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/
How to Create Custom Searches and Relationships for Users