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

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.

    Mason
    • 2,100 pts
      9,660 pts
      LEVEL 27

    Nice work drdave!

    Look at you go with your own custom theme function :) I'll ask a theme designer or two to stop by and doublecheck, but it looks good and as you say - it does exactly what you're wanting in this scenario.

    Nicely done and thanks for sharing! :D

    drdave
    • 63 pts
      618 pts
      LEVEL 6

    Seems so much cleaner than using a plugin imo unless, or until membership plugin can provide a fix. I was looking at Buddypress Private Community for a while but thought it might clash with membership. I'll definitely keep an eye out.

    Thanks masonjames

    yagg
    • 53 pts
      4 pts
      LEVEL 0

    Just found this topic thanks to Google and it kinda saved my life. Just one thing though: for me it doesn't seem to work with member pages... Any idea why?
    thanks again.

    Jack Kitterhing
    • 13,175 pts
      20,391 pts
      LEVEL 30

    Hi there, @frankwarwick,

    Awesome, glad to hear that worked for you! :)

    Kind Regards
    Jack.

    designlobby
    • 50 pts
      25 pts
      LEVEL 2

    I have tried adding this code to my theme functions.php file but It appears to be doing absolutely nothing?! All i changed was removing the <?php ?> start and end tags, and changed the url to redirect to. What am I doing wrong?

JOIN 388130 HAPPY MEMBERS

We pride ourselves on our level of customer support and responsiveness to member requests. Your WordPress experience will never be the same


Become a member

  • PayPal Partner