Fork me on GitHub
Current releases are 2.1.4 (30 Oct 2014) and (5 Aug 2014)

Ready for 2.1? Find out if your plugins are compatible. 2.0 will no longer be updated after Dec 2014.

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.