diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php
index 42fff8fe7e..c44e9d7101 100644
a
|
b
|
function wp_oembed_add_discovery_links() { |
359 | 359 | * @since 4.4.0 |
360 | 360 | */ |
361 | 361 | function wp_oembed_add_host_js() { |
362 | | wp_enqueue_script( 'wp-embed' ); |
| 362 | add_filter( 'embed_oembed_html', 'wp_prepend_oembed_host_inline_script_tag' ); |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Inline oEmbed host script before post embeds. |
| 367 | * |
| 368 | * The wp-embed script is printed before to ensure that the `message` event listener is added before the iframe'd post |
| 369 | * embed is able to be loaded. Additionally, it is inlined to prevent the external script from blocking the page from |
| 370 | * continuing to render. The wp-embed script is printed before each post embed and not just before the first instance |
| 371 | * because it is possible that the filters may apply on content that is not initially printed. |
| 372 | * |
| 373 | * @since 5.8.2 |
| 374 | * |
| 375 | * @param string $html Embed markup. |
| 376 | * @return string Embed markup with oEmbed host JS prepended. |
| 377 | */ |
| 378 | function wp_prepend_oembed_host_inline_script_tag( $html ) { |
| 379 | if ( ! preg_match( '/<blockquote\s[^>]*wp-embedded-content/', $html ) ) { |
| 380 | return $html; |
| 381 | } |
| 382 | |
| 383 | $dependency = wp_scripts()->query( 'wp-embed' ); |
| 384 | if ( ! $dependency ) { |
| 385 | return $html; |
| 386 | } |
| 387 | |
| 388 | // @todo What if a plugin override the src to be somewhere else? |
| 389 | $path = ABSPATH . ltrim( $dependency->src, '/' ); |
| 390 | if ( ! file_exists( $path ) ) { |
| 391 | return $html; |
| 392 | } |
| 393 | |
| 394 | $script = wp_get_inline_script_tag( file_get_contents( $path ) ); |
| 395 | |
| 396 | return $script . $html; |
363 | 397 | } |
364 | 398 | |
365 | 399 | /** |