Private Messaging help!

Permalink
Hello!
I was wondering is it possible to restrict the view of the send private message link to just have a certain group see it? for example users with admin permissions but have the link vanish for ordinary users.

 
adajad replied on at Permalink Best Answer Reply
adajad
Yes there is, but you need to add some code and override a core page. If you haven't already I suggest you read this how-to on overrides to understand the concept before you continue: http://www.concrete5.org/documentation/how-tos/developers/change-th...

When you are done reading, this is how you can restrict the view of the "Send Private Message" link on the profile pages.

1. Copy the file 'root/concrete/elements/profile/sidebar.php' to 'root/elements/profile/sidebar.php'. Create the folder(s) as necessary.
2. Edit your newly copied 'root/elements/profile/sidebar.php' and add the two snippets of code I have commented below (make sure you view the entire block):
<?php  $av = Loader::helper('concrete/avatar'); ?>
<div id="ccm-profile-sidebar">
   <div class="ccm-profile-header">
      <a href="<?php echo View::url('/profile',$profile->getUserID())?>"><?php echo  $av->outputUserAvatar($profile)?></a><br />
      <a href="<?php echo View::url('/profile',$profile->getUserID())?>"><?php echo  $profile->getUsername()?></a>
   </div>
   <div style="margin-top:16px; padding-bottom:4px; margin-bottom:0px; font-weight:bold"><?php echo t('Member Since')?></div>
   <?php echo date(DATE_APP_GENERIC_MDY_FULL, strtotime($profile->getUserDateAdded('user')))?>
   <?php  
   $u = new User();
   $g = Group::getByName('Administrators'); //get the 'Administrators' group object
   if ($u->isRegistered() && $u->getUserID() != $profile->getUserID()) { ?>
   <div style="margin-top:16px;">
      <div>
      <?php  if( !UsersFriends::isFriend( $profile->getUserID(), $u->uID ) ){ ?>


I am getting the group object for Administrators with
$g = Group::getByName('Administrators');


When the code checks if PM is enabled I also check if the logged in user is in the group Administrators or is the Super Admin. If that is true the link will be rendered:
if ($profile->getUserProfilePrivateMessagesEnabled() == 1 && ($u->inGroup($g)||$u->isSuperUser()))