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 trying to get the user level of the author that is displayed on an author page (not the current user that is logged in, but the user that is presented on the current author page that I am viewing)

I am using this code

<?
get_currentuserinfo() ;
global $user_level;
if ($user_level >= 4) {
     include (TEMPLATEPATH . '/author_1.php');
} else {
    include (TEMPLATEPATH .'/author_2.php');
}
?>

I tried to replace $user with $curauth but still no results, it is showing only one template for both. Any ideas?

thank you

share|improve this question
    
Levels have been deprecated years ago, they are mostly meaningless nowadays. Why do you need them? –  toscho Nov 25 '13 at 1:31
    
simply because I need to have two author pages, based on user level/role –  whitelord Nov 25 '13 at 1:35

1 Answer 1

up vote 3 down vote accepted

toscho is correct. User levels have been deprecated for a long time now. However, the following will get you the available information about the author of the posts on an author archive page.

$author = get_queried_object();
var_dump($author);

In that dump you should see everything you need, but use the role not the user level-- look in $author->roles. For example:

$author = get_queried_object();
$allowed = array('author','editor','administrator');
$roles = array_intersect($author->roles,$allowed);
if (!empty($roles)) {
  include (TEMPLATEPATH . '/author_1.php');
} else {
  include (TEMPLATEPATH .'/author_2.php');
}

You should also almost certainly be using get_template_part instead of include.

share|improve this answer
    
thanks, but I'm not sure why I should look there. I do not need to see the role, I just need to redirect to the correct author template based on the author's role. –  whitelord Nov 25 '13 at 2:05
    
I do not know how to use it for what I need. –  whitelord Nov 25 '13 at 2:44
    
The code in your opening post is about 90% there. I will expand the answer a later. –  s_ha_dum Nov 25 '13 at 3:30
    
it actually worked with iclude. using get_template_part breaks some code on the template. thank you for your help, much appreciated! –  whitelord Nov 25 '13 at 22:35
    
get_template_part should not break code. At its heart is just an include. You probably have a variable scope problem. –  s_ha_dum Nov 25 '13 at 22:58

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.