TIPP: How to show edit & delete buttons only for creators of replies and admins
TIPP: How to show edit & delete buttons only for creators of replies and admins
I wondered why logged in user can see edit and delete links, even if they have not the right to use them. To make the edit and delete link only visible to user with the correct rights and admins follow these instructions:
1. Make a copy of "com_communityanswers/layouts/default/question/replies.php"
2. Change "edit":
2.1. Search for line 163 - 69:
if($params->get('access-edit')){
?>
| <a href="#" onclick="document.adminForm.cid.value=<?php echo $reply->id;?>;Joomla.submitbutton('reply.edit');return false;"
class="muted text-muted">
<?php echo JText::_('JGLOBAL_EDIT');?>
</a>
<?php
}
2.2. Add the green lines, so the code should look like this:
if($params->get('access-edit')){
?>
<?php if ((!$user->guest && ($reply->created_by == $user->id)) || ($user->authorise('core.admin', $asset))) { ?>
| <a href="#" onclick="document.adminForm.cid.value=<?php echo $reply->id;?>;Joomla.submitbutton('reply.edit');return false;" class="muted text-muted">
<?php echo JText::_('JGLOBAL_EDIT');?>
</a>
<?php } ?>
<?php
}
3. Do the same with the delet section in line 209 - 215, it should look like this:
?>
<?php if ((!$user->guest && ($reply->created_by == $user->id)) || ($user->authorise('core.admin', $asset))) { ?>
| <a href="#"
onclick="document.adminForm.cid.value=<?php echo $reply->id;?>;Joomla.submitbutton('replies.trash'); return false;"
class="muted text-muted">
<?php echo JText::_('COM_COMMUNITYANSWERS_LABEL_DELETE');?>
</a>
<?php } ?>
<?php
That's it, upload the file in your template override folder and the edit and delete link are only visible for reply creator and admin.
Hope this will help somebody.
Best regards,
Jürgen