• Resolved laymonk

    (@laymonk)


    How can I choose my own group names (instead of Group1, Group2, etc)?

    If these are unchangeable, perhaps we can avoid displaying Group1, Group2, etc … and instead only display the group descriptions … ie, use the fixed group names only internally.

    Also, is there a way to import a group list ?

    Thank you in advance for responding … and I am not shy of going to code, if I have to.

    thanks

    • This topic was modified 4 years, 4 months ago by laymonk.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Robin W

    (@robin-w)

    the group numbers and indeed names are only used for admin. I am not planning to remove the numbers, many sites have lots of groups, and finding them quickly is important. Sorry.

    I haven’t thought about export/import – in fact no-one has ever asked about this. The group names are stored in the options table.

    Thread Starter laymonk

    (@laymonk)

    Thank you very much for responding, and for the explanation.

    One other question (I can create a new support thread, if you prefer):

    Are there any hooks available?

    for instance, upon initial sign-up, to automatically make a user a member of some groups, based on user-meta fields

    thanks

    • This reply was modified 4 years, 3 months ago by laymonk.
    Plugin Author Robin W

    (@robin-w)

    Are you happy coding? if so, then I can probably find functions or hooks

    Thread Starter laymonk

    (@laymonk)

    Yes, that’s the idea … I don’t mind coding this. That would really be most useful for me. Thank you.

    Plugin Author Robin W

    (@robin-w)

    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);
    }
    Thread Starter laymonk

    (@laymonk)

    This is really insightful, thanks a million.

    I see how user_meta can be selected and acted upon.

    I redirect wp_login to a custom login, will that affect the line:
    > add_action(‘wp_login’, ‘rew_add_group_login’, 10, 2);

    Also, using the groupN field is problematic for me because the association between the user-meta values will be with the group descriptions, not their less meaningful id’s.

    So, question for me is:
    Is there a way to access the group descriptions and use that for matching to user-meta?

    • This reply was modified 4 years, 3 months ago by laymonk.
    • This reply was modified 4 years, 3 months ago by laymonk.
    • This reply was modified 4 years, 3 months ago by laymonk.
    Plugin Author Robin W

    (@robin-w)

    what custom login are you using? chances are that it also hooks to that link, so the easiest way is just to test it to see that it works.

    this code should work for a name (untested!)

    function rew_set_group ($user_id) {
    $newgroupname = get_user_meta ($user_id , 'some_parameter' , true ) ;
    //quit if empty
    if (empty ($newgroupname)) return ;
    global $rpg_groups ;
    foreach ( $rpg_groups as $group => $name ) {
    	if ($name == $newgroupname) {
    	$newgroup = $group ;
    	continue ;
    	}
    }
    //quit if the name does not have a group
    if (empty ($newgroup)) 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);
    }
    • This reply was modified 4 years, 3 months ago by Robin W.
    Thread Starter laymonk

    (@laymonk)

    Hi,

    Sorry I have not come back here on this topic. I got dragged into other things and have not looked at it more.

    I was also put off by realising that there were already quite a few users in the system, and making the groups work was going to involve a ton of manual work:

    • First to associate the private groups 1-by-1 to almost a hundred groups. YIKES!
    • Then to associate each user of more than a hundred users to one or more private groups. YIKES!

    The ‘User Management’ section is a nice feature, but only filters by private group’s groups (the roles filter doesn’t really work, and wouldn’t have been that useful anyways … not as much as other user meta fields that mirror the private groups’ names), and that didn’t help me at all in the end.

    In the end, I began to doubt this is a practical solution for my use case. Without a way to manually or easily map forum groups to private groups, and users to private groups, I just don’t see it as a solution.

    I also peered at the DB to see if I could figure out a pattern, so I could address it with sql or php, but because it doesn’t have it’s own custom tables I knew it was going to be more work and time than I was willing to give it.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How can I choose my own group names?’ is closed to new replies.