programatically create group from template

Posted in

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

3 Responses to programatically create group from template

  1. George December 7, 2021 at 5:20 pm #

    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

  2. Torben Berns December 7, 2021 at 3:23 pm #

    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

  3. George December 6, 2021 at 9:55 am #

    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

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share