Skip to:
Content
Pages
Categories
Search
Top
Bottom

Roles under username (.bbp-author-role)


  • tommysvr
    Participant

    @tommysvr

    Hi,

    I’m not sure if this would be considered a request or perhaps just a modification I could make, so forgive me if this is the wrong section.

    I would like to be able to display an image based on a users role. That is, if they’re a subscriber, the would have a the relevant subscriber image. The same for mods, admin etc. I feel the easiest way to do this would be with CSS, but unfortunately the role underneath a username on a post only has the class .bbp-author-role. Would it be possible to add another class such as .bbp-author-role-subscriber to allow further customisation?

    I’m a bit of a php novice, so I’m completely sure where to start with it. I also feel this could be beneficial to others.

    Thanks in advance.

    • This topic was modified 1 year, 11 months ago by  tommysvr.
    • This topic was modified 1 year, 11 months ago by  tommysvr.
    • This topic was modified 1 year, 11 months ago by  tommysvr.
Viewing 4 replies - 1 through 4 (of 4 total)

  • synergywp1
    Member

    @synergywp1

    Hi, I can help you with this. I am doing the same and needed to figure it out as well. Hopefully they’ll add this in updated versions… Seems like a basic feature that can add awesome visual option via CSS. Anyways, I will assume you know a bit of CSS. For the PHP, I recommend that you create a folder “bbpress” inside your WP theme folder, i.e. wp-content/themes/yourtheme/bbpress Then go to /plugins/bbpress/bbp-theme-compat/bbpress and copy/paste the file “loop-single-reply.php” to your newly created bbpress folder from above. What this does is now make bbPress use that file instead of the default one. Now you can make changes to it and not worry about updates to bbPress overwriting your changes. On line ~ 30, you’ll see an opening DIV with id=”post-*some php”…

    On the next line, enter this:

    $reply_id = bbp_get_reply_id( $reply_id );
    $abc_role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) );

    Then the next line that’s already there should be:

    div class="bbp-reply-author"

    Turn it into this:

    div class="bbp-reply-author ?php echo $abc_role ?>"

    Add the bracket < before the first ?php in that above statment… I dont know why its not letting me show it.

    And there you have it. The CSS class name will now contain the verbatim user role… This means that "Key Master" will actually be in the class.. No problem, just use:

    div.Key { color: #abc }

    to target the admin. Sure, “Master” will be in there but, but it’ll be taken as 2 different classes, “Key” and “Master”. With additional pvp, you could turn it into “keymaster” but its not necessary for 99.9% of applications and would just run more PHP. I’m literally doing this right now, so i havent checked other template files, but it’s the same thing.. So for instance, if you want to change the css in the index for only admins, to have lets say a special color link, find the template file that displays the index, add that same snippet in, and it will work the same. have fun. :)


    tommysvr
    Participant

    @tommysvr

    Genius! Thank you very much!


    leanderbraunschweig
    Participant

    @leanderbraunschweig

    Perfect solution – thanks a bunch!


    AllenPayne
    Participant

    @allenpayne

    @synergywp1 I can’t get this to work…Can you post the whole code on PasteBin.com and share it? I would really appreciate it.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.