Forum

Thread tagged as: Question

check if admin user is logged in from the front end

hi,

is it possible to check if an admin user is logged in from a page on the front end?

like perch_member_logged_in() but for admin users not members?

thanks.

Mark Smith

Mark Smith 0 points

  • 4 years ago

You could use minimal perch API function, but I don't see any reason this would be useful, what would you be hoping to do? Maybe there is something better...

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, the "Ctrl-E to edit" functionality does this. What are you trying to achieve? You have to be careful with it or you'll kill your performance.

i'd like a couple of pages on the site which are for staff only, i know could register them as members but the only people who need to access are admin users so it's not ideal to ask them to log in as a member and an admin user separately to view. the pages would be very low traffic so i'm not too concerned with performance but i'm open to suggestions if there's a better approach?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's not public API, so I can't support it, but you can use:

$Users = new PerchUsers;
$CurrentUser = $Users->get_current_user();

if (is_object($CurrentUser) && $CurrentUser->logged_in()) {
    ... user is logged in ...
}

thank you!