diff --git a/src/wp-includes/class-wp-embed.php b/src/wp-includes/class-wp-embed.php index f536f71a04..1cd4d6252c 100644 --- a/src/wp-includes/class-wp-embed.php +++ b/src/wp-includes/class-wp-embed.php @@ -311,7 +311,7 @@ class WP_Embed { * @return string Potentially modified $content. */ public function autoembed( $content ) { - return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content ); + return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); } /** @@ -323,10 +323,10 @@ class WP_Embed { public function autoembed_callback( $match ) { $oldval = $this->linkifunknown; $this->linkifunknown = false; - $return = $this->shortcode( array(), $match[1] ); + $return = $this->shortcode( array(), $match[2] ); $this->linkifunknown = $oldval; - return "\n$return\n"; + return $match[1] . $return . $match[3]; } /** diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 4523e4ee3b..f0960d7536 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -132,6 +132,40 @@ CAP; $this->assertContains( 'https://www.youtube.com/embed/zHjMoNQN7s0?feature=oembed', $out ); } + /** + * @ticket 23776 + */ + function test_autoembed_empty() { + global $wp_embed; + + $content = ''; + + $result = $wp_embed->autoembed( $content ); + $this->assertEquals( $content, $result ); + } + + /** + * @ticket 23776 + */ + function test_autoembed_no_paragraphs_around_urls() { + global $wp_embed; + + $content = <<http://some.link/ +http://some.other.link/ +EOF; + + $result = $wp_embed->autoembed( $content ); + $this->assertEquals( $content, $result ); + } + function test_wp_prepare_attachment_for_js() { // Attachment without media $id = wp_insert_attachment(array(