this should get you close to what you want – not fully debugged or tested, so you might need to play with it
in essence in the user meta ‘private_group’ is set to the groups as a string with ‘*’ as delimiter eg
*group6*group8*group36*group39*group102*group103*group38*
so
//add assign group to register,
add_action ('bbp_user_register', 'rew_add_group') ;
//and to wp-login
add_action('wp_login', 'rew_add_group_login', 10, 2);
//and on every visit
add_action('init', 'rew_add_group_on_init');
function rew_add_group ($user_id) {
if ($user_id == 0) return ; // bail if no user ID
rew_set_group ($user_id) ;
}
function rew_add_group_login($user_login, $user) {
$user_id = $user->ID ;
rew_set_group ($user_id) ;
}
function rew_add_group_on_init () {
$user = wp_get_current_user();
$user_id = $user->ID ;
rew_set_group ($user_id) ;
}
function rew_set_group ($user_id) {
$check = get_user_meta ($user_id , 'some_parameter' , true ) ;
if ($check == 'hello') {
$newgroup = 'group38' ;
}
else return ;
$group_string=get_user_meta( $user_id, 'private_group',true);
$group_string = rtrim($group_string, '*');
$group_list = explode ('*' , $group_string) ;
//if exists, then dont need to add
if (in_array ( $newgroup, $group_list)) {
return ;
}
else {
$group_list[] = $newgroup ;
$new_list = implode ('*' , $group_list).'*' ;
update_user_meta( $user_id, 'private_group', $new_list);
}