Get Admin Logged-In Status from Frontend in Mage Adobe Commerce (Magento 2)
Here we learn, how to know the admin logged in status from frontend in Adobe Commerce (Magento 2).
Write the below code where ever you need to know the admin logged in status from frontend in Adobe Commerce (Magento 2).
public function isAdminloggedIn()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$dateTime = $objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime');
$adminConfig = $objectManager->create('Magento\Security\Model\Config');
$lifetime = $adminConfig->getAdminSessionLifetime();
$currentTime = $dateTime->gmtTimestamp();
$adminSession = $objectManager->create('Magento\Security\Model\AdminSessionsManager');
$lastUpdatedTime = $dateTime->gmtTimestamp($adminSession->getCurrentSession()->getUpdatedAt());
if (!is_numeric($lastUpdatedTime)) {
$lastUpdatedTime = strtotime($lastUpdatedTime);
}
if ($lastUpdatedTime >= ($currentTime - $lifetime)
&& $adminSession->getCurrentSession()->getStatus() == 1
&& $adminSession->getCurrentSession()->getUserId()
) {
return true;
} else {
return false;
}
}
If you require any technical help, please email us at support@webkul.com. Additionally, browse various solutions to improve your store’s functionality by visiting the Adobe Commerce plugins page.
For expert consultation or to develop custom features, Hire Adobe Commerce Developers for your project.
That’s it.
Categories:
Magento2.1
View Comments (2)
Comment or Ask a Question
Quick Links