Skip Navigation

[Resolved] How do I create Custom roles and Post Groups in the background?

This support ticket is created 7 years, 1 month 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.

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Author
Posts
#574182

Hi there
I am servicing a number of customers in the same system, and would like to do the following.

When I create a new customer (CPT) in the system using CRED I would like to:
- create a couple of Access Custom Roles (e.g. tm_37_user and tm_37_editor) .. where 37 is the customerID
- create one or more Access Post Groups (e.g. tm_37), and update the customer record with the wpcf-custom-group value (e.g. wpcf-custom-group-a6b14a3123d327627a887a6a442d427f,) so that it can later be applied to _wpcf_access_group field of posts created by the client editors (using CRED forms and the hook cred_save_data)

How do I do that?

I would also like to know if Access (and Toolset in general) support users having multiple roles? I realise that Access (and native WP) only allow one role per user, but several other access management plugins extend this to allow multiple and hierarchical roles. If this is possible in Toolset it will come in handy.

Thanks in advance.

Best
Ken

#574247

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ken,

Thank you for contacting our support forum.

Actually I do not recommend creating a custom role each time a user is created as it will create a lot of roles to micromanage for each user individually and can be cumbersome in the long run.

So I would recommend grouping your users into various roles and allowing each user to create a profile based on the role you want them to have. These roles will already be pre-setup in the post group information.

Unfortunately no toolset doesn't support this at the moment.

Thanks,
Shane

#574266

Hi Shane
A customer is, in my case, not equal a user.
Each new Customer (CPT) will have multiple users in the system.
So customer 37 will have a couple of roles. Then the users of customer 37 will be given one of these roles.
But - to my question - how do I do the two things I describe?

Sorry to hear that Access/Toolset doesn’t support multiple roles per user. Please add that to the wish list. It would be great value.

Thanks
Ken

#574274

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ken,

I thought about this, however the role can be created but this will need to be a custom solution, which means that CRED can't be used to create a new user because a role needs to be selected. So the user will need to be created from a custom form that was built and using a php hook to set the user role.

What we use to do is create a post form and then hook into the form when it is submitted to create a new user based on the details that were provided but this is for a basic user creation.

Regarding the automatically adding to the post group there isn't a hook for this so it will need to be done through the backend.

Thanks,
Shane

#574276

Okay
My questions are:
1: how do I, from code (eg function, hook), create new Access Custom Roles?
2: how do I create Access Post Groups, again from code, and retrieve the Post Group ID ( wpcf_custom_group value) to be used elsewhere?

Beda has previously explained how to add the Post Group ID to a Post by using a CRED hook.

Thanks
Ken

#574292

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ken,

This can be done with a regular wordpress hook.

https://codex.wordpress.org/Function_Reference/add_role

I can possibly escalate this one to see if there is a way to do it with a hook but it will take some time.

Thanks,
Shane

#574358

Hi Shane
Okay, if it is just a normal WP role, it will work. And I can use a CRED hook.

What about question 2 - how to create Access Post Groups?

Best
Ken

#574555

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ken,

Yes this creates a regular wordpress role.

Also I checked to see if I could find a function that could easily create a new post group but was unable to do so. So its seems as if its not possible to hook into the function to create a new post group through code.

Thanks,
Shane

#574566

Okay Shane
Can you tell me where I can submit suggestions for product enhancements?

#574666

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ken,

Product enhancement or feature requests can be made through our forums by creating a ticket and setting the tags and topic as a feature request.

Thanks,
Shane

#575464

I will make a couple of suggestions for enhancements re multiple roles per user and also re creating post groups and assigning them to posts via code.
Right now the latter can be done semi-manually (Beda has shown me in another ticket), but I need it done as part of code.