BuddyDev

Search

restricting member directory access

  • Participant
    Level: Initiated
    Posts: 11
    David on #15211

    how can i restrict access to the member directories?

    Currently, the directories are not pages so I am having trouble restricting the URL link to the directories that I created.

    I’d like to restrict access to the member type directory URLs to only logged in users or a certain user level.

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #15216

    Hi David,
    Welcome to BuddyDev.

    You may use the following code to redirect non logged users

    
    add_action( 'bp_template_redirect', function () {
    
    	if ( ! is_user_logged_in() && bp_is_members_directory() ) {
    		bp_core_redirect( site_url( '/' ) );
    	}
    } );
    
    

    If you are using the Member Types feature of BuddyPress and want to do it for the directory of a specific member type, you may use ‘bp_get_current_member_type()’ to check for that.

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 11
    David on #15230

    Appreciate the help. Can you tell me where this code goes?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #15237

    Hello David,

    You can use this code in your “bp-custom.php” file. To get more info please refer the following URL:
    https://codex.buddypress.org/themes/bp-custom-php/

    Thank You
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved