Changeset 61119
- Timestamp:
- 11/04/2025 12:45:02 AM (4 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/wp-includes/default-filters.php (modified) (1 diff)
-
src/wp-includes/embed.php (modified) (1 diff)
-
tests/phpunit/tests/oembed/discovery.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r61111 r61119 705 705 add_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 ); 706 706 707 add_action( 'wp_head', 'wp_oembed_add_discovery_links' ); 707 add_action( 'wp_head', 'wp_oembed_add_discovery_links', 4 ); // Printed after feed_links() and feed_links_extra(). 708 add_action( 'wp_head', 'wp_oembed_add_discovery_links' ); // Unhooked the first time that wp_oembed_add_discovery_links() runs for back-compat. 708 709 add_action( 'wp_head', 'wp_oembed_add_host_js' ); // Back-compat for sites disabling oEmbed host JS by removing action. 709 710 add_filter( 'embed_oembed_html', 'wp_maybe_enqueue_oembed_host_js' ); -
trunk/src/wp-includes/embed.php
r60948 r61119 333 333 * @since 4.4.0 334 334 * @since 6.8.0 Output was adjusted to only embed if the post supports it. 335 * @since 6.9.0 Now runs first at `wp_head` priority 4, with a fallback to priority 10. This helps ensure the discovery links appear within the first 150KB. 335 336 */ 336 337 function wp_oembed_add_discovery_links() { 338 if ( doing_action( 'wp_head' ) ) { 339 // For back-compat, short-circuit if a plugin has removed the action at the original priority. 340 if ( ! has_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ) ) { 341 return; 342 } 343 344 // Prevent running again at the original priority. 345 remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); 346 } 347 337 348 $output = ''; 338 349 -
trunk/tests/phpunit/tests/oembed/discovery.php
r59700 r61119 50 50 51 51 $this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) ); 52 53 add_filter( 'oembed_discovery_links', '__return_empty_string' ); 54 $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ), 'Expected filtering oembed_discovery_links to empty string to result in no wp_oembed_add_discovery_links() output.' ); 52 55 } 53 56 … … 101 104 $this->assertFalse( get_oembed_response_data( $post, 100 ) ); 102 105 } 106 107 /** 108 * @ticket 64178 109 * @covers ::wp_oembed_add_discovery_links 110 */ 111 public function test_wp_oembed_add_discovery_links_back_compat() { 112 $action = 'wp_head'; 113 $old_priority = 10; 114 $new_priority = 4; 115 $callback = 'wp_oembed_add_discovery_links'; 116 117 $this->assertTrue( has_action( $action, $callback, $old_priority ), 'Expected wp_oembed_add_discovery_links() to be hooked at wp_head with old priority.' ); 118 $this->assertTrue( has_action( $action, $callback, $new_priority ), 'Expected wp_oembed_add_discovery_links() to be hooked at wp_head with new priority.' ); 119 120 // Remove all wp_head actions and re-add just the one being tested. 121 remove_all_actions( $action ); 122 add_action( $action, $callback, $old_priority ); 123 add_action( $action, $callback, $new_priority ); 124 125 $post_id = self::factory()->post->create(); 126 $this->go_to( get_permalink( $post_id ) ); 127 $this->assertQueryTrue( 'is_single', 'is_singular' ); 128 129 $mock_action = new MockAction(); 130 add_filter( 'oembed_discovery_links', array( $mock_action, 'filter' ) ); 131 132 $wp_head_output = get_echo( 'wp_head' ); 133 $this->assertSame( 1, $mock_action->get_call_count() ); 134 135 $expected = '<link rel="alternate" title="oEmbed (JSON)" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n"; 136 $expected .= '<link rel="alternate" title="oEmbed (XML)" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n"; 137 138 $this->assertSame( $expected, $wp_head_output, 'Expected wp_head output to be the same as the wp_oembed_add_discovery_links() output.' ); 139 $this->assertSame( $expected, get_echo( $callback ), 'Expected wp_oembed_add_discovery_links() output to be the same as the wp_head output when called outside of wp_head.' ); 140 } 103 141 }
Note: See TracChangeset
for help on using the changeset viewer.