Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Disable "leave group" and "request membership" buttons


  • whoaloic
    Participant

    @whoaloic

    Hello,
    I would like the users not be able to leave groups or request membership buttons.
    I have set groups to private.

    Cheers

Viewing 12 replies - 1 through 12 (of 12 total)

  • danbp
    Moderator

    @danbp

    Hi,

    leave groups & request membership use the same button, depending the context. See reference.

    Try this if you use only private groups

    function xyz() {
    global $groups_template;
       if ( bp_is_active(group) )
          return '';
    }
    add_filter( 'bp_get_group_join_button', 'xyz' );

    Reference: wp-content\plugins\buddypress\bp-groups\bp-groups-template.php:2747


    whoaloic
    Participant

    @whoaloic

    Thank you @dandb.
    Tested and approved 🙂


    5high
    Participant

    @5high

    I think this is just what I need too – but will it work for public groups, though in a members only site?

    I’ve set BP so that only admins can create new groups, I only have 3 groups, and have added the code to automatically join all new members to all groups (which seems to be working well) – found here: https://buddypress.org/support/topic/how-to-add-new-members-to-groups-automatically/

    By the way @danbp or @whoaloic can you confirm that I would copy the file bp-groups-template.php and put it in my child theme\buddypress\bp-groups\bp-groups-template.php and then edit line 2747?

    Many thanks.


    5high
    Participant

    @5high

    Nope, not the right solution for me. Any other code you can think of?
    Many thanks.


    5high
    Participant

    @5high

    Ok, I know it’s not the correct php way, but in lieu of any other option I’ve found how to remove showing it with css – posted in BuddyBoss here: http://www.buddyboss.com/support-forums/topic/1st-month-feedback-mobileresponsive-theme/ and I put this code…
    #buddypress #admins-list div.action a, #buddypress #mods-list div.action a, #buddypress #members-list div.action a, #buddypress #groups-list div.action a, #buddypress #friend-list div.action a{display:none;}
    in my child theme style.css file.
    Hope it helps other who are stuck too 🙂


    5high
    Participant

    @5high

    No, that code didn’t work either – but this does:

    .group-button .leave-group {
      display:none !important;
    }

    and this removed the container it was in so you don’t get left with a 26px gap:

    .buddypress div#item-header div#item-header-content #item-buttons {
      height: 0px;
    }

    Not perfect or the correct php way but it is a solution for those that can’t make the first one here work.

    Cheers.


    Garrett Hyder
    Participant

    @garrett-eclipse

    Came across this and tried @danbp’s solution with no avail until i realized bp_is_active should be looking for ‘groups’ as a string and with s. But in any case that check isn’t necessary as the filter will only be executed for groups so that check is redundant and the global group_template isn’t needed either.
    Here’s what I’ve employed with success.

    // Remove Join/Leave Button
    function bp_remove_group_join_button() {
        return '';
    }
    add_filter( 'bp_get_group_join_button', 'bp_remove_group_join_button');

    *I know old topic, but might as well provide the working function for future finders.


    5high
    Participant

    @5high

    Thanks so much for posting this info! I’d just found that my previous work-around wasn’t working anymore, but your code above works a treat.
    For anyone else looking to do this, just add it into your bp-custom.php file in the plugins folder (NOT the buddypress folder, but in the root of the plugins folder).
    Much appreciated 😉


    welshlamb10
    Participant

    @welshlamb10

    @garrett-eclipse

    Is it possible that this can only apply to a role such a custom wp role e.g ‘member’

    // Remove Join/Leave Button
    function bp_remove_group_join_button() {
        return '';
    }
    add_filter( 'bp_get_group_join_button', 'bp_remove_group_join_button');

    Appreciate any tips of code guidance.

    Thanks


    Garrett Hyder
    Participant

    @garrett-eclipse

    @welshlamb10 I believe that should be possible.

    
    // Remove Join/Leave Button
    function bp_remove_group_join_button( $button, $group ) {
        $current_user = wp_get_current_user();
        if ( in_array( 'member', (array) $current_user->roles ) ) {
            return '';
        }
        return $button;
    }
    add_filter( 'bp_get_group_join_button', 'bp_remove_group_join_button', 10, 2);
    

    The filter gives access to the $button and $group, then you can use the current user to determine if $button should be returned or an empty string.

    The above code will check the current user to see if they have the ‘member’ role. If they do the button is suppressed otherwise the button will be there.

    Hope that helps


    welshlamb10
    Participant

    @welshlamb10

    That’s fantastic – thank you for the pointers, any idea how to do the same for when they click the group?

    The buttons have gone but clicking the group shows – request access form.


    Garrett Hyder
    Participant

    @garrett-eclipse

    I assume you’re talking about the group listing when referring to ‘clicking the group’. In that case I believe you’d want to customize the groups/groups-loop.php template by copying it into your own theme and conditionally remove the links if the current user isn’t a member.
    Here’s docs on the template hierarchy in Buddypress – https://codex.buddypress.org/themes/theme-compatibility-1-7/template-hierarchy/

    That should allow you to control that list of groups and suppress links depending on role.
    As to the request access form if for some off chance they make it to that screen, if you want to suppress the form with a blocking message when they’re a member you can use the same template replacement concept to replace groups/single/home.php

    Or potentially this plugin by @imath may be more appropriate as you could just make the groups private/hidden;
    https://github.com/imath/altctrl-public-group

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