Your cart is currently empty!
programatically create group from template
—
by
Is there a way to allow a registered user to create a group with defined capabilities?
when my clients register and create their own pages, they need to be able to
Posted in Groups
Comments
3 responses to “programatically create group from template”
Hey Torben,
You’re welcome, I’m glad I could help and my apologies for forgetting to mention the documentation page where we have useful examples on Groups API:
– https://docs.itthinx.com/document/groups/api/examples/
Apart from these examples and if you still need some guidance on the API, please don’t hesitate to follow-up here.
Kind regards,
George
Hi George,
Thanks very much for this. I really appreciate it. Can you just tell me where I should be looking to find more documentation surrounding creating and adding members to groups. I don’t have any problem doing so from the admin page, but I would very much like to continue to do this programatically. Following your lead above I can get my form to add the necessary group but ideally I would also be setting its parent group at the same time.
Thanks again for your help.
Torben
Hi Torben,
Welcome to our support forum.
The method you can use to create a group programmatically is:
if ( !Groups_Group::read_by_name( 'Title' ) ) {
$group_id = Groups_Group::create( array( 'name' => 'Title' ) );
}
and once it is called a new group will be created and named as Title if it doesn’t already exist. Obviously you can call it the way that it fits your project, ie once another hook is triggered.
Furthermore, since version 2 of Groups, support for capabilities has been dropped and therefore I would recommend you to avoid using them. With the current version of Groups whenever a user is a member of a group, the user automatically has access to all the posts restricted to that group and vice versa.
Kind regards,
George