Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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:

function user_role_check( $role, $user_id = null ) {

  $user = wp_get_current_user();

    if ( empty( $user ) )
    return false;

  return in_array( $role, (array) $user->roles );
}

In your theme you would use it like this:

<?php if ( user_role_check( 'administrator' )): ?>

   Do this 

 <?php else: ?>

   Do this

<?php endif; ?>

Learn more about Roles and Capabilities: http://codex.wordpress.org/Roles_and_Capabilities

share|improve this answer
    
thank you for your answer. the problem is i need to use bbp_get_reply_author_id() to show the role & image below the username of every forum user in my bbpress forums. so i don't think wp_get_current_user() would work in this case. any other ideas? –  Allen Payne Mar 11 '13 at 2:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.