Action, if a specific user is logged in
Permalink 1 user found helpful
Hi!
I'm familiar with the condition if a registered user is logged in:
But what if i want to have a condition if a specific user is logged in, e.g. the user with id=23. How would i do that?
Would it also be possible to create conditions for specific user groups?
Thank you,
Michael
I'm familiar with the condition if a registered user is logged in:
<?php $u = new User(); if($u->isLoggedIn()) { // do this }
But what if i want to have a condition if a specific user is logged in, e.g. the user with id=23. How would i do that?
Would it also be possible to create conditions for specific user groups?
Thank you,
Michael
Thank you,
but where does the id of the user in my example go?
but where does the id of the user in my example go?
just run another IF statement inside the first, like so...
<?php $u = new User(); if($u->isLoggedIn()) { if($u == 1) { echo t("User ID is 1"); } } ?>
Just clarifying a difference between a user object and a user id
$u = new User(); // user object for current user $uID = $u->getUserID(); // then from that get the user id for current user
Excellent, thank you john, In my haste writing and testing this from memory (finally getting this stuff!!), I only tested it against "1" for super user and didn't realize I missed that line...
this works perfect now!!
this works perfect now!!
And this will check if the user is in the "Administrators" group and then filter the personalized code by a set of user id's...
<?php $u = new User(); $uID = $u->getUserID(); $groups = $u->getUserGroups(); $grp = Group::getByName('Administrators'); if($u->isLoggedIn()) { if(!$u->inGroup($grp)) { if($uID == 1) { echo t("Logged as User ID 1, administrator"); } if($uID == 2) { echo t("Logged as User ID 2, administrator"); } } }
Viewing 15 lines of 16 lines. View entire code block.
Cool! Thank you so much!
Cheers,
Michael
Cheers,
Michael
Something like that. I'm not at my desk right now and can't remember it off hand...