From 373ba799c3c488fd0a86d0a7d248d03be24dfce6 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 30 Jul 2015 19:41:27 +0000 Subject: [PATCH] Backport r33469 and r33470 to 4.2. See #33106. Built from https://develop.svn.wordpress.org/branches/4.2@33518 git-svn-id: http://core.svn.wordpress.org/branches/4.2@33485 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-embed.php | 9 ++-- wp-includes/formatting.php | 76 ++++++++++++++++++++++++---------- wp-includes/shortcodes.php | 25 ++--------- 3 files changed, 63 insertions(+), 47 deletions(-) diff --git a/wp-includes/class-wp-embed.php b/wp-includes/class-wp-embed.php index eda4467c45..e3426ab8b1 100644 --- a/wp-includes/class-wp-embed.php +++ b/wp-includes/class-wp-embed.php @@ -312,11 +312,14 @@ class WP_Embed { * @return string Potentially modified $content. */ public function autoembed( $content ) { - // Strip newlines from all elements. - $content = wp_replace_in_html_tags( $content, array( "\n" => " " ) ); + // Replace line breaks from all HTML elements with placeholders. + $content = wp_replace_in_html_tags( $content, array( "\n" => '' ) ); // Find URLs that are on their own line. - return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); + $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); + + // Put the line breaks back. + return str_replace( '', "\n", $content ); } /** diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 08c367c645..0151e1fc64 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -419,10 +419,10 @@ function wpautop($pee, $br = true) { $pee = preg_replace('!()!', "$1\n\n", $pee); // Standardize newline characters to "\n". - $pee = str_replace(array("\r\n", "\r"), "\n", $pee); + $pee = str_replace(array("\r\n", "\r"), "\n", $pee); - // Strip newlines from all elements. - $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) ); + // Find newlines in all elements and add placeholders. + $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) ); // Collapse line breaks before and after