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.
This
<?php if ( current_user_can('contributor') ) : ?>
only checks the users capabilities and is used like this<?php if ( current_user_can('edit_post') ) : ?>
You could write a function like this in
functions.php
:In your theme you would use it like this:
Learn more about Roles and Capabilities: http://codex.wordpress.org/Roles_and_Capabilities