Fork me on GitHub
Current release is 2.1.6 (21 Nov 2014).

Users who have not yet upgraded to 2.1 should get security release 2.0.18.14 (1 Nov 2014). We will stop providing these security releases to 2.0 at the end of this year.

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>';
}
}
}
}
Tagged:

Answers

Sign In or Register to comment.