Another simpler approach would be to created a bp-custom.php and place it in the plugins directory and add the following code
`<?php
function bp_guest_redirect() {
global $bp;
if ( bp_is_activity_component() || bp_is_groups_component() /*|| bbp_is_single_forum()*/ || bp_is_forums_component() || bp_is_blogs_component() || bp_is_page( BP_MEMBERS_SLUG ) ) {
// enter the slug or component conditional here
if(!is_user_logged_in()) { // not logged in user
wp_redirect( get_option(‘siteurl’) . ‘/register’ );
} // user will be redirect to any link to want
}
}
add_filter(‘get_header’,’bp_guest_redirect’,1);
?>`
This code will work to hide buddypress pages and group forums as is, if your using sitewide forums in line 4 remove the comments around:
|| bbp_is_single_forum()
Save and refresh. Works in current versions.
@giannisff I would definitely consider that solution.
@drill your solutions works, only for the respective pages but what about the pages that are created on the fly .. for example when I tried to browse site_url/membsers/x/profile I get to see it.
Any idea about this issue?
Anyways thanks both of you for stopping by and replying 🙂
I am interested in finding out the answer for this as well.
Hi, @drill_sgtlewis – that looks great. Where do I put that bp-custom.php file? In the buddypress plugin root?
@echofoxtrot
This plugin works and is more complete as far as building a private community.
https://github.com/bphelp/private_community_for_bp
Thanks! I just need to protect Groups and the Forum, not the whole site. I’ll give this code a shot.
Hello,
@drill_sgtlewis, can you tell me how can I adapt this code to avoid non-logged user to get to a specific page?
I was trying something like this:
function restrict_access(){
global $bp, $bp_unfiltered_uri;
$component = $bp->current_component;
if (!is_user_logged_in() && ($component == “events”)
) {
bp_core_redirect( “/home/” );
}
}
add_action( ‘wp’, ‘restrict_access’, 3 );
But it didn’t worked.
Thanks
Has someone found a solution to this issue? I also want to deny access to non-logged in users to group and members pages.
I tried private_community_for_bp but I did not understand how to customize code since I want to leave generic users to vist 3 pages that do not belong to bp installation since, like site homepage
Hi! I tried with the plugin indicated by @chouf1 https://wordpress.org/extend/plugins/network-privacy/ but it doesn’t work properly (it let you see groups and members!) and the link provided by @bphelp doesn’t work 🙁
Is there any other plugin option?
@asdevargas
I removed the github version in favor of using the version in the official WP repository which has been improved. You can get it here:
https://wordpress.org/plugins/private-community-for-bp-lite/
And freshly updated 🙂 Thank you @bphelp!