Title: Creating and assigning groups &amp; capabilities programmatically?
Last modified: August 22, 2016

---

# Creating and assigning groups & capabilities programmatically?

 *  [ypeynaud](https://wordpress.org/support/users/ypeynaud/)
 * (@ypeynaud)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/creating-and-assigning-groups-capabilities-programmatically/)
 * Hi there,
 * First thank you and congratulations for the great Groups plugin! I have enjoyed
   using it to protect pages “by hand” for groups of users through the ultra-simple
   UI you provide in the WP backend. But I have now to go a step further by doing
   things programmatically in php templates and I am afraid I need some advice.
 * What I was conveniently doing by hand was, for a set of manually create pages:
    - define both a pair group-capability to protect the pages
    - assign users to this pair for them (only) being able to read the pages
 * I now have to do the same in php for a set of pages created programmatically.
   I understand how to do the second step (assign users to group) thanks to the 
   Groups_User_Group::create class. But I am lost in the API for achieving the first
   step, which I understand should result in a list of several sub-steps like:
    - creating a group
    - creating a capability and pairing it with the group
    - protecting the pages with the group/capability pair: is it just filling up
      a groups-groups_read_post custom field?
 * I am rather a beginner than an expert in php. Do you have some code examples 
   to help me out? Or some more precise advices on how to use the API for achieving
   these steps?
 * Many thanks in advance!
    Yves.
 * [https://wordpress.org/plugins/groups/](https://wordpress.org/plugins/groups/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [ypeynaud](https://wordpress.org/support/users/ypeynaud/)
 * (@ypeynaud)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/creating-and-assigning-groups-capabilities-programmatically/#post-5414284)
 * Hi again,
 * [@itthinx](https://wordpress.org/support/users/itthinx/): any clue for me? I 
   would appreciate it in order to be able to move forward on this issue. I am quite
   stuck 🙁
 * Thanks in advance,
    Yves.

Viewing 1 replies (of 1 total)

The topic ‘Creating and assigning groups & capabilities programmatically?’ is closed
to new replies.

 * ![](https://ps.w.org/groups/assets/icon-256x256.png?rev=983146)
 * [Groups](https://wordpress.org/plugins/groups/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/groups/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/groups/)
 * [Active Topics](https://wordpress.org/support/plugin/groups/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/groups/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/groups/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [ypeynaud](https://wordpress.org/support/users/ypeynaud/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/creating-and-assigning-groups-capabilities-programmatically/#post-5414284)
 * Status: not resolved