WP_oEmbed::fetch( string $provider, string $url, string|array $args = '' ): object|false
- Since
- 2.9.0
- Source
wp-includes/class-wp-oembed.php:534
Compatibility
- WordPress
- since 2.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.
Parameters
$providerstring- The URL to the oEmbed provider.
$urlstring- The URL to the content that is desired to be embedded.
$argsstring|arrayoptional- Additional arguments for retrieving embed HTML.
See wp_oembed_get() for accepted arguments. Default empty.Default:''
Return value
object|false- The result in the form of an object on success, false on failure.
Performance profile
How much work a call to WP_oEmbed::fetch() 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
- Light
- Scaling
- Scales with input
- Instructions
- 52–73
- Plugin surface
- 1 hook
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 76.
Third-party callbacks on 'oembed_fetch_url' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_oEmbed::fetch() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 52–53 | wp_embed_defaults(), wp_parse_args(), add_query_arg(), add_query_arg(), urlencode(), add_query_arg(), add_query_arg(), apply_filters() |
!is_wp_error() | 64 | wp_embed_defaults(), wp_parse_args(), add_query_arg(), add_query_arg(), urlencode(), add_query_arg(), add_query_arg(), apply_filters(), ->_fetch_with_format(), is_wp_error() |
!is_wp_error() | 68–69 | wp_embed_defaults(), wp_parse_args(), add_query_arg(), add_query_arg(), urlencode(), add_query_arg(), add_query_arg(), apply_filters(), ->_fetch_with_format(), is_wp_error(), is_wp_error() |
is_wp_error() | 68 | wp_embed_defaults(), wp_parse_args(), add_query_arg(), add_query_arg(), urlencode(), add_query_arg(), add_query_arg(), apply_filters(), ->_fetch_with_format(), is_wp_error(), ->get_error_code() |
is_wp_error() | 72–73 | wp_embed_defaults(), wp_parse_args(), add_query_arg(), add_query_arg(), urlencode(), add_query_arg(), add_query_arg(), apply_filters(), ->_fetch_with_format(), is_wp_error(), ->get_error_code(), is_wp_error() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 76 instructions, 52–73 executed per call, 6 branches. The work does not change between versions.
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::fetch() runs, in this order:
- apply_filters( oembed_fetch_url )filterline 553 (+19 into the body)
Filters the oEmbed URL to be fetched.
Uses · 6
- wp_parse_args()Merges user defined arguments into defaults array.
- wp_embed_defaults()Creates default array of embed parameters.
- add_query_arg()Retrieves a modified URL query string.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- WP_oEmbed::_fetch_with_format()Fetches result from an oEmbed provider for a specific format and complete provider URL
Used by · 1
- WP_oEmbed::get_data()Takes a URL and attempts to return the oEmbed data.
Source code
public function fetch( $provider, $url, $args = '' ) { $args = wp_parse_args( $args, wp_embed_defaults( $url ) ); $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider ); $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider ); $provider = add_query_arg( 'url', urlencode( $url ), $provider ); $provider = add_query_arg( 'dnt', 1, $provider ); /** * Filters the oEmbed URL to be fetched. * * @since 2.9.0 * @since 4.9.0 The `dnt` (Do Not Track) query parameter was added to all oEmbed provider URLs. * * @param string $provider URL of the oEmbed provider. * @param string $url URL of the content to be embedded. * @param array $args Optional. Additional arguments for retrieving embed HTML. * See wp_oembed_get() for accepted arguments. Default empty. */ $provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args ); foreach ( array( 'json', 'xml' ) as $format ) { $result = $this->_fetch_with_format( $provider, $format ); if ( is_wp_error( $result ) && 'not-implemented' === $result->get_error_code() ) { continue; } return ( $result && ! is_wp_error( $result ) ) ? $result : false; } return false; }Changelog
Introduced in 2.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-wp-oembed.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.