wppaste
WordPress

WP_oEmbed::fetch( string $provider, string $url, string|array $args = '' ): object|false

Since
2.9.0
Source
wp-includes/class-wp-oembed.php:532
Connects to an oEmbed provider and returns the result.

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
52–73

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

Plugin surface
1 hook

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

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
always52–53wp_embed_defaults(), wp_parse_args(), add_query_arg(), add_query_arg(), urlencode(), add_query_arg(), add_query_arg(), apply_filters()
!is_wp_error()64wp_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–69wp_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()68wp_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–73wp_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:

  1. apply_filters( oembed_fetch_url )filterline 551 (+19 into the body)

    Filters the oEmbed URL to be fetched.

Uses · 6

Used by · 1

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.

  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.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 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.