create a file named bp-custom.php that you will then place in yoursite/wp-content/plugins folder after you paste the following code in it:
`
`
Just change the /register in the line :
wp_redirect( get_option(‘siteurl’) . ‘/register’ );
to the page you want the logged out user to be directed too!
I found this somewhere on the net so props to whomever coded it!
the above reply stripped out the code so hopefully this will print out!
`
`
It stripped the code again. Just place this between opening and closing php tags in the bp-custom.php file:
`
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);
`
@bphelp I tried this and when I refreshed my site, all of your code appears below the admin bar on my site — above my header.
I created a new page and named it “new page here.”
Here’s your code with my info:
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’) . ‘/new-page-here’ ); } // user will be redirect to any link to want } } add_filter(‘get_header’,’bp_guest_redirect’,1);
Am I to insert my URL as well? I tried with and without changing it and that didn’t work either.
Kevin
@bphelp I missed my greater than sign in starting out the page. Now your code doesn’t show, but when I log out, i get an error across the top of the screen instead:
Warning: Cannot modify header information – headers already sent by (output started at /home/*****/public_html/inlandcoder/wp-content/themes/frisco-for-buddypress/members/index.php:12) in /home/*****/public_html/inlandcoder/wp-includes/pluggable.php on line 876
did you add the code to the bp-custom.php you create in yoursite/wp-content/plugins? did you remember to add the code between opening and closing php tags and save the file? I have it working flawless on wp 3.5.1 and bp 1.7 beta 1. for example this line:
wp_redirect( get_option(‘siteurl’) . ‘/register’ );
redirects to register page
you could for example change it to something like this:
wp_redirect( get_option(‘siteurl’) . ‘/sample-page’ );
that would redirect to the sample page.
That sounds more like your theme is shooting off errors. Try activating the bp-default theme and see what happens. also make sure there is no extra lines before or after the opening and closing php tags in the bp-custom.php
@bphelp I do believe I have it now. Yes, my butchered theme that I’m learning on was sending off errors. I enabled the BP-Default Theme and we’re good. I have the BP navigation tabs going to the Sample Page.
I knew you had it right, but I didn’t understand and I didn’t know my theme was causing errors. I use this site for practicing, then I implement the changes that work back to my new site: http://www.gumpolen.com
Thanks,
Kevin