diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index 71f1794c52..fb2141da46 100644
--- a/src/wp-includes/formatting.php
+++ b/src/wp-includes/formatting.php
@@ -238,16 +238,30 @@ function wpautop($pee, $br = true) {
$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
$pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
- if ( strpos($pee, '' ) !== false ) {
+ // no P/BR around param and embed
+ $pee = preg_replace( '|(|', '', $pee );
+ $pee = preg_replace( '%\s*(?(?:param|embed)[^>]*>)\s*%', '$1', $pee );
}
+
+ if ( strpos( $pee, '\]]*[>\]])\s*%', '$1', $pee );
+ $pee = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee );
+ $pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $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 )
+
+ 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('!([^<]+)(div|address|form)>!', "
$1
$2>", $pee);
$pee = preg_replace('!\s*(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee); // don't pee all over a tag
@@ -256,11 +270,13 @@ function wpautop($pee, $br = true) {
$pee = str_replace('
', '', $pee);
$pee = preg_replace('!\s*(?' . $allblocks . '[^>]*>)!', "$1", $pee);
$pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
+
if ( $br ) {
$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
$pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks
$pee = str_replace('', "\n", $pee);
}
+
$pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
$pee = preg_replace('!
(\s*?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
$pee = preg_replace( "|\n$|", '', $pee );
diff --git a/tests/phpunit/tests/formatting/Autop.php b/tests/phpunit/tests/formatting/Autop.php
index 7cd324f985..d2f78bc17e 100644
--- a/tests/phpunit/tests/formatting/Autop.php
+++ b/tests/phpunit/tests/formatting/Autop.php
@@ -98,4 +98,169 @@ PS. Not yet subscribed for update notifications?
Password: ';
$this->assertEquals( "$str
", trim( wpautop( $str ) ) );
}
+
+ /**
+ * wpautop() Should not add and
around and