Skip to:
Content
Pages
Categories
Search
Top
Bottom

Exclude self from members directory


  • Henry
    Member

    @henrywright-1

    Does the currently logged in user appear by default in the members directory? If so, is there a reason for this? I was thinking of excluding the currently logged in user.

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

  • bp-help
    Participant

    @bphelp

    @henrywright-1
    Yes by default. Not really sure why but you could write a function to exclude the current logged in user.


    Henry
    Member

    @henrywright-1

    Thanks for confirming. I’ll just filter out the logged in user. Probably also do it for the follow pages (I’m using the BP follow plugin too)


    aces
    Participant

    @aces

    @henrywright-1

    https://wordpress.org/plugins/bp-ninja/ ?

    I haven’t tried it myself.

    I’ve seen code snippets around for a stealth mode but don’t have anything to hand…. https://www.google.com/search?q=buddypress+stealth+mode


    Henry
    Member

    @henrywright-1

    Thanks @ aces seems like an interesting plugin. I’ll check it out


    Henry
    Member

    @henrywright-1

    I ended up using if ( bp_get_member_user_id() == bp_loggedin_user_id() ) continue; right after bp_the_member() in members-loop.php. I borrowed the idea from an old post by @r-a-y

    The only drawback with this approach is the numbers in the pagination will be off by 1.

    So even though the pagination might read “Showing 1 – 5 of 5 members”, you will see just 4 members on the page (the 5th member is the current user who we’ve just excluded).


    rogeriorvaz
    Participant

    @rogeriorvaz

    Solution:
    Add the code in the functions’ theme file.

    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=bp_loggedin_user_id();//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 searching  or we are listing friends?, do not exclude in this case
     if(!empty($args['user_id'])||!empty($args['search_terms']))
     return $qs;
     
     if(!empty($args['exclude']))
     $args['exclude']=$args['exclude'].','.$excluded_user;
     else
     $args['exclude']=$excluded_user;
     $qs=build_query($args);
     return $qs;
     
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Exclude self from members directory’ is closed to new replies.
Skip to toolbar