So here’s the deal..I have WordPress + bbPress integrated with a membership software (aMember).
On my bbPress forums, under people’s username i want to show the WordPress roles (Not bbpress roles) of every member and also an image depending of the role of every member.
For example,
If user role is subscriber -> Show role under username in bbpress -> Also show an image below.
The reason why i want to show WordPress roles (instead of bbpress roles) is that my membership software (amember) allows me to set different wordpress roles depending on the User’s subscription. I have 2 different membership plans on my site (one free and on paid) and i want to show different images in my bbpress forums based on their plan.
I went through the bbPress templates and i found this code (in loop-single-reply.php):
<?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?> // this shows the bbpress role
<?php echo 'Points: '.cp_getPoints(bbp_get_reply_author_id()); ?> // this shows the member points below the username - I use a points plugin)
Now how can i replace this code with a code that shows the WordPress roles (not bbpress) for every user and also show an image under it depending on what roles it is. For example:
If Is Role “Subscriber” -> Show Role + Image Under It
If Is Role “Contributor” -> Show Role + Image Under It
If Is Role “Administrator” -> Show Role + Image Under It
I’m not a programmer so i have no idea how to accomplish this. Please help. I found some related code that i think i could use to make this work:
<?php if ( current_user_can('contributor') ) : ?>
Content
<?php endif; ?>
Now my failed attempt looks like this:
<?php
$user_roles = $current_user->roles;
$current_user = $bbp_get_reply_author_id; // i think this is wrong :P
$user_role = array_shift($user_roles);
?>
<?php if ($user_role == 'administrator') : ?>
Show Role
Show Image
<?php elseif ($user_role == 'editor') : ?>
Show Role
Show Editor Image
<?php elseif ($user_role == 'author') : ?>
Show Role
Show Author Image
<?php elseif ($user_role == 'contributor') : ?>
Show Role
Show Contributor Image
<?php elseif ($user_role == 'subscriber') : ?>
Show Role
Show Subscriber Image
<?php else : ?>
Show Role
<?php endif ?>
I have no idea what i’m doing…The code above is something i found on Google.
Can anyone help?
I would really appreciate it.
It would look something like this to test if a user is a subscriber.
in your case if you want to do multiple user checks i would use a switch statement like so
you can continue the switch statement with more user roles.
EDITED
EDITED BASED ON USER REQUESTS
Ok this should do it, replace all the code that you have getting user name,avatar, points and image using the following code.
In your functions place this
remove the
//
in front ofecho
abovePlace the following inside your template
to add more roles and images, just add a new array after subscriber
I FOUND A MUCH SIMPLER SOLUTION:
The starter and premium roles are custom roles which i created using the User Role Editor plugin.
Everything seems to be working fine now.
I know this is a bit late but here is my solution which i believe is the shortest and most efficient: