Created
July 19, 2022 13:17
-
-
Save bjornpatje/7a3a4025c9e251c24be00c0c161e6e7d to your computer and use it in GitHub Desktop.
Whitespace fix WordPress
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
<?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