Fork me on GitHub
Please upgrade to 2.1.x here. The 2.0 branch is no longer being updated.
Critical: Update to 2.1.8, released 15 Jan.

Get user's role name from user ID

edited July 2011 in Vanilla 2.0 Help
I'm trying to write a simple plugin that will add a div before the user's name in a post which will be used to show an icon of my choosing.

Since the icon will come after the user's icon but before the name I need to override the UserAnchor function located in, /library/core/functions.render.php

The part I'm not sure how to do is the if statement. What is the best way to get the Role Name based on the comment that is being rendered?

class AdminIcon extends Gdn_Plugin {
* Takes a user object, and writes out an achor of the user's name to the user's profile.
if (!function_exists('UserAnchor')) {
function UserAnchor($User, $CssClass = '') {
if ($CssClass != '')
$CssClass = ' class="'.$CssClass.'"';

//If admin append div
if((RoleName->RoleID->($User->UserID)) == 'Administrator') {
return '<div class="adminicon"></div><a href="'.Url('/profile/'.$User->UserID.'/'.urlencode($User->Name)).'"'.$CssClass.'>'.$User->Name.'</a>';
else {
return '<a href="'.Url('/profile/'.$User->UserID.'/'.urlencode($User->Name)).'"'.$CssClass.'>'.$User->Name.'</a>';


Sign In or Register to comment.