Skip to:
Content
Pages
Categories
Search
Top
Bottom

Show members list in private group


  • bambidotexe
    Participant

    @bambidotexe

    Hello,

    I would like to show the members list in private group to users who do not belong to the said group.
    I was thinking i had to change access and visibility of the nav items so i did that:

    function change_access_group_nav_tabs() {
      if(bp_is_group()) {
        buddypress()->groups->nav->edit_nav( array('visibility' => 'public'), 'members', bp_current_item() );
        buddypress()->groups->nav->edit_nav( array('access' => 'anyone'), 'members', bp_current_item() );
      }
    }
    add_action( 'bp_actions', 'change_access_group_nav_tabs' );

    But it didnt work…

    Any suggestion how to proceed?

    Thanks in advance 🙂

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

  • bambidotexe
    Participant

    @bambidotexe

    up,

    no idea?


    bambidotexe
    Participant

    @bambidotexe

    up

    still cant figuring out 🙁


    bambidotexe
    Participant

    @bambidotexe

    I found a workaround, I’am quite not completely satisfied but…

    First of all, disable members list on group:

    function change_access_group_nav_tabs() {
      if(bp_is_group()) {
        buddypress()->groups->nav->edit_nav( array( 'user_has_access' => false ), 'members', bp_current_item() );
      }
    }
    add_action( 'bp_actions', 'change_access_group_nav_tabs' );

    (btw, setting the value to true actually make the the nav items always here, but we still can’t access the group list on click)

    And then I simply add a custom BP Group Extension to make my own members list:

    class Group_Extension_List_Members extends BP_Group_Extension {
        /**
         * Here you can see more customization of the config options
         */
        function __construct() {
          $args = array(
              'slug' => 'members-list',
              'name' => 'Membres',
              'access' => array( 'anyone'),
              'show_tab' => array( 'anyone'),
              'nav_item_position' => 12,
              'screens' => array(
                  'create' => array(
                      'enabled' => false
                  ),
                  'edit' => array(
                        'enabled' => false
                  ),
              )
          );
          parent::init( $args );
        }
        function display( $group_id = NULL ) {
          //Remove user who do not belong to the group on members loop
          function filter_for_groups( $members_template_has_members, $members_template, $r ) {
            for ($i=sizeof($members_template->members)-1; $i >= 0 ; $i--) {
              $user_id = $members_template->members[$i]->id;
              if(!groups_is_user_member( $user_id, bp_get_group_id() )){
                $members_template->member_count = $members_template->member_count-1;
                array_splice($members_template->members, $i, 1);
              }
            }
            if ($members_template->member_count <= 0) {
              return '';
            } else {
              return $members_template_has_members;
            }
          };
          add_filter( 'bp_has_members', 'filter_for_groups', 10, 3 );
    
          require('/Your/theme/custom/members/loop/members-loop.php');
        }
    }
    bp_register_group_extension( 'Group_Extension_List_Members' );

    Hope it will help other in the future, And I’m still open to know the good way to proceed.

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