Groups API question

โ€”

by

hello, sorry – wrong forum to post in but I can’t see where to post my question.

I am wanting to use Groups_User_Group::create for adding a user to a group. but can’t seem to get it to work.

For testing purposes I am using my test account with user id: ‘rjbwarren@tiscali.co.uk’ (I use email addresses as the login ID for accounts on my site)

and for testing purposes my group is called “SAGE” – Group id 2

I have set up the following:

$user_id=’rjbwarren@tiscali.co.uk’; ;
$group_id=’2′;

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

However when I run it, it’s not adding the user to that group.

Am I missing a lot of other required configuration here, or is there just some mis-configuration?

I will, at some point enable a user to add themselves to multiple groups.


Comments

3 responses to “Groups API question”

  1. Antonio,

    You are a star!!! thank you so much. I wasn’t miles off, but you have got be back on track.

    So grateful ๐Ÿ™‚

    Rich

    1. perfect ๐Ÿ˜‰

  2. Hi,
    “Groups_User_Group::create” needs user’s id. You can use for example:

    $user = get_user_by( 'email', 'rjbwarren@tiscali.co.uk' );
    if ($user) {
    $result = Groups_User_Group::create( array( "user_id"=>$user->ID, "group_id"=>2 ) );
    }

    cheers

Share