BuddyDev

Search

[Resolved] Remove All Members Option

  • Participant
    Level: Enlightened
    Posts: 90
    Sujee Kulendran on #15426

    Hi Brajesh!

    I hope you are well. I had placed the code you provided to bp-custom and it works great when users are logged in. When users are logged out, however, I can see all members. I wouldn’t want visitors to enter the URL with slug /members/ and see active members.

    Any way we can get rid of that? Please see the code you had kindly shared below.

    /**
    * Filter members loop args.
    *
    * @param array $args
    *
    * @return array
    */
    function buddydev_filter_all_members_list_for_members_dir( $args = array() ) {

    if ( ! bp_is_members_directory() ) {
    return $args;
    }

    if ( ! is_user_logged_in() ) {
    $args[‘include’] = array( 0, 0 );// invalid
    } else {
    $args[‘user_id’] = get_current_user_id();
    }

    return $args;

    }

    add_filter( ‘bp_after_has_members_parse_args’, ‘buddydev_filter_all_members_list_for_members_dir’ );

    Thanks again!
    Sujee

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2461
    Ravi on #15429

    Hello Sujee,

    Please try following code in your “bp-custom.php” file. This code will make none logged in users to redirect back to the URL they come from. The code will redirect only when they will try to access members directory. Please check and let me know if it meets your requirement or not.

    
    /**
     * Redirect not logged in user
     */
    function buddydev_redirect_not_logged_user() {
            // Redirect visitors when they try to access members directory.
    	if ( ! is_user_logged_in() && bp_is_members_directory() ) {
    		bp_core_redirect( bp_get_referer_path() );
    	}
    }
    
    add_action( 'bp_template_redirect', 'buddydev_redirect_not_logged_user' );
    
    

    Thank You
    Ravi

  • Keymaster
    (BuddyDev Team)
    Posts: 21852
    Brajesh Singh on #15433

    Hi Sujee,
    That’s strange. The above code should work for logged out too. It should hide all members form directory.

    Are you modifying member loop in any other way except the above code.


    @ravisharma
    ,
    Thank you for the code but I will rather like it to work without it too.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 90
    Sujee Kulendran on #15448

    Hi Brajesh,

    I had cleared cache and it works beautifully now! Thank you. Ravi – thank you for your suggestion as well.

    Thanks,
    Sujee

  • Keymaster
    (BuddyDev Team)
    Posts: 21852
    Brajesh Singh on #15450

    Thank you Sujee.

  • Participant
    Level: Initiated
    Posts: 1
    Wil on #15799

    Hi Ravi,

    I too was looking for this solution and was very glad I came across it.

    I don’t, however, have a “bp-custom.php” file (that I could find) so instead put the code in the “functions.php” file within the custom functions section of the Boss Child Theme. It appears to work perfectly but I wanted to check that it was OK to have the code in this location and that it wouldn’t cause any issues down the line.

    Many thanks

    Wil

  • Keymaster
    (BuddyDev Team)
    Posts: 21852
    Brajesh Singh on #15800

    Hi Wil,
    I will confirm here on behalf of Ravi.
    It is alright to put it in the functions.php. It won’t cause any issue to you.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved