I run WordPress 5.1.1 with BuddyPress plugin.

Basically what I want to do is, redirect the user from custom login link to their profile page in BuddyPress.

I have read and check almost all codes provided on Stackoverflow for my similar query but non one has worked on my site.

The only code worked it's below but it has one problem for my site settings and setup.

function bp_help_redirect_to_profile(){
  global $bp;
  if( is_user_logged_in() && is_front_page() ) {
   bp_core_redirect( get_option('home') . '/members/' . 
   bp_core_get_username( bp_loggedin_user_id() ) . '/profile' );
  }
}
add_action( 'get_header', 'bp_help_redirect_to_profile',1);

The problem is, when I want to redirect on homepage of the website it's keep redirecting me on the BuddyPress profile. Categories and post sections are loading correctly.

So, what i need is, when the login flow redirect user on their BuddyPress profile page, after when user hit the homepage of the site to load the homepage of the site and not, the BuddyPress.

I hope someone can help and tweak the function in this way.

Thank you

2 Answers

0
Nilambar On

You can use wp_login action for that. Please check following example. bp_core_get_user_domain() will fetch the profile URL and after successful login user will be redirected to that profile URL.

function wpso_take_to_profile( $user_login, $user ) {
    if ( function_exists( 'bp_core_get_user_domain' ) ) {
        $url = bp_core_get_user_domain( $user->ID );
        wp_redirect( $url );
        die();
    }
}
add_action('wp_login', 'wpso_take_to_profile', 10, 2);
0
Nikunj Kathrotiya On
add_filter( 'bp_login_redirect', 'bpdev_redirect_to_profile', 11, 3 );

function bpdev_redirect_to_profile( $redirect_to_calculated, $redirect_url_specified, $user )
{

  if( empty( $redirect_to_calculated ) )
    $redirect_to_calculated = admin_url();

    //if the user is not site admin,redirect to his/her profile

if( isset( $user->ID) && ! is_super_admin( $user->ID ) )
    return bp_core_get_user_domain( $user->ID );
else
    return $redirect_to_calculated; /*if site admin or not logged in,do not do 
    anything much*/

}

Tested Code put in your active theme function file