Commit f7a4525383 for wordpress.org
commit f7a4525383cc10cf159da9ba4d09e539802f1324
Author: Weston Ruter <weston@xwp.co>
Date: Tue Nov 4 00:47:33 2025 +0000
Embeds: Add `wp_oembed_add_discovery_links()` to run earlier at `wp_head` priority 4.
This results in the oEmbed discovery links being printed before scripts and styles are printed. This helps ensure they appear within the first 150K bytes of the HTML response, which is required by `WP_oEmbed::discover()`. With increasing the `styles_inline_size_limit` from 20K to 40K in #63018, it becomes more probable that the oEmbed discovery links will be pushed out of range.
For backwards compatibility with themes and plugins that disable the oEmbed discovery links by unhooking `wp_oembed_add_discovery_links()` from running at `wp_head` priority 10 (even though the `oembed_discovery_links` filter is available to disable such links), this callback is added a second time to run earlier at priority 4. The first time the function runs, it checks to see if the callback is still hooked at priority 10. If not, the function short circuits. If it is still hooked at priority 10, however, the function then unhooks itself at priority 10 so that it won't run a second time later during the `wp_head` action, before proceeding with printing the discovery links. A similar back-compat approach was taken previously in [60910]. The back-compat checks are only performed if the function is invoked during the `wp_head` action, allowing the function to be called "idempotently" elsewhere.
Developed in https://github.com/WordPress/wordpress-develop/pull/10449
Follow-up to [61118], [61117].
Props westonruter, swissspidy.
See #64186, #63018.
Fixes #64178.
Built from https://develop.svn.wordpress.org/trunk@61119
git-svn-id: http://core.svn.wordpress.org/trunk@60455 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php
index 3c0e6d8b9f..229c9a7541 100644
--- a/wp-includes/default-filters.php
+++ b/wp-includes/default-filters.php
@@ -704,7 +704,8 @@ add_filter( 'media_send_to_editor', 'image_media_send_to_editor', 10, 3 );
add_action( 'rest_api_init', 'wp_oembed_register_route' );
add_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 );
-add_action( 'wp_head', 'wp_oembed_add_discovery_links' );
+add_action( 'wp_head', 'wp_oembed_add_discovery_links', 4 ); // Printed after feed_links() and feed_links_extra().
+add_action( 'wp_head', 'wp_oembed_add_discovery_links' ); // Unhooked the first time that wp_oembed_add_discovery_links() runs for back-compat.
add_action( 'wp_head', 'wp_oembed_add_host_js' ); // Back-compat for sites disabling oEmbed host JS by removing action.
add_filter( 'embed_oembed_html', 'wp_maybe_enqueue_oembed_host_js' );
diff --git a/wp-includes/embed.php b/wp-includes/embed.php
index c143ffe4a4..b7567024aa 100644
--- a/wp-includes/embed.php
+++ b/wp-includes/embed.php
@@ -332,8 +332,19 @@ function wp_oembed_register_route() {
*
* @since 4.4.0
* @since 6.8.0 Output was adjusted to only embed if the post supports it.
+ * @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.
*/
function wp_oembed_add_discovery_links() {
+ if ( doing_action( 'wp_head' ) ) {
+ // For back-compat, short-circuit if a plugin has removed the action at the original priority.
+ if ( ! has_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ) ) {
+ return;
+ }
+
+ // Prevent running again at the original priority.
+ remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
+ }
+
$output = '';
if ( is_singular() && is_post_embeddable() ) {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index df74f1453c..2920f66519 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '6.9-beta2-61118';
+$wp_version = '6.9-beta2-61119';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.