<?php
/*
Plugin Name: Remove Extra Whitespace
Description: Blank out fields on input that are submitted with nothing but whitespace and field on output with zero'd out (blank) dates.
Version: 1.03
Requires at least: 2.05
*/

//if (@$_SERVER['REMOTE_ADDR'] != '184.71.180.122') { return; }

addFilter('admin_postlogin',    'removeExtraWhitespace');
addFilter('viewer_output_rows', 'blankOutZeroDates',    null, 3);

//
function removeExtraWhitespace() {
  foreach (array_keys($_REQUEST) as $name) {
    if (is_array( $_REQUEST[$name] )) { continue; } // skip arrays

    $_REQUEST[$name] = preg_replace("/^\s+$/s", '', $_REQUEST[$name]);
  }
}

function blankOutZeroDates($records, $listDetails, $schema) {
  foreach (array_keys($records) as $index) {
    foreach ($records[$index] as $fieldname => $value) {
      if ($value == '0000-00-00 00:00:00') { $records[$index][$fieldname] = ''; }
    }
  }
  return $records;
}
  

?>
