Group Accounts - Functions

Here's a list of some useful functions and methods included in the plugin:

rcpga_group_accounts()->members->is_group_owner( $user_id = 0 )

Checks if a given user is the owner of a group. $user_id can be omitted to check the current user. Example:

if ( rcpga_group_accounts()->members->is_group_owner() ) {
    // Current user is a group owner.
} else {
    // Current user is not a group owner.
}

rcpga_group_accounts()->members->is_group_admin( $user_id = 0 )

Checks if a given user is a group admin. $user_id can be omitted to check the current user.

if ( rcpga_group_accounts()->members->is_group_admin() ) {
    // Current user is a group admin.
} else {
    // Current user is not a group admin.
}

rcpga_group_accounts()->members->is_group_member( $user_id = 0 )

Checks if a given user is a group member. $user_id can be omitted to check the current user.

if ( rcpga_group_accounts()->members->is_group_member() ) {
    // Current user is a group member.
} else {
    // Current user is not a group member.
}

rcpga_group_accounts()->members->get_role( $user_id = 0 )

Returns the group role of a given user. Returns a role name ("owner", "admin", "member", "invited") or false if the user is not in a group. $user_id can be omitted to check the current user.

rcpga_group_accounts()->members->get_group_name( $user_id = 0 )

Returns the name of the given member's group (or false if none exists). $user_id can be omitted to check the current user.

rcpga_group_accounts()->members->get_group_id( $user_id = 0 )

Returns the ID number of the given member's group (or  false if none exists). $user_id can be omitted to check the current user.

rcpga_group_accounts()->members->add( $args = array() )

Adds a new member to a group. Available arguments to be used in $args:

  • user_id (int) - ID of the user being added.
  • group_id (int) - ID of the group to add the user to.
  • role (string) - The new user's role (options: owner, admin, member, invited).
  • date_added (string) - Date the user was added to the group in MySQL format.

rcpga_group_accounts()->members->remove( $user_id )

Removes a user from any group they belong to.

rcpga_group_accounts()->members->remove_all_from_group( $group_id )

Removes all members from a specific group. This is often used when deleting a group.

rcpga_add_member_to_group( $args )

Adds a member to a group. If the user does not exist then it is created. Available arguments:

  • user_email (string) - Email if the user to add.
  • group_id (int) - ID number of the group to add the user to.
  • send_invite (bool) - Whether or not to send the invitation email (default is true).

Returns the ID of the user on success or a WP_Error object on failure.

Example:

rcpga_add_member_to_group( array(
    'user_email'  => 'janedoe@example.com',
    'group_id'    => 5,
    'send_invite' => false
) );

rcpga_send_group_invite( $user_id )

Sends the group invitation link to a given user.

rcpga_get_level_group_seats_allowed( $level_id )

Returns the number of seats allowed for the specified subscription level.

rcpga_is_level_group_accounts_enabled( $level_id )

Checks if group accounts are enabled for a subscription level. Returns true if so, or false if not.

rcpga_get_group_enabled_levels()

Returns an array of all subscription level IDs that have group accounts enabled.