Embeds: Fix parsing of post embeds in wp_filter_oembed_result() by appending wp-embed script instead of prepending it in get_post_embed_html().

Due to the way that the `blockquote` and `iframe` are being parsed with a regular expression in `wp_filter_oembed_result()`, if there is any content at all before the `blockquote` start tag then it will fail to be included in the first matching group. By appending the `wp-embed` script instead of prepending it in `get_post_embed_html()`, then the parsing issue is avoided.

Also use non-greedy match `wp_maybe_enqueue_oembed_host_js()`.

Amends [52132].
Fixes #44632.


git-svn-id: https://develop.svn.wordpress.org/trunk@52153 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2021-11-13 07:26:52 +00:00
parent 1e6bede076
commit 9aa70c8ebf
2 changed files with 14 additions and 7 deletions

View File

@@ -300,7 +300,9 @@ class Tests_Embed_Template extends WP_UnitTestCase {
$actual = get_post_embed_html( 200, 200, $post_id );
$actual = preg_replace( '/secret=("?)\w+\1/', 'secret=__SECRET__', $actual );
$this->assertStringEndsWith( $expected, $actual );
$this->assertStringStartsWith( '<blockquote class="wp-embedded-content" data-secret=__SECRET__>', $actual );
$this->assertStringContainsString( $expected, $actual );
$this->assertStringEndsWith( '</script>', trim( $actual ) );
}
/** @covers ::wp_oembed_add_host_js() */