diff --git a/wp-includes/class-wp-embed.php b/wp-includes/class-wp-embed.php
index 148c5f4bf7..16e5acd79f 100644
--- a/wp-includes/class-wp-embed.php
+++ b/wp-includes/class-wp-embed.php
@@ -129,6 +129,12 @@ class WP_Embed {
* `->maybe_make_link()` can return false on failure.
*/
public function shortcode( $attr, $url = '' ) {
+ // This filter can be used to output custom HTML instead of allowing oEmbed to run.
+ $custom = apply_filters( 'wp_embed_shortcode_custom', false, $attr, $url );
+ if ( false !== $custom ) {
+ return $custom;
+ }
+
$post = get_post();
if ( empty( $url ) && ! empty( $attr['src'] ) ) {
@@ -318,11 +324,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 25fb02d608..f323e9c0af 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -504,8 +504,8 @@ function wpautop( $pee, $br = true ) {
// Standardize newline characters to "\n".
$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