Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Access $Author's role in plugin using BeforeCommentMeta?
I'm trying to write a simple plugin that highlights the comments of different authors in different colors, by role. It looks like I could hook into the BeforeCommentMeta event (in applications/vanilla/views/discussion/helper_functions.php) to add a wrapper div with class="[Role]" and then use a stylesheet to customize appearance for each role.
However, I'm not sure how to access the role data for the author of each comment. Any advice on how to do this? I'm aware that $Sender, $ClassName, $EventName, and $EventArguments are passed into the callback function, but to my knowledge none of them have the $Author information. Am I wrong in this? Thanks in advance!
//Edit:
I realized that $Sender->EventArguments['Author']->UserID has the user's ID. How do I get the role from this?
However, I'm not sure how to access the role data for the author of each comment. Any advice on how to do this? I'm aware that $Sender, $ClassName, $EventName, and $EventArguments are passed into the callback function, but to my knowledge none of them have the $Author information. Am I wrong in this? Thanks in advance!
//Edit:
I realized that $Sender->EventArguments['Author']->UserID has the user's ID. How do I get the role from this?
Tagged:
1
Comments
The easiest way is to add the role as an eventarguments to have it available in your plugin. So you'll need to change the garden/vanilla source.
$Database = Gdn::Database();
$Database->SQL()->Select('RoleID')->From('GDN_UserRole')->Where('UserID =',$UserID);
$DataSet = $Database->Get();
Get() doesn't seem to be defined. I feel like I'm not using the database class properly. The documentation doesn't help much either. Any suggestions here?
There was an error rendering this rich post.
So no issue of reapplying your patch on every single release.
I didn't had access to a garden db, hence I couldn't check if it could be availabled.
But, in my opinion, if the RoleID is available before the call, it might be better to add the info, instead of doing another database request afterward. (I haven't checked the code, so no idea about that).