I have seen several posts regarding hiding unwanted fields in the frontend editor and several posts asking about getting the user's group, and I needed to do both, so here's my solution.
Put the following code near the top of form.php
<?php// get user ID$user = &JFactory::getUser();$userId = $user->get('id');// get user Group$db =& JFactory::getDBO();$query = " SELECT ".$db->nameQuote('group')." FROM ".$db->nameQuote('jos_k2_users')." WHERE ".$db->nameQuote('userID')." = ".$db->quote($userId)."; ";$db->setQuery($query);$userGroup = $db->loadResult();?>
You can then surround whatever element you want to hide as in the following example where I hide the toggle sidebar unless user is editor or site owner.
<?php if($userGroup == 2 OR $userGroup == 4) : ?> <div id="k2ToggleSidebarContainer"> <a href="#" id="k2ToggleSidebar"><?php echo JText::_('Toggle sidebar'); ?></a> </div> <?php endif; ?>
These are my user group numbers and will be different on your site. Just check your database (jos_k2_user_groups) to get the numbers that correspond to each of your groups.
Put the following code near the top of form.php
<?php// get user ID$user = &JFactory::getUser();$userId = $user->get('id');// get user Group$db =& JFactory::getDBO();$query = " SELECT ".$db->nameQuote('group')." FROM ".$db->nameQuote('jos_k2_users')." WHERE ".$db->nameQuote('userID')." = ".$db->quote($userId)."; ";$db->setQuery($query);$userGroup = $db->loadResult();?>
You can then surround whatever element you want to hide as in the following example where I hide the toggle sidebar unless user is editor or site owner.
<?php if($userGroup == 2 OR $userGroup == 4) : ?> <div id="k2ToggleSidebarContainer"> <a href="#" id="k2ToggleSidebar"><?php echo JText::_('Toggle sidebar'); ?></a> </div> <?php endif; ?>
These are my user group numbers and will be different on your site. Just check your database (jos_k2_user_groups) to get the numbers that correspond to each of your groups.