Hide Modify Link - Plugin

3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: April 2, 2015   (RSS)

By Ryan - March 24, 2015

Hi, I was trying to create a plugin that would allow me to hide the modify link next to records that have a status field set to closed.

I been trying to use the hook listRow_actionLinks but with no luck.

Has anyone done anything like this before?

<?php
/*
Plugin Name: Hide Modify Link
Author: RD
Description: Hide Modify Link
Version: 1.00
Requires at least: 2.03
*/


addFilter('listRow_actionLinks',      'hideModifyLink', null, 3);

function hideModifyLink($trStyle, $tableName, $record) {
//only run when saving records in certain tables
 if ($tableName == 'requisitions') {
 
  if (@$record['status'] && @$record['status'] == 3) { // if record is closed (3)
  
   $showModify = false; 
   
  }
 }
}

?>

Hi mjftech,

The problem is that the listRow_actionLinks is designed for adding new links as opposed to editing or removing those that are already displayed for a certain user. You could try and remove edit link using str_replace:

function hideModifyLink($trStyle, $tableName, $record) {
//only run when saving records in certain tables
 if ($tableName == 'requisitions') {
 
  if (@$record['status'] && @$record['status'] == 3) { // if record is closed (3)
  
    //str_replace function goes in here
    $trStyle = str_replace("<a href=\"?menu={$tableName}&amp;action=edit&amp;num={$record['num']}\">modify</a>", '', $trStyle)
    
  }
 }
 //After you've updated the link, return it.
 return $trStyle;
}

This is just example code, so it might need some tweaking to get it to work with your plugin. So if the status and table are correct, the $trStyle variable gets updated to remove the modify link. Finally the $trStyle item is then returned. 

I'm wondering if a better option is to grey out records that have a status of 3 instead, you could do easily using this plugin:

http://www.interactivetools.com/add-ons/detail.php?Grey-Hidden-Records-1025

I think there could be unintended consequences to removing the modify link, for example what if someone accidentally selects the incorrect status.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com