@sharmavishal – that didn’t work for me. No plugins have worked.
@Henry- which code specifically? All of my redirect codes?
@navyspitfire just tested right now and am able to redirect logins to groups section and logout to main site
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return home_url();
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', create_function( '$url,$query,$user', 'return home_url();' ), 10, 3 );
This should work when in your functions.php, but if as you said something overrides your functions file there is another problem afoot.
And when you say “all your redirect codes” you might have referred the problem, you can have only 1 redirect code block functioning without conflicts, multiple redirect functions should be in one code block/function I think.
@peter-hamilton how would I use your code snippet to redirect to the user profile. Separately looking for some thing that works all the code I have tried does not
hi @earl_d,
add this snippet to bp-custom.php and give it a try.
function bpex_redirect_to_profile( $redirect_to_calculated, $redirect_url_specified, $user ){
if( empty( $redirect_to_calculated ) )
$redirect_to_calculated = admin_url();
// redirect logged in to his/her profile - except site admins
if( isset( $user->ID) && ! is_super_admin( $user->ID ) )
return bp_core_get_user_domain( $user->ID );
else
return $redirect_to_calculated; /* nada !*/
}
add_filter( 'bp_login_redirect', 'bpex_redirect_to_profile', 11, 3 );
For the redirect URL error you mentionned here, use:
return bp_core_get_user_domain( $user->ID ) .'/mypics';
mypics is a slug, not a constant ( $user->ID ) .mypics
… or just add a login link to your site anywhere in your theme files. e.g <a href="<?php echo wp_login_url(bp_loggedin_user_domain()); ?>"><?php _e('Login', 'buddypress'); ?></a>
.
This will redirect a user to their profile page after logging in.
@danbp thanks for the assistance. It seems to be working. I hope I did not hijack the OP request. That was my reason for starting a different topic