From 26b1d5f927c8bad587af2f6ff27001b0c0b26f4f Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 2 Jun 2016 21:24:30 +0000 Subject: [PATCH] Auto-embedding: - We already match URLs on their own line, add another regex to match URLs in their own paragraphs. - Always exclude the `\s<>"` characters when matching. - Add more unit tests. Props iseulde, azaozz. Fixes #25387. Built from https://develop.svn.wordpress.org/trunk@37627 git-svn-id: http://core.svn.wordpress.org/trunk@37595 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-embed.php | 8 ++++++-- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-embed.php b/wp-includes/class-wp-embed.php index 5f22e92a5c..888dcd33da 100644 --- a/wp-includes/class-wp-embed.php +++ b/wp-includes/class-wp-embed.php @@ -334,8 +334,12 @@ class WP_Embed { // 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. - $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); + if ( preg_match( '#(^|\s|>)https?://#i', $content ) ) { + // Find URLs on their own line. + $content = preg_replace_callback( '|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); + // Find URLs in their own paragraph. + $content = preg_replace_callback( '|(]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', array( $this, 'autoembed_callback' ), $content ); + } // Put the line breaks back. return str_replace( '', "\n", $content ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 391d4949e2..388123bdd9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37626'; +$wp_version = '4.6-alpha-37627'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.