Skip to content

Instantly share code, notes, and snippets.

@bjornpatje
Created July 19, 2022 13:17
Show Gist options
  • Save bjornpatje/7a3a4025c9e251c24be00c0c161e6e7d to your computer and use it in GitHub Desktop.
Save bjornpatje/7a3a4025c9e251c24be00c0c161e6e7d to your computer and use it in GitHub Desktop.
Whitespace fix WordPress
<?php
function ___wejns_wp_whitespace_fix($input) {
$allowed = false;
$found = false;
foreach (headers_list() as $header) {
if (preg_match("/^content-type:\\s+(text\\/|application\\/((xhtml|atom|rss)\\+xml|xml))/i", $header)) {
$allowed = true;
}
if (preg_match("/^content-type:\\s+/i", $header)) {
$found = true;
}
}
if ($allowed || !$found) {
return preg_replace("/\\A\\s*/m", "", $input);
} else {
return $input;
}
}
ob_start("___wejns_wp_whitespace_fix");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment