Skip to content

Instantly share code, notes, and snippets.

@brandonkelly
Created June 22, 2012 19:26
Show Gist options
  • Save brandonkelly/2974626 to your computer and use it in GitHub Desktop.
Save brandonkelly/2974626 to your computer and use it in GitHub Desktop.
Trim out whitespace when saving a Wygwam field
In system/expressionengine/third_party/wygwam/ft.wygwam.php, find this in the beginning of the save() function:
// Clear out if just whitespace
if (! $data || preg_match('/^\s*(<\w+>\s*(&nbsp;)*\s*<\/\w+>|<br \/>)?\s*$/s', $data))
{
return '';
}
And replace it with this:
// Trim out any whitespace/empty tags
$data = preg_replace('/^(\s|<(\w+)>(&nbsp;|\s)*<\/\2>|<br \/>)*/', '', $data);
$data = preg_replace('/(\s|<(\w+)>(&nbsp;|\s)*<\/\2>|<br \/>)*$/', '', $data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment