1

so close to figuring this out, or not I'm not to sure! Basically what I want to do is on the authors page (so outside the loop) if a user role is an editor I want to display a little badge (but just outputting their name and role at the mo) in their profile. I have:

functions.php:

function get_user_role($id)
{
    $user = new WP_User($id);
    return array_shift($user->roles);
}

and

author.php:

<?php
global $post;
$aid = $post->post_author;
if ($userlevel == '2') {
echo get_the_author_meta('user_nicename', $aid).' | '.get_user_role($aid);
}

?>

But doesn't seem to work, any ideas?

2
  • 3
    Please follow up on your other questions. You're already in a position where most people will stay away from answering further ones.
    – kaiser
    Jun 28, 2012 at 15:37
  • Any progress on this question?
    – kaiser
    Apr 1, 2013 at 19:18

2 Answers 2

1

In your template:

// rolename could for e.g. be 'editor' or 'author' or 'administrator'
author_can( get_the_ID(), 'rolename' ) AND print "<img src='...' alt='A kool badge!' />";
2
  • Hi, thanks for the reply, but would this not display for the logged in user and not the author of the profile?
    – david
    Jun 28, 2012 at 15:21
  • @david Yes, you were right. Code fixed.
    – kaiser
    Oct 17, 2012 at 15:10
0

Edit: Get all the editors first and then loop over them.

$users = get_users(array('role' => 'editor'));
//foreach user,
//your badge code

Does this help?

4
  • thanks for the reply but don't seem to get anything with that, using: if(current_user_can('editor')){ echo 'hello world '; }
    – david
    Jun 27, 2012 at 10:11
  • Are you logged in with that role? If you're logged in as administrator, try replacing editor with administrator. Do you want the code to run for logged in users only or any user with the editor role? Jun 27, 2012 at 10:14
  • also wouldn't current_user_can only work if you were logged in as an editor, I want to display someone an editor to people visiting the site
    – david
    Jun 27, 2012 at 10:14
  • Okay... then you may have to get the users list first, then check their role which is in the users object and do the stuff. Jun 27, 2012 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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