I am now able to block buddypress pages and redirect users to a page I choose

drdave Inactive
Expert
Just Getting Started
628
#115

After a long saga I think I finally solve this mystery. I only took some guesses and got it working but if someone has a more elegant way of doing this then great! It is working as expected but I am not a coder.

Found my solution here
http://premium.wpmudev.org/forums/topic/prive-community-with-buddypress#post-28572

I modified Richie_KS codes since I want to disallow logged out users from all my buddypress pages and redirect them to my login page instead.

In functions.php I add this
<?php
function bp_guest_redirect() {
global $bp;
if ( bp_is_activity_component() || bp_is_groups_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') . '/signup' );
} // user will be redirect to any link to want
}
}
add_filter('get_header','bp_guest_redirect',1);
?>

This code also killed another bird.
http://premium.wpmudev.org/forums/topic/continuing-this-remove-search-box-for-non-logged-in-users

I use BuddyPress Daily Child 3.9.6 theme and it works perfectly when a logged out user attempt any buddypress page searches using the sidebar search option. They are only redirected to my login page.

Any corrections to my code if necessary will be appreciated. I know if it ain't broke I shouldn't fix it but I hate to end up with problems down the road due to my poor coding skills.

(1)