Try This Code :
add_action( 'wp', 'custom_lockdown_redirect', 3 );
function custom_lockdown_redirect(){
global $wp;
if (!is_user_logged_in()){
if ( bp_is_activation_page()
|| bp_is_register_page()
|| ( in_array( $GLOBALS['pagenow'], array( '/login' )))
)
return;
bp_core_redirect(get_option('http://yoursite.com') . "/login");
exit;
}
}
Make sure the you change /login
with your login link.
Add it to your theme’s function.php file
Hello @chatty24 . . thanks for stopping by and luking into the problem. As u suggested, i have included your code in my bp-custom.php. it does prevent it from going to any other page but it ends up going on to a page not found error and i found that its not pointing to the exact url even after changing to my custom link.
Try to add it to your theme’s function.php file instead of bp-custom.php
I tried adding it even into functions.php but it still has the same behavior. It is unable to find the Server path. Instead it directly points to my page. For example my path is localhost/expo_social/welcome but it redirects to localhost/welcome thereby showing the page not found error.
and one more thing. . i managed to sort the above error by just putting two dots before my page url. but the wiered thing is that when i try to login, it again takes me to my register page 😀
@chatty24 is there anything else i can try in this?
This is what I use. It blocks access to all the BP and bbPress components, but allows visitors to see the blog. I’m sure you could customize it to kill access to that too.
When you attempt to access a page you shouldn’t be able to see, you are redirected back to the home page
/**
* Block public access to site with some exceptions.
*/
function hwdsb_block_access() {
if ( is_user_logged_in() ) {
return;
}
$redirect = is_buddypress();
$site_path = bp_core_get_site_path();
// subdirectory install
if ( is_multisite() && ! is_subdomain_install() ) {
global $current_blog;
$site_path = $current_blog->path;
}
// strip site path from URI
$path = substr( esc_url( $_SERVER['REQUEST_URI'] ), strlen( $site_path ) );
if ( ! $redirect && function_exists( 'is_bbpress' ) ) {
$redirect = is_bbpress();
}
// redirect if we match a condition and we're not on the homepage
if ( (bool) $redirect === true && $path != '' ) {
bp_core_redirect( bp_core_get_root_domain() );
exit();
}
}
add_action( 'template_redirect', 'hwdsb_block_access', 0 );
@mrjarbenne this is what exactly i wanted. . thnx pal. .
Great! Found where I was looking for…
BUT: we use Buddypress Docs, and the page /docs is still accessible…
Any suggestions?
THX!!!
@mrjarbenne
I am using the code snipet you advise to block access to all the BP and bbPress components, but allows visitors to see the blog. It seems that this code re-directs back to homepage. I am interested in having visitors re-directed to another page, in my situation, to my sign up page. Can you advise where in the code I can make such adjustment as well as advise the code to use, thanks.
@gbsu
change this line bp_core_redirect( bp_core_get_root_domain() );
to where you want your page to redirect
for eg.
bp_core_redirect( bp_core_get_root_domain()."/sign-up");
@saish_neugi the Plugin Private Buddypress works well also. It isn’t being updated anymore, but I’ve tested it and still works without errors.
@romansb that can also be a gud way. . only to take care that it doesn’t temper some of your plugins functioning as its a very old plugin.
A hassle-free solution is to use a theme with a Restrict Page / Require A Login page template.
Isn’t this something that “press permit core” plugin does out of the box? Maybe I am missing what is needed here.
chatty’s code worked for us – thanks