Custom Div with links on Admin Bar

I think you need to use “global $current_user;” in your function to get the details of $current_user and global $wp_admin_bar; for admin bar.

This is how I managed to get the role of the current user and change the URL from admin depending on role (It doesn’t solve your issue, but maybe you find it helpful)

function mytheme_admin_bar_render() {
global $wp_admin_bar;
global $current_user;


    if (!is_admin()) {
        $adminUrl = admin_url();
        $wp_admin_bar->add_menu( array(
            'parent' => false,
            'id' => 'am-profile',
            'title' => __('Admin's Title'),
            'href' => $adminUrl
        ));
    }else{
        $profilehref = site_url();
        $wp_admin_bar->add_menu( array(
            'parent' => false,
            'id' => 'some_id',
            'title' => __($sitereturnto),
            'href' => $profilehref 
        ));
    }
}

add_action( 'admin_bar_menu', 'mytheme_admin_bar_render', 20 );