Skip to:
Content
Pages
Categories
Search
Top
Bottom

Disable Group abandonment and Group access request


  • hcmendez
    Participant

    @hcmendez

    Hi, is it possible to disable those actions altogether?

    Our site will be a members directory where the user will register and buy a membership and they will be added to a specific membership group we don’t want users to leave the group.

    I saw a post from 9 years ago but didn’t get any answer.

    Disable Leave Group on Specific Groups

    This is the code the user mentioned:

    if ( $group->is_member ) {
    
    // Stop sole admins from abandoning their group
    $group_admins = groups_get_group_admins( $group->id );
    if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() )
    return false;
    
    $button = array(
    'id'                => 'leave_group',
    'component'         => 'groups',
    'must_be_logged_in' => true,
    'block_self'        => false,
    'wrapper_class'     => 'group-button ' . $group->status,
    'wrapper_id'        => 'groupbutton-' . $group->id,
    'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ),
    'link_text'         => __( 'Leave Group', 'buddypress' ),
    'link_title'        => __( 'Leave Group', 'buddypress' ),
    'link_class'        => 'group-button leave-group',
    );

    This code can do what I need? If so, how can I use this code? I tried with Code Snippets and it didn’t work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Seems I wrote too much? I will post in two parts:

    Hi @hcmendez, I am trying to do exactly the same thing myself and found the post your referenced, which was now made 10 years ago! I have developed a staging test site for a Radio Club, where registration is disabled and all user accounts will be set up for the users. There are 3 levels of membership: member, editor and admin – each with separate user roles. I have a group called “ROC Members” which all levels of membership are in and I do not want them to have the ability to leave (so want to remove the Join/Leave Button from this group (I can manage members from WP backend).

    After some experimentation, I have found a rather poor “workaround”, by adding an extra ‘if’ statement to the code in plugins -> buddypress -> bp-groups -> bp-groups-template.php (where the extra code above is from), which is far from ideal as it can get overwritten on buddypress update.

    
    // SPECIAL G4WKW CODE
    // If NO group mods, STOP ANYONE abandoning that group. 
    $group_mods = groups_get_group_mods( $group->id );				
    $modsno = count( $group_mods );
    if ( $modsno < 1 ) {
    	return false;
    }
    

    As I have not managed to code something that works to identify my specific group, I did a bit of lateral thinking and my code looks to see whether or not a “group_mod” is present in a group and (if not) the Join/Hide button is hidden, like the case of group_admins, when only one is present. I can live with it for now, as I just have to make sure that all other groups have at least one Moderator set, then they work as normal.

    It works fine for me, using BuddyPress Version 10.4.0, under WordPress 6.0.2 and a modified “Wellness Pro Version: 1.1.4” child theme under Genesis Framework Version: 3.3.5.

    I hope it helps, unless and until some kind BuddyPress dev comes in with a proper solution!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar