How can we identity or differentiate between admin or frontend code execution or request?
If you are hard core developer then surely you will be required this function now and then. And in this case, our recommendation is to add this function in your core helper class because then you can use this function from more than one module.
Here are the two functions we have written, you can use either of them, this function will return true if you are on admin or executing the code at admin end of the site.
public function isAdmin() { if(Mage::getDesign()->getArea() == Mage_Core_Model_Design_Package::DEFAULT_AREA){ return false; } return true; }
or
public function isAdmin() { if(Mage::app()->getStore()->isAdmin()){ return true; } if(Mage::getDesign()->getArea() == 'adminhtml'){ return true; } return false; }
Hope this article helped you in some way. Please leave us your comment and let us know what do you think?