Created
October 15, 2012 23:22
-
-
Save Vheissu/3896305 to your computer and use it in GitHub Desktop.
Wordpress Auto P Forked
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
function wpautop_forked($pee, $br = 1) {</code> | |
if ( trim($pee) === '' ) | |
return ''; | |
$pee = $pee . "\n"; // just to make things a little easier, pad the end | |
$pee = preg_replace('| | |
\s* | |
|', "\n\n", $pee); | |
// Space things out a little | |
$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li | |
|pre|select|option|form|map|area|blockquote|img|address|math|style|input | |
|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer | |
|nav|figure|figcaption|details|menu|summary)'; | |
$pee = preg_replace('!(]*>)!', "\n$1", $pee); | |
$pee = preg_replace('!()!', "$1\n\n", $pee); | |
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines | |
if ( strpos($pee, ' $pee = preg_replace('|\s*]*)>\s*|', "", $pee); // no pee inside object/embed | |
$pee = preg_replace('|\s*\s*|', '', $pee); | |
} | |
$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates | |
// make paragraphs, including one at the end | |
$pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY); | |
$pee = ''; | |
foreach ( $pees as $tinkle ) | |
$pee .= ' | |
' . trim($tinkle, "\n") . " | |
\n"; | |
$pee = preg_replace('| | |
\s* | |
|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace | |
$pee = preg_replace('! | |
([^<]+)!', " | |
$1 | |
", $pee); | |
$pee = preg_replace('! | |
\s*(]*>)\s* | |
!', "$1", $pee); // don't pee all over a tag | |
$pee = preg_replace("| | |
( <li.+?) | |
|", "$1", $pee); // problem with nested lists | |
$pee = preg_replace('| | |
]*)>|i', " | |
", $pee); | |
$pee = str_replace(' | |
', ' | |
', $pee); | |
$pee = preg_replace('! | |
\s*(]*>)!', "$1", $pee); | |
$pee = preg_replace('!(]*>)\s* | |
!', "$1", $pee); | |
if ($br) { | |
$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", " ", $matches[0]);'), $pee); | |
$pee = preg_replace('|(?<! | |
)\s*\n|', " | |
\n", $pee); // optionally make line breaks | |
$pee = str_replace(' ', "\n", $pee); | |
} | |
$pee = preg_replace('!(]*>)\s* | |
!', "$1", $pee); | |
$pee = preg_replace('! | |
(\s*]*>)!', '$1', $pee); | |
if (strpos($pee, ']*>)(.*?) | |
!is', 'clean_pre', $pee ); | |
$pee = preg_replace( "|\n | |
$|", ' | |
', $pee ); | |
return $pee; | |
} | |
remove_filter('the_content', 'wpautop'); | |
add_filter('the_content', 'wpautop_forked'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment