How to get the role label from wp_user_roles
-
I am building a site that has multiple groups for users. We are using the plugin : user hierarchy to do this. It doesn’t really make groups for users but lets you control the hierarchy of user roles, so it’s kinda a work around but it works. What we are doing is using the “Role Label” to hold the full company name, and the “Role Name” for an abbreviated name that has a delimeter in it to separate managers from members. Example for a manager role label: ABCD Company, and the example for that role name: abcd-manager. And then I use a custom function to explode the role name to get the manager or member.
I just wanted to give a quick background of our setup to give a better understanding of what we are doing.So what I want to do is somehow access the “Role Label” from the db for the current user.
What I have figured out so far is to get the current users role name, and get it from the db where role name = current users role name.
My problem is I do not know exactly what to query to compare and get the values.
Here is what I have come up with (with help of other forum users posts as reference)
function dirty_get_role(){ global $wpdb, $current_user; $user_role = ""; if (is_user_logged_in()){ $user_roles = $current_user->roles; $user_role = array_shift($user_roles); } $role = explode('"',$wpdb->get_var("SELECT option_value FROM wp_options WHERE option_name = 'wp_user_roles' and role_name = '$user_role'")); return $role[1]; }
I can get the current users role name with no problem, its just getting the role label that I need help with.
Thanks
- The topic ‘How to get the role label from wp_user_roles’ is closed to new replies.