Modify comments depending on different user roles

Hey, is it possible to change the background color of a single comment depending on the user role of the author?

I think of a if clause, which checks the author of each comment and allocate the comment field a different css class. So user can identify comments from specific user faster and easier.

  • Nobody? A general comment wheather this is MAYBE with X effort possible or forget it and wait for the new milestone with comment as an entity :D would be helpfull too!!!

  • Yes, it can be done with a plugin. As you said, a css class could be added to the div for the comment and then themers could use whatever colors they want. This sounds really easy to add.

  • Thanks! I'm new to elgg so where should i start? I know that the the replies.php file in groups/views/default/discussion shows the discussion. In line 17 the comments are listed with the elgg_list_annotations, so i guess i should edit this method. But this would bring some side effects or?

  • The best place to start is by reading this page:

    Followed by learning about the elgg views system:


    What you want to do is find the view that outputs the comment, and extend/overwrite/hook it in a new plugin.  Your new view will be the same as the old view, but it will check for whatever user status you require and assign the appropriate classes.

  • Thanks! After some days of reading and coding, i did it. With the help of CSS3 i made a nice color gradient *yeah* ^^.

    @Matt First i thought, why he can't just write a soluation or a helpful code snippet. But now i think, thanks dude! This was the kind of help i needed to better understand the elgg platform and to get the skills to develop my own plugins (like this one)!!

  • You're welcome!  And it will only get easier.

  • @mhauptma, would you please upload your plugin to the community?

    Would like to test it, sounds like a good idea.


  • @mhauptma, what are you using to differentiate different roles?

    I folowed instructions from Roles plugin but not even showing available roles

    Here is my code:

    $user = elgg_get_logged_in_user_entity();
    $user_guid = $user->getGUID();

    //$myrole = roles_get_role($user = null);
    //$myrole = roles_get_role($user);

    $myrole = roles_get_role();

    echo 'Role:' . $myrole . '';

    I need to do what you said you got it to work, show something if user has certain role. Can you share some info on how you did it ?