Changeset 52437
- Timestamp:
- 01/04/2022 03:22:40 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r52377 r52437 643 643 644 644 add_action( 'wp_head', 'wp_oembed_add_discovery_links' ); 645 add_action( 'wp_head', 'wp_oembed_add_host_js' ); 645 add_action( 'wp_head', 'wp_oembed_add_host_js' ); // Back-compat for sites disabling oEmbed host JS by removing action. 646 add_filter( 'embed_oembed_html', 'wp_maybe_enqueue_oembed_host_js' ); 646 647 647 648 add_action( 'embed_head', 'enqueue_embed_scripts', 1 ); -
trunk/src/wp-includes/embed.php
r52332 r52437 357 357 * Adds the necessary JavaScript to communicate with the embedded iframes. 358 358 * 359 * @since 4.4.0 360 */ 361 function wp_oembed_add_host_js() { 362 add_filter( 'embed_oembed_html', 'wp_maybe_enqueue_oembed_host_js' ); 363 } 359 * This function is no longer used directly. For back-compat it exists exclusively as a way to indicate that the oEmbed 360 * host JS _should_ be added. In `default-filters.php` there remains this code: 361 * 362 * add_action( 'wp_head', 'wp_oembed_add_host_js' ) 363 * 364 * Historically a site has been able to disable adding the oEmbed host script by doing: 365 * 366 * remove_action( 'wp_head', 'wp_oembed_add_host_js' ) 367 * 368 * In order to ensure that such code still works as expected, this function remains. There is now a `has_action()` check 369 * in `wp_maybe_enqueue_oembed_host_js()` to see if `wp_oembed_add_host_js()` has not been unhooked from running at the 370 * `wp_head` action. 371 * 372 * @since 4.4.0 373 * @deprecated 5.9.0 Use {@see wp_maybe_enqueue_oembed_host_js()} instead. 374 */ 375 function wp_oembed_add_host_js() {} 364 376 365 377 /** … … 375 387 */ 376 388 function wp_maybe_enqueue_oembed_host_js( $html ) { 377 if ( preg_match( '/<blockquote\s[^>]*?wp-embedded-content/', $html ) ) { 389 if ( 390 has_action( 'wp_head', 'wp_oembed_add_host_js' ) 391 && 392 preg_match( '/<blockquote\s[^>]*?wp-embedded-content/', $html ) 393 ) { 378 394 wp_enqueue_script( 'wp-embed' ); 379 395 } -
trunk/tests/phpunit/tests/oembed/template.php
r52153 r52437 310 310 remove_all_filters( 'embed_oembed_html' ); 311 311 312 // This function is now a no-op. 312 313 wp_oembed_add_host_js(); 313 314 314 $this->assert Equals( 10,has_filter( 'embed_oembed_html', 'wp_maybe_enqueue_oembed_host_js' ) );315 $this->assertFalse( has_filter( 'embed_oembed_html', 'wp_maybe_enqueue_oembed_host_js' ) ); 315 316 } 316 317 317 318 /** @covers ::wp_maybe_enqueue_oembed_host_js() */ 318 function test_wp_maybe_enqueue_oembed_host_js() {319 public function test_wp_maybe_enqueue_oembed_host_js() { 319 320 $scripts = wp_scripts(); 320 321 … … 329 330 wp_maybe_enqueue_oembed_host_js( $post_embed ); 330 331 $this->assertTrue( $scripts->query( 'wp-embed', 'enqueued' ) ); 332 } 333 334 /** @covers ::wp_maybe_enqueue_oembed_host_js() */ 335 public function test_wp_maybe_enqueue_oembed_host_js_without_wp_head_action() { 336 $scripts = wp_scripts(); 337 338 remove_action( 'wp_head', 'wp_oembed_add_host_js' ); 339 $this->assertFalse( $scripts->query( 'wp-embed', 'enqueued' ) ); 340 341 $post_embed = '<blockquote class="wp-embedded-content" data-secret="S24AQCJW9i"><a href="https://make.wordpress.org/core/2016/03/11/embeds-changes-in-wordpress-4-5/">Embeds Changes in WordPress 4.5</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);" title="“Embeds Changes in WordPress 4.5” — Make WordPress Core" src="https://make.wordpress.org/core/2016/03/11/embeds-changes-in-wordpress-4-5/embed/#?secret=S24AQCJW9i" data-secret="S24AQCJW9i" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>'; 342 343 wp_maybe_enqueue_oembed_host_js( $post_embed ); 344 $this->assertFalse( $scripts->query( 'wp-embed', 'enqueued' ) ); 331 345 } 332 346
Note: See TracChangeset
for help on using the changeset viewer.