<?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.00
Requires at least: 2.05
*/

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) {
    $record = &$records[ $index ];

    foreach (array_keys($record) as $fieldname) {
      $value = &$record[$fieldname];
      if ($value == '0000-00-00 00:00:00') { $value = ''; }
    }
  }

  return $records;
}

?>
