By jorre on
is there a way / variable to check if the logged in user is an admin or moderator or any kind of role?
I'd like to show the loginscreen only to admins/moderators...
is there a way / variable to check if the logged in user is an admin or moderator or any kind of role?
I'd like to show the loginscreen only to admins/moderators...
Comments
It is possible to check
It is possible to check whether the logged-in user has a certain role. For example, something like this if you have a role called 'moderator'
However, this is useless for showing the login screen only to 'moderators', because if they are not already logged-in they are not moderators, they are just visitors.
thanks, this works out just
thanks, this works out just perfect. there is a link to the login screen, I just don't want normal users to have a navigation menu available, only mods/admin
Pakfriet.be
If the user isn't logged in how will you check?
If the user is logged in, they don't need a login screen.
If a visitor is not logged in, there isn't any way to know what role(s) they might belong to once logged in.
In any event, every hacker bot on planet earth knows that every drupal site's login pages are located at {yoursite}/user/login
spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...
It is also possible to check
It is also possible to check so using the drupal built in user_access() function, for example the super administrator account doesn't have a role by default so you can check it using :
hope it might help somebody.
Note: I tried this with drupal version 5.x
And for Drupal 7.x, since the
And for Drupal 7.x, since the administrator role isn't included by default (i.e. we don't know what the RID or the role name will be) ...
if (user_access('administer site configuration')) {
// do something
}
haha
works like a charm!
Just what I was looking for,
Just what I was looking for, thanks
Thanks to cog.rusty and
Thanks to cog.rusty and mos3abof for such clear, concise info and code.
This thread will be useful to many.
// Load the currently logged
// Load the currently logged in user.
global $user;
if (in_array('administrator', $user->roles)) {
// do fancy stuff
$form['field_end_date']['#disabled'] = FALSE;
}
Where I write this code for check user?
Hi All,
Where I need to write this code for check user role.
Do i need to write in any custom module with hook_init()?
or any other place?
Please suggest !
I have 100 users registered
I have 100 users registered in Mysite and they are from different countries. They have also posted their Content.
When they logged in their account, how do I show if they are Online/Offline to other users ?
Any help much appreciated.
=-=
The thread was generated under Durpal 4.7.x. If you are suing a core that old, upgrade. If you aren't, generate a new thread tagged with the version of Drupal in use.
thanks, this works out just
thanks, this works out just perfect. there is a link to the login screen, I just don't want normal users to have a navigation menu available, only mods/admin
Just what I was looking for,
Just what I was looking for, thanks
Using hasRole() for Drupal 10
This thread is very useful, so I thought it'd be worth coming back here to update for Drupal 10. Based on the addition made here: https://www.drupal.org/node/3002289 which introduces
hasRole()For my uses, I needed to hide a button for all users who were NOT administrators. This is what worked for me:
You probably don't want to
You probably don't want to exclude user 1 if the administrator role is not assigned.