The cleanest way is to create an observer that adds the class to the body.
For this you can create a new module (or use an existing one. Just in case, here is how you can create one. Let's call it Easylife_AdminClass
).
You will need the following files:
app/etc/modules/Easylife_AdminClass.xml
- the declaration file
<?xml version="1.0"?>
<config>
<modules>
<Easylife_AdminClass>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Adminhtml />
</depends>
</Easylife_AdminClass>
</modules>
</config>
app/code/local/Easylife/AdminClass/etc/config.xml
- the configuration file
<?xml version="1.0"?>
<config>
<modules>
<Easylife_AdminClass>
<version>0.0.1</version>
</Easylife_AdminClass>
</modules>
<global>
<models>
<adminclass>
<class>Easylife_AdminClass_Model</class>
</adminclass>
</models>
</global>
<adminhtml>
<events><!-- event used for adding a class to the body-->
<core_block_abstract_to_html_before>
<observers>
<adminclass>
<type>singleton</type>
<class>adminclass/adminhtml_observer</class>
<method>addBodyClass</method>
</adminclass>
</observers>
</core_block_abstract_to_html_before>
</events>
</adminhtml>
</config>
app/code/local/Easylife/AdminClass/Model/Observer.php
- the observer.
<?php
class Easylife_AdminClass_Model_Adminhtml_Observer{
public function addBodyClass($observer){
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Page){ //check if the block is the root block,
$admin = Mage::getSingleton('admin/session')->getUser();
if ($admin->getId()){//check if the admin is logged in
$block->addBodyClass($admin->getUsername());//add the class to the body.
}
}
return $this;
}
}
I recommend adding a prefix to the class you add to the body.
I mean replace $block->addBodyClass($admin->getUsername());
with $block->addBodyClass('some-prefix-'.$admin->getUsername());
since the username can be almost anything. For example you will have a surprise if you have an admin named 'root'. Here is how the root
class looks in the default admin css
.root{
position: relative;
height: 260px;
margin: 0;
width: 1px;
}