To check if the user is logged in, is_user_logged_in() is used:
function is_user_logged_in() {
$user = wp_get_current_user();
return $user->exists();
}
True if user is logged in, false if not logged in.
To obtain the default data (such as User ID, User Login, etc.)of the user try this code:
global $bp;
$the_user_id = $bp->loggedin_user->userdata->ID;
$the_user_login = $bp->loggedin_user->userdata->user_login;
To get data for the current logged in user, this this:
`$the_first_name = bp_get_profile_field_data(‘field=First Name&user_id=’.bp_loggedin_user_id());
Hope you find these code lines useful.
Just to note, is_user_logged_in() ships as part of WordPress itself, there’s generally no need to redefine it from your own code (unless you are perhaps reimplementing the login system).