Get Organic Group roles of the current user It seems a few different versions of this question exist so apologies if it seems I am repeating but I dont think I am. I am trying to use the api to get the og role(s) of the current user, not just which groups the user belongs to. I hope to able to create an array that looks like this for the current user:

Array
(
['Group 1'] =&gt; Array
    (
        [0] =&gt; 'OG Admin'
        [1] =&gt; 'OG Member'
    )

['Group 2'] =&gt; Array
    (
        [0] =&gt; 'OG Moderator'
        [1] =&gt; 'OG Member'
    )

['Group 3'] =&gt; Array
    (
        [0] =&gt; 'OG Member'
    )

)
Here is the data structure I ended up with:

Array
(
// Index 0 will be site-wide rid and roles
[gid] =&gt; Array
    (
        [rid] =&gt; 'OG Role Label'
    )
)


Here is the code I hacked together to get it to work. I placed this code into a custom module but I can't seem to get the function to get called from the desired location. I have a file ../sites/all/themes/THEME/templates/includes/toolbar.php. The function call is inside this file but for some reason is never executed. Any ideas on how to make the function call correctly??

function _MYMODULE_get_user_roles($scope=ALL) {
    global $user;
    $user_roles[]=$user-&gt;roles;

    if ($scope==ALL || $scope == SITE_ONLY)
    {
        $user_roles['SITE'] = $user-&gt;roles;
        switch (true) {
            case in_array ( 'System Administrator', array_values ( $user-&gt;roles ) ) :
                //drupal_set_message ( '&lt;pre&gt;Load System Administrator Toolbar&lt;/pre&gt;' );
                break;
            case in_array ( 'Site Account Admin', array_values ( $user-&gt;roles ) ) :
                //drupal_set_message ( '&lt;pre&gt;Load Site Account Administrator Toolbar&lt;/pre&gt;' );
                break;
            case in_array ( 'Site Content Admin', array_values ( $user-&gt;roles ) ) :
                //drupal_set_message ( '&lt;pre&gt;Load Site Content Administrator Toolbar&lt;/pre&gt;' );
                break;
            case in_array ( 'authenticated user', array_values ( $user-&gt;roles ) ) :
                //drupal_set_message ( '&lt;pre&gt;Load Member Toolbar&lt;/pre&gt;' );
                break;
            default :
                //drupal_set_message ( '&lt;pre&gt;No Member roles found: Do Not load a toolbar&lt;/pre&gt;' );
                break;
        }
    }
    if ($scope==ALL || $scope == OG_ONLY)
    {
        $groups=og_get_groups_by_user();
        foreach ($groups['node'] as $group )
        {
            $roles = MYLEGACYMODULE_get_user_roles($group);
            $group_string = node_load($group)-&gt;title;
            $group_string .= ' (gid: ' . $group . ')';
            $group_string .= ' as ';
            foreach ($roles as $role )
            {
                switch ($role)
                {
                    case 7:
                        $role_string = '"Group Content Manager"';
                        $role_string .= ' (rid: ' . $role . ')';
                        $user_roles[$group]=array(
                                $role=&gt;'Group Content Manager'
                        );
                        break;
                    case 8:
                        $role_string = '"Group Account Manager"';
                        $role_string .= ' (rid: ' . $role . ')';
                        $user_roles[$group]=array(
                                $role=&gt;'Group Account Manager'
                        );
                        break;
                    default:
                        if (empty($role))
                        {
                            /*  Note: Note that in PHP the switch statement is considered a looping structure for the purposes of continue.
                             *  continue accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of.
                            *   The default value is 1, thus skipping to the end of the current loop.
                            *   --http://www.php.net/manual/en/control-structures.continue.php
                            */
                            continue 2;
                        }
                        $role_string = '"Unknown Group Role"';
                        $role_string .= ' (rid: ' . $role . ')';
                        $user_roles[$group]=array($role=&gt;'Unknown Group Role');
                        break;
                }

            }
        }

    }
    return $user_roles;
}