Skip to content

Instantly share code, notes, and snippets.

@Vheissu
Created October 15, 2012 23:22
Show Gist options
  • Save Vheissu/3896305 to your computer and use it in GitHub Desktop.
Save Vheissu/3896305 to your computer and use it in GitHub Desktop.
Wordpress Auto P Forked
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('!(]*&gt;)!', "\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*]*)&gt;\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('!
([^&lt;]+)!', "
$1
", $pee);
$pee = preg_replace('!
\s*(]*&gt;)\s*
!', "$1", $pee); // don't pee all over a tag
$pee = preg_replace("|
( &lt;li.+?)
|", "$1", $pee); // problem with nested lists
$pee = preg_replace('|
]*)&gt;|i', "
", $pee);
$pee = str_replace('
', '
', $pee);
$pee = preg_replace('!
\s*(]*&gt;)!', "$1", $pee);
$pee = preg_replace('!(]*&gt;)\s*
!', "$1", $pee);
if ($br) {
$pee = preg_replace_callback('/&lt;(script|style).*?&lt;\/\\1&gt;/s', create_function('$matches', 'return str_replace("\n", " ", $matches[0]);'), $pee);
$pee = preg_replace('|(?&lt;!
)\s*\n|', "
\n", $pee); // optionally make line breaks
$pee = str_replace(' ', "\n", $pee);
}
$pee = preg_replace('!(]*&gt;)\s*
!', "$1", $pee);
$pee = preg_replace('!
(\s*]*&gt;)!', '$1', $pee);
if (strpos($pee, ']*&gt;)(.*?)
!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