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.

I am using the admin role and 2 custom roles. On the author.php i want to be able to place the role of that user.

I am using this to pull the role out in text

$curauth = $wp_query->get_queried_object();
$user_id = $curauth->ID;
$user = new WP_User( $user_id );
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    foreach ( $user->roles as $role )
        echo $role;
}

Put i want to be able to put that into something like

if (current_user_can('buyer')) { 
        get_template_part( 'buyer', 'edit' ); } 
      else if (current_user_can('courier')) { 
        get_template_part( 'courier', 'edit' ); } 
      else if (current_user_can('banned')) { 
        get_template_part( 'account', 'banned' ); }
      else if (is_user_logged_in()) { 
        get_template_part( 'account', 'error' );
    } else {  }

Which using for the current users, i need to make that work for the author user.

share|improve this question
    
You question is a little confusing. The first code echoes a user's role. The second code adds a template part based on their role. What, exactly, are you trying to do? –  infamouse Apr 12 '13 at 21:05
    
The second code echos the current user, i want it to echo the author so i may use it in the author.php. –  Noob Theory Apr 12 '13 at 22:14
    
If my answer worked please mark it as the solution. –  infamouse Apr 16 '13 at 17:46
add comment

1 Answer

up vote 1 down vote accepted

As an alternative to "current_user_can" WordPress provides "user_can" which will take a User object or ID as a parameter. Combining your top code and the bottom code with the new function it would look like this:

$author_user = $wp_query->get_queried_object(); // the queried object in 'author.php' should be an author user

if (user_can($author_user, 'buyer')) { 
  get_template_part( 'buyer', 'edit' );
} else if (user_can($author_user, 'courier')) { 
  get_template_part( 'courier', 'edit' );
} else if (user_can($author_user, 'banned')) { 
  get_template_part( 'account', 'banned' ); 
} else {
  // etc...
}
share|improve this answer
add comment

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.