Code Snippets

Assigning a user to a group

Groups_User_Group::create( array( 'user_id' => $user_id, 'group_id' => $group_id ) );

Get all users in a group

$group = new Groups_Group( $group_id );
$users = $group->users;

Get all groups the current user belongs to

$groups_user = new Groups_User( get_current_user_id() );
// get group objects
$user_groups = $groups_user->groups;
// get group ids (user is direct member)
$user_group_ids = $groups_user->group_ids;
// get group ids (user is direct member or by group inheritance)
$user_group_ids_deep = $groups_user->group_ids_deep;

Does the current user belong to the Foobar group?

$is_a_member = false;
require_once( ABSPATH . 'wp-includes/pluggable.php' );
if ( $group = Groups_Group::read_by_name( 'Foobar' ) ) {
$is_a_member = Groups_User_Group::read( get_current_user_id() , $group->group_id );

Does the current user have the make_donuts capability?

require_once( ABSPATH . 'wp-includes/pluggable.php' );
$groups_user = new Groups_User( get_current_user_id() );
$can_make_donuts = $groups_user->can( 'make_donuts' );

Is a post restricted by group?

Assuming that you have the $post_id of the post for which you would check whether it is restricted, you can obtain the group IDs of the groups that are restricting access to it:

$group_ids = Groups_Post_Access::get_read_group_ids( $post_id );
if ( count( $group_ids ) > 0 ) {
    // $group_ids holds one or more IDs of the groups that restrict read access to the post



Groups – The Groups repository on GitHub.

Groups Premium Menu Hide – An example of hiding menu items for members of a Premium group.

Groups Utilities – Set of utilities and extras for itthinx’s Groups

Users Auto Group – Assign automatically new users to a specific group.

Affiliates Auto Group – Add new affiliates to a specific group.

Groups Comments Filter – Left comments in pages where the user has group access.

Groups List Users