wppaste
WordPress

wp_oembed_add_discovery_links()

Since
4.4.0, 6.8.0, 6.9.0
Source
wp-includes/embed.php:337
Adds oEmbed discovery links in the head element of the website.

Compatibility

WordPress
since 6.9.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Performance profile

How much work a call to wp_oembed_add_discovery_links() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
11–64

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 65.

Plugin surface
1 hook

Third-party callbacks on 'oembed_discovery_links' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • querycontent queryget_post()one call below wp_oembed_add_discovery_links()
  • optionoption read or writeget_option()one call below wp_oembed_add_discovery_links()

Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 9 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_oembed_add_discovery_links() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
doing_action() && !has_action()11doing_action(), has_action()
!doing_action() && !is_singular()14doing_action(), is_singular(), apply_filters()
!doing_action() && is_singular() && !is_post_embeddable()17doing_action(), is_singular(), is_post_embeddable(), apply_filters()
doing_action() && has_action() && !is_singular()24doing_action(), has_action(), remove_action(), is_singular(), apply_filters()
doing_action() && has_action() && is_singular() && !is_post_embeddable()27doing_action(), has_action(), remove_action(), is_singular(), is_post_embeddable(), apply_filters()
!doing_action() && is_singular() && is_post_embeddable()36doing_action(), is_singular(), is_post_embeddable(), _x(), get_permalink(), get_oembed_endpoint_url(), esc_url(), apply_filters()
doing_action() && has_action() && is_singular() && is_post_embeddable()46doing_action(), has_action(), remove_action(), is_singular(), is_post_embeddable(), _x(), get_permalink(), get_oembed_endpoint_url(), esc_url(), apply_filters()
!doing_action() && is_singular() && is_post_embeddable()54doing_action(), is_singular(), is_post_embeddable(), _x(), get_permalink(), get_oembed_endpoint_url(), esc_url(), _x(), get_permalink(), get_oembed_endpoint_url(), esc_url(), apply_filters()
doing_action() && has_action() && is_singular() && is_post_embeddable()64doing_action(), has_action(), remove_action(), is_singular(), is_post_embeddable(), _x(), get_permalink(), get_oembed_endpoint_url(), esc_url(), _x(), get_permalink(), get_oembed_endpoint_url(), esc_url(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6511–645
8.56511–645
8.46511–6452 fewer instructions than PHP 8.3
8.36711–665
8.26711–665
8.16711–665
7.46711–665

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while wp_oembed_add_discovery_links() runs, in this order:

  1. apply_filters( oembed_discovery_links )filterline 365 (+28 into the body)

    Filters the oEmbed discovery links HTML.

Uses · 10

  • doing_action()Returns whether or not an action hook is currently being processed.
  • has_action()Checks if any action has been registered for a hook.
  • remove_action()Removes a callback function from an action hook.
  • is_singular()Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types).
  • is_post_embeddable()Determines whether a post is embeddable.
  • _x()Retrieves translated string with gettext context.
  • esc_url()Checks and cleans a URL.
  • get_oembed_endpoint_url()Retrieves the oEmbed endpoint URL for a given permalink.
  • get_permalink()Retrieves the full permalink for the current post or post ID.
  • apply_filters()Calls the callback functions that have been added to a filter hook.

Source code

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() ) {		$output .= '<link rel="alternate" title="' . _x( 'oEmbed (JSON)', 'oEmbed resource link name' ) . '" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n"; 		if ( class_exists( 'SimpleXMLElement' ) ) {			$output .= '<link rel="alternate" title="' . _x( 'oEmbed (XML)', 'oEmbed resource link name' ) . '" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";		}	} 	/**	 * Filters the oEmbed discovery links HTML.	 *	 * @since 4.4.0	 *	 * @param string $output HTML of the discovery links.	 */	echo apply_filters( 'oembed_discovery_links', $output );}

Changelog

Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

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.from the docblock
6.8.0
Output was adjusted to only embed if the post supports it.from the docblock
4.4.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/embed.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.