Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hide Admin from Group List

  • Avatar of xKroniK13x
    xKroniK13x
    Participant

    @xkronik13x

    I am creating a social website for many colleges, and created a new group for all of the colleges (roughly 91 right now). Since I created the group, I was auto-assigned as the administrator of it. I don’t want my account accessible or visible to anyone, as I am not attending that college. I have used the script as follows to remove myself from the members list (a list of all members on the buddypress site, regardless of what group they are in):

    add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
    function bpdev_exclude_users($qs=false,$object=false){
     //list of users to exclude
     
     $excluded_user='1';//comma separated ids of users whom you want to exclude
     
     if($object!='members')//hide for members only
     return $qs;
     
     $args=wp_parse_args($qs);
     
     //check if we are listing friends?, do not exclude in this case
     if(!empty($args['user_id']))
     return $qs;
     
     if(!empty($args['exclude']))
     $args['exclude']=$args['exclude'].','.$excluded_user;
     else
     $args['exclude']=$excluded_user;
     
     $qs=build_query($args);
     
     return $qs;
     
    }

    This works great, it completely removes me from the loop, but if you click on a group page, my name will still appear in that loop. I am trying to make my account completely invisible, so this is only half way there.

    I used the following code to make my profile not viewable, but my name still appears, but when you click it you get 404. I want to keep this implemented for the future, so it’s like I don’t exist:

    add_action( 'wp', 'hide_profile_template', 1 );
    function hide_profile_template() {
    global $bp; 
        if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) :
            global $wp_query;
            $wp_query->set_404();
            status_header(404);
            include(locate_template('404.php'));
            exit;
        endif;
    }

    I’ve been adding this code to a new plugin that I named simply “Hide Admin,” if that is relevant at all. I chose to do this opposed to using the functions.php file to simply make it easier to toggle, in case I ever decide to make myself visible in the future.

    I’ve done lots of Googling, and have also attempted to edit the groups-loop file to excluse user-id 1, but it either breaks it completely or simply does not work.

    I’m really at a loss here, I’d appreciate the help! Thanks!

Viewing 1 replies (of 1 total)
  • Avatar of shanebpdev
    shanebp
    Participant

    @shanebp

    Re your rebuild of the ajax_querystring…
    It’s even better to remove yourself before that query is constructed.
    Take a look at this hook: bp_pre_user_query_construct

    Re remove group admin from loop…
    That’s a tough one.
    I recall not being able to do that or that the consequences were too ugly or some fail.
    This is kinda of clunky – but sometimes I create a dummy user for use in those situations.
    And make it clear in that profile that you aren’t a member of _____.
    It gives you a ‘mask’ to wear and makes it easier to compartmentalize friend requests, etc.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.