I'm trying to set it so that when you view somebody's profile page you see a different template based on their role. So, everybody gets a regular "profile" page but if your also a author you also get a special "editor" page as well.

Normally in Wordpress you get...


but what I want is...


Below is what I've got so far in my functions.php file but the line that sets variable $curauth doesn't seem to work here. But it does work in my loop.php file???

function change_author_permalinks() {
    global $wp_rewrite;

    $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
    if ( !get_user_role( 'subscriber', $curauth->ID ) ) {
        $wp_rewrite->author_base = 'editor';
    } else {
        $wp_rewrite->author_base = 'profile';


i needed something similar to this so i added a rewrite rule to the same author.php file and there i added a redirect based on the user role, so to put this in your use case:

First redirect editor to your theme author.php file by adding this rewrite rule

function my_rewrite_rules_098( $wp_rewrite ) {
  $newrules = array();
  $new_rules['editor/(\d*)$'] = 'index.php?author_name=$matches[1]';
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

Next create a function to check the user role, say in your functions.php file:

function user_has_role( $roles_to_check = array(), $user_id ) {

  if( ! $roles_to_check ) return FALSE;
  if( ! $user_id ) return FALSE;

  $user = new WP_User( $user_id ); // $user->roles

  return in_array( $roles_to_check, $user->roles, FALSE );

then in your author.php theme file at the top add this:

if(isset($_GET['author_name'])) {
    $curauth = get_userdatabylogin($author_name);
    $curauth = get_userdata(intval($author));
//check user role  
$user_role_exists = user_has_role( array('Author'),$curauth->ID; );
if ($user_role_exists && isset(get_query_var('editor'))){
    //either rediret to a different editor.php template file 
    //or include it here something like:

Hope this helps

  • hmmm I'm still getting the same result in $curauth = bool(false). Should $author_name and $author be set as global variables? – EddyR Feb 27 '11 at 10:05
  • not in functions.php only on author.php – Bainternet Feb 27 '11 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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