Created
June 22, 2012 19:26
-
-
Save brandonkelly/2974626 to your computer and use it in GitHub Desktop.
Trim out whitespace when saving a Wygwam field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*( )*\s*<\/\w+>|<br \/>)?\s*$/s', $data)) | |
{ | |
return ''; | |
} | |
And replace it with this: | |
// Trim out any whitespace/empty tags | |
$data = preg_replace('/^(\s|<(\w+)>( |\s)*<\/\2>|<br \/>)*/', '', $data); | |
$data = preg_replace('/(\s|<(\w+)>( |\s)*<\/\2>|<br \/>)*$/', '', $data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment