wp_oembed_add_discovery_links()
- Since
- 4.4.0, 6.8.0, 6.9.0
- Source
wp-includes/embed.php:337
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
- Scaling
- Constant
- Instructions
- 11–64
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 65.
Third-party callbacks on 'oembed_discovery_links' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_post()one call below wp_oembed_add_discovery_links() - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
doing_action() && !has_action() | 11 | doing_action(), has_action() |
!doing_action() && !is_singular() | 14 | doing_action(), is_singular(), apply_filters() |
!doing_action() && is_singular() && !is_post_embeddable() | 17 | doing_action(), is_singular(), is_post_embeddable(), apply_filters() |
doing_action() && has_action() && !is_singular() | 24 | doing_action(), has_action(), remove_action(), is_singular(), apply_filters() |
doing_action() && has_action() && is_singular() && !is_post_embeddable() | 27 | doing_action(), has_action(), remove_action(), is_singular(), is_post_embeddable(), apply_filters() |
!doing_action() && is_singular() && is_post_embeddable() | 36 | doing_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() | 46 | doing_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() | 54 | doing_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() | 64 | doing_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 65 | 11–64 | 5 | |
| 8.5 | 65 | 11–64 | 5 | |
| 8.4 | 65 | 11–64 | 5 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 67 | 11–66 | 5 | |
| 8.2 | 67 | 11–66 | 5 | |
| 8.1 | 67 | 11–66 | 5 | |
| 7.4 | 67 | 11–66 | 5 |
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:
- 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.
Signature, return type and hooks compared across 5 parsed releases.
wp_head priority 4, with a fallback to priority 10. This helps ensure the discovery links appear within the first 150KB.from the docblockAbout 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.