Skip Navigation

[Resolved] Assigning User(s) Access to View Custom Post Type Relationship Entries

This support ticket is created 5 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 5 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#1226959

I set up a one to many relationship for two custom post types - folders and documents, assigning documents to folders.

How can I set up the site so that I can enable certain users to see certain folders and respective documents? Could this happen when I create a folder using CRED and include a field that lists users as a multiple checkbox field so that I can control which users can view the documents for a folder?

Would I have to set up a custom post type for users that would be in a many to one relationship with folders? Is there a way that this new custom post type could sync with the WordPress users' list so that when a user logs in, she or he will be able to visit a frontend profile page and view only the folders and their documents that the user has access?

Any help appreciated. 🙂 Eric

#1227087

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Eric

Because of the limitations of how checkboxes fields are stored and because of the limited comparison operators available in conditional shortcodes, I envisage this working something like the following.

You add a generic checkboxes or multiselect field to a form for submitting folders/documents where the field options are populated by a View that lists users.

When you submit said form, the field is available as an array of the selected options in the $_POST object, and you use the cred_save_data hook to save this array of users as post meta (i.e. a non-Types custom field).

Then when it comes to display a document that only specified users are allowed to see, you create a custom function that tests whether the current user id is in the list of allowed users for the current post and returns a true-or-false type value.

Your template for displaying the document wraps the content inside a wpv-conditional shortcode which checks your custom function for true or false, so that the content will only be visible if the current user is one of the enabled users for that post.

Let me share a few relevant links and you can see whether that is something you can implement yourself, and you can ask if there is a particular part of the above you need more help with.

https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/