Redirect buddypress users to their profile on login

Redirect users to their own profile after they login on your website. Admins are logged in as usual to the WordPress dashboard.

As always with Buddypress functions, insert it into your bp-custom.php.

bp-custom.php

add_filter('bp_login_redirect', 'redirect_to_profile', 11, 3);

function 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, doesn't do anything
	}