Joomla - Check to see if we are in admin area or not
Asked Answered
S

2

17

I'm creating a new template for my joomla website and I've replaced joomla's native Mootools with jQuery and I'm converting all moo codes to jQuery ones.

Somehow many of codes like the ones in joomla libraries are written for both admin and frontend area, and if I replace them with jquery codes, admin section won't work properly. I wanna know if there's a way to determine if we are in admin section of site or not, so I can use javascript codes based on this condition.

Stickle answered 5/9, 2012 at 15:6 Comment(0)
M
36

It seems to work in Joomla 1.5, Joomla 2.x and 3.x

$app = JFactory::getApplication();
if ($app->isSite())  echo 'Client is site';
if ($app->isAdmin()) echo 'Client is administrator';
Minutes answered 6/9, 2012 at 15:12 Comment(1)
Only variables should be assigned by reference.Gradation
B
5

For Joomla 4.0 should be

$app = Joomla\CMS\Factory::getApplication();
if ($app->getName() == 'administrator')   //since   3.2
    echo 'Client is administrator';
Borderline answered 15/9, 2020 at 8:18 Comment(1)
I notice in the code, that before 4,0 getApplication()->isAdmin() would do the job, but from 4.0, it is deprecated and isClient('administrator') is advised. isClient is valid from 3.7.0 onwards.Medamedal

© 2022 - 2024 — McMap. All rights reserved.