Files
wordpress/wp-includes/embed.php
Weston Ruter f7a4525383 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
2025-11-04 00:47:33 +00:00

38 KiB