Skip Navigation

[Gelöst] User access to CPT Taxonomy Terms

This support ticket is created vor 2 Jahre, 4 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. 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+00:00)

This topic contains 5 Antworten, has 2 Stimmen.

Last updated by Jamal vor 2 Jahre, 4 Monate.

Assisted by: Jamal.

Author
Artikel
#2221355

I have setup a custom user role and would like to restrict access to only be able to select certain Categories for the CPT. As an example I have a user role called "Human Resources".

This specific user role "Human Resources" should only be able to post posts to the category called "Jobs and Bursaries" setup by admin. Other CPT Categories should not be accessible and or be able to add new categories.

hidden link

I am using the Toolset Access plugin to do this.

#2221423

Jamal
Supporter

Languages: Englisch (English ) Französisch (Français )

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

Hello and thank you for contacting the Toolset support.

I am afraid that's not possible through Toolset Access. Toolset Access can control who creates the taxonomy terms, by it cannot restrict the terms to assign per user or user role.

If you need to achieve this, you must use a workaround. For example, you can come up with a custom code that is hooked to the save_post action and based on the user role, you can unassign the restricted taxonomy terms.
https://developer.wordpress.org/reference/hooks/save_post/

You may also restrict this user role from accessing the backend, and manage the post creation process using forms. In this case, you can use a generate field(with only the allowed term, manually entered by you), then use some custom code to assign the selected term to the post.

I hope my suggestions make sense to you. Let me know if you have any questions.

#2221435

Would it be possible to:

1. create a post form
2. Displaye pre-defined CPT categories which user is allowed to use.
3. Have the form posted to CPT wich would be assigned only to chosen category?

Reason there would be more than one CPT category options is due to the CPT having different custom fields dependant on category chosen.

#2221449

Jamal
Supporter

Languages: Englisch (English ) Französisch (Français )

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

I am afraid the 2nd step is not possible. Inside a form, the taxonomy field will display all the taxonomy terms. We can't display just a set of them.

However, you can use a custom field(vs taxonomy), and using custom code display only the allowed terms. Then, you will need custom code to perform the assignement based on what the user has chosen for the custom field. This is, somehow, similar to my suggestion of using generic field. Generic fields are not stored on the database at all. They are meant to be handled using custom code.

The hook that can allow you to generate the values for the custom field is wpt_field_options https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options
The hook that can allow you to assign the terms to the post after the form submit is cred_save_data https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#2221453

Is there no way to setup a post form to only post to a specific category term. My problem is that users who work in specific departments (category term) will post in the wrong category term.

#2221513

Jamal
Supporter

Languages: Englisch (English ) Französisch (Français )

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

Unfortunately, that's not possible out of the box. But you can achieve it using some custom CSS and Javascript. The CSS code to hide the field, and the Javascript code to select the term for the field.

Another way, is to pass a post to the form as placeholder, this way the values for the post, will be prefilled in the form, but that will be for all the fields, not only the taxonomy field:

[cred_field form="name of the form" post="123"]

123 being the ID of the post that you want to use as a placeholder.

Finally, I think that the best solution would be some custom code that will assign the taxonomy term to the post based on the user role. That will use the cred_save_data

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