BuddyDev

Search

[Resolved] Remove Groups Options

Tagged: 

  • Participant
    Level: Enlightened
    Posts: 38
    Javier on #4366

    Hello,

    I’m searching BP codex looking for a hook or something to remove group options, meaning: privacy options (public, private, hidden), invitations…

    My goal is to use groups to segment users. Here at Buddydev you have a great solution to limit the number of groups an user can join (in my case, one group per user, obviously): https://buddydev.com/plugins/buddypress-limit-group-membership-per-user/.

    Also, I just want site administrator to manage groups, so I’d prefer not to allow group admins to change group privacy (public, private…) or send invites. Actually, given this scenario, it doesn’t matter if a group is private or not, this options become pointless.
    I’ve been able to remove the “join this group” button,

    ‘function bp_remove_group_join_button() {
    return ”;
    }
    add_filter( ‘bp_get_group_join_button’, ‘bp_remove_group_join_button’);’

    but I don’t know if is possible to accomplish the above.

    I appreciate any guidance.

    Regards,
    Javier

    *Hopefully the new Group Type functionality will give us more customisation options: https://codex.buddypress.org/developer/group-types/

  • Keymaster
    (BuddyDev Team)
    Posts: 21291
    Brajesh Singh on #4398

    Hi Javier,
    I am sorry for the delayed reply.

    1. The privacy options are hardcoded into the template file and only way to do it will be to override the create/manage group templates.

    If your theme is supplying it, please modify it in your child theme.
    If it is not in your theme you can copy it from

    1. plugins/buddypress/bp-templates/bp-legacy/buddypress/groups/create.php to yourtheme/buddypress/groups/create.php and

    2. plugins/buddypress/bp-templates/bp-legacy/buddypress/groups/single/admin.php to yourtheme/buddypress/groups/single/admin.php

    You can put the conditions using is_super_admin()

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 38
    Javier on #4437

    Hi Brajesh,

    Thank you very much for the guidance.

    I was able to hide privacy options within mytheme/buddypress/groups/single/admin.php, so now ‘mygroup/admin/group-settings/’ is empty for non super admin. But the tab is still there, and I’d like to remove ‘delete-group’ also. Tried this (in a plugin) with no luck:

    function test_remove_group_admin_tab() {
    global $bp;
    if ( ! bp_is_group() || ! ( bp_is_current_action( ‘admin’ ) && bp_action_variable( 0 ) ) || is_super_admin() ) {
    return;
    }
    // Add the admin subnav slug you want to hide in the following array
    // other admin subnav items are: group-settings, group-avatar, group-invites, manage-members
    $hide_tabs = array(
    ‘group-settings’ => 1,
    ‘delete-group’ => 1
    );
    // since BP 2.2
    $slug = bp_get_current_group_slug() . ‘_manage’;

    // Remove the nav item
    foreach ( array_keys( $hide_tabs ) as $tab ) {
    bp_core_remove_subnav_item( $slug, $tab );
    }
    }
    add_action( ‘bp_groups_setup_nav’, ‘test_remove_group_admin_tab’, 9 );

    I read somewhere there are certain issues with bp_core_remove_subnav_item() and other navigation removal functions. I don’t really know what’s happening here.

    Thanks
    Javier

  • Participant
    Level: Enlightened
    Posts: 38
    Javier on #4440

    Hello again,

    I’ve been able to remove the options doing the following (which makes not necessary to overload ‘groups/single/admin.php’ template, I guess):

    function jatstudio_remove_group_admin_tab() {
    if ( ! bp_is_group() || ! ( bp_is_current_action( ‘admin’ ) && bp_action_variable( 0 ) ) || is_super_admin() ) {
    return;
    }

    // Add the admin subnav slug you want to hide in the following array
    $hide_tabs = array(
    ‘group-settings’ => 1,
    ‘delete-group’ => 1
    );

    $parent_nav_slug = bp_get_current_group_slug() . ‘_manage’;

    // Remove the nav items
    foreach ( array_keys( $hide_tabs ) as $tab ) {
    bp_core_remove_subnav_item( $parent_nav_slug, $tab, ‘groups’ );
    }

    // You may want to be sure the user can’t access
    if ( ! empty( $hide_tabs[ bp_action_variable( 0 ) ] ) ) {
    bp_core_add_message( ‘No tienes suficientes permisos para acceder.’, ‘error’ );
    bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) );
    }
    }
    add_action( ‘bp_actions’, ‘jatstudio_remove_group_admin_tab’, 9 );

    The key is to add $component to ‘bp_core_remove_subnav_item()’, which defaults to ‘members’.

    My problem now is that I also need to remove ‘send-invites’ from groups primary navigation. The function is ‘bp_core_remove_nav_item()’ I guess, but this is not working:

    bp_core_remove_nav_item( ‘send-invites’, ‘groups’ );

    It would be nice to remove all of this options from users dropdown menu too.

    Thank you,
    Javier

  • Participant
    Level: Enlightened
    Posts: 59
    טליה שוורץ on #36818

    hey
    i have tried to use the code here:
    https://buddydev.com/disable-buddypress-group-deletion-non-site-admin

    1. i am using buddyboss,
    when creating “bp-custom.php” in my child theme (next to function.php) and posting the code inside this file, it doesn’t work. only if i add it to the functions.php file.
    a. is that ok to leave it in functions.php?
    b. just to understand, was i supposed to create bp-custom.php in other place?

    2. i want to remove also the forum item from the subnav
    but this doen’t work:

    $parent = groups_get_current_group()->slug . ‘_manage’;
    bp_core_remove_subnav_item( $parent, ‘forum’, ‘groups’ );

  • Keymaster
    (BuddyDev Team)
    Posts: 21291
    Brajesh Singh on #36872

    Hi,
    Thank you for the question.

    1. Please put bp-custom.php in wp-content/plugins directory.

    For more details, Please see https://buddydev.com/docs/buddypress-guides/what-is-bp-custom-php/

    2. Forum is special case(added bu group extension).

    You may want to do it like below.

    
    
    function buddydev_disable_group_forums_by_non_site_admin() {
    	if ( ! bp_is_group() || is_super_admin() ) {
    		return;
    	}
    
    	$parent = groups_get_current_group()->slug . '_manage';
    	bp_core_remove_subnav_item( $parent, 'forum', 'groups' );
    }
    
    add_action( 'bp_actions', 'buddydev_disable_group_forums_by_non_site_admin', 200 );
    
    

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 59
    טליה שוורץ on #36875

    that is great!! thank you so much!
    this is an amazing site!

  • Keymaster
    (BuddyDev Team)
    Posts: 21291
    Brajesh Singh on #36903

    Thank you.

The topic ‘ [Resolved] Remove Groups Options’ is closed to new replies.

This topic is: resolved