is it possible to make a redirection per role?
Thanks & regards
Alexander

Comments

Cory Goodwin’s picture

Yes

  global $user;
  if (in_array('admin', $user->roles)) {
    // Redirect the Administrator
    return 'admin';
  }  elseif (in_array('unverified', $user->roles)) {
    // Redirect Unverified
    return 'node/4';
} else {
    return 'node';
  }

jdlind38’s picture

How would you redirect users of a specific role and insert their user id in the url?? For example, user/[USER ID]/foo... Basically, I'm looking for the array to return 'user/'.$user->uid.'/my/example'

Cory Goodwin’s picture

Use this snippet to print the user id.

<?php
global $user;
print $user->uid;
?>

If you wanted to return a link for a logged in user you could use something like this

<a href="user/<?php
global $user;
print $user->uid;
?>">My Account</a>

--
Need professional help with your Drupal project? Goodwin Solutions

beckyjohnson’s picture

What would you do if you wanted to print out the user name for example the path to user/admin? If you want to re-direct a user to their main account page?

This is what i have so far:

// --- role based

global $user;
if (in_array('people', $user->roles)) {
    return 'user/' .$user->uid. '/apply_for_role';
    
    // The % means the person's Uid
}

if (in_array('principal', $user->roles)) {
    return 'users/' .$user ->uid. ;
}

else {
    return '<front>';
}

I'm using Drupal 6 though!
Becky

3cwebdev’s picture

Status: Active » Closed (fixed)