<?php
/*
Plugin Name: v2.03 Demos
Description: Demos and example code for new CMS admin plugin features including:  Displaying custom row colors for different records, modifying displayed field values on list page, and adding custom action links to the actions column. (See source code for more details).
Version: 1.00
Requires at least: 2.03
*/

// register callbacks

addFilter('listRow_trStyle',      'v203_highlightAdminUsers', null, 3);
addFilter('listRow_displayValue', 'v203_linkEmails',          null, 4);
addFilter('listRow_actionLinks',  'v203_addViewLiveLink',     null, 3);


// admin record lists: update style of <tr> rows
// Example: show red background for admin accounts under "User Accounts"
// Notes: Other uses might included color coding record rows based on status or priority
function v203_highlightAdminUsers($trStyle, $tableName, $record) {
  if (@$tableName != 'accounts') { return $trStyle; }  // skip all but specified section/table name

  // add style to <tr> rows if record has 'isAdmin' checked
  if ($record['isAdmin']) { $trStyle = "background-color: #FCC;"; }

  return $trStyle;
}



// admin record lists: modify column values
// Example: Convert any column value with an @ in it into a mailto: link
// Notes: Other uses would be adding any custom data or formatting for the list view display
function v203_linkEmails($displayValue, $tableName, $fieldname, $record) {
// we've commented out the next line so this will affect all sections, uncomment to limit to one section
// if (@$tableName != 'accounts') { return $displayValue; }  // skip all but target section

  // check for @
  $containsAt = (strstr($displayValue, '@') !== false);

  // create mailto: link
  if ($containsAt) {
    $displayValue = "<a href='mailto:$displayValue'>$displayValue</a>";
  }

  return $displayValue;
}



// admin record lists: add or modify action links
// Example: Add a "view live" link that opens the viewer for this record in a new window (example only, requires valid viewer url to work)
// Notes: Other uses would include adding custom actions or functionality to the CMS, linking to 3rd party scripts such as emailers, etc.
function v203_addViewLiveLink($actionLinks, $tableName, $record) {
// we've commented out the next line so this will affect all sections, uncomment to limit to one section
// if (@$tableName != 'accounts') { return $actionLinks; }  // skip all but target section

  $actionLinks .= "<a href='/path/to/web/viewer.php?{$record['num']}' target='_blank'>view live</a>";

  return $actionLinks;
}


?>
