Support » Plugin: Private groups » How can I choose my own group names?

  • 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 1 month, 3 weeks ago by laymonk.
Viewing 7 replies - 1 through 7 (of 7 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.

    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 1 month, 3 weeks ago by laymonk.
    Plugin Author Robin W

    (@robin-w)

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

    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);
    }

    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 1 month, 3 weeks ago by laymonk.
    • This reply was modified 1 month, 3 weeks ago by laymonk.
    • This reply was modified 1 month, 3 weeks 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 1 month, 3 weeks ago by Robin W.
Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.