BuddyDev

Search

[Resolved] Hook to remove button for specifc group taxonomy

  • Participant
    Level: Initiated
    Posts: 2
    Rob Sumner on #41969

    Hi,

    I am building a site for a school.

    I have divided groups into two taxonomies (kids and classes)

    The ‘Classes’ groups are created by an admin(teacher). The admin decides which pupils to add to those groups.

    I am trying to remove the Join and Leave buttons to prevent the pupils from adding or removing themselves from the Classes groups.

    The ‘Kids’ taxonomy can work as normal and are created by the kids themselves.

    Everything I have tried so far either removes all buttons, or leaves all buttons for all groups.

    Can anyone help? Thanks.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #41985

    Hello Rob,

    Thank you for posting here. Please let me know the following things:

    1. Are you using BuddyPress Or BuddyBoss PlateForm?
    2. If BuddyPress, Which template pack you are using means ‘BP Legacy’ or ‘BP Nouveau’.

    One more thing, I am assuming by taxonomies you are referring to BuddyPress group types.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 2
    Rob Sumner on #41992

    Hi Ravi,
    Thanks for replying.
    I am using BuddyPress with the Nouveau template pack (and Buddy X theme)
    Yes, the taxonomies are the BuddyPress Group types.

    Thanks,
    Rob

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #41998

    Hello Rob,

    Thank you for the acknowledgment.

    Please try the following code and let me know if it works or not.

    
    
    add_filter( 'bp_get_group_join_button', function ( $button, $group ) {
    
    	// If not public groups return button.
    	if ( 'public' != $group->status || groups_is_user_member( get_current_user_id(), $group->id ) ) {
    		return $button;
    	}
    
    	$group_types = (array) bp_groups_get_group_type( $group->id, false );
    
    	// Replace by your group type id.
    	if ( in_array( 'classes', $group_types ) ) {
    		$button = array();
    	}
    
    	return $button;
    }, 10, 2 );
    
    

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 2
    Rob Sumner on #42057

    Hi Ravi,

    Many thanks for your help. Unfortunately, the code did not work, but I was able to use some of your code combined with another to create a solution that does seem to work:

    //remove Join/Leave Button
    function bp_remove_group_join_button( $button, $group ) {

    $group_types = (array) bp_groups_get_group_type( $group->id, false );

    // Replace by your group type id.
    if ( in_array( ‘class’, $group_types ) ) {
    return ”;
    }

    return $button;
    }
    add_filter( ‘bp_get_group_join_button’, ‘bp_remove_group_join_button’, 10, 2);

    This takes all control away from the front-end so only admins can add or remove members (children) from the class groups.

    Thanks,
    Rob

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #42071

    Hello Rob,

    Thank you for the acknowledgment. I am glad to know that you fix it on your own.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved