wppaste
WordPress

WP_oEmbed::get_html( string $url, string|array $args = '' ): string|false

Since
2.9.0
Source
wp-includes/class-wp-oembed.php:390
The do-it-all function that takes a URL and attempts to return the HTML.

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

$urlstring
The URL to the content that should be attempted to be embedded.
$argsstring|arrayoptional
Additional arguments for retrieving embed HTML.
See wp_oembed_get() for accepted arguments. Default empty.Default: ''

Return value

string|false
The UNSANITIZED (and potentially unsafe) HTML that should be used to embed on success, false on failure.

Performance profile

How much work a call to WP_oEmbed::get_html() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
12–29

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

Plugin surface
2 hooks

Third-party callbacks on 'pre_oembed_result', 'oembed_result' 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

What one call costs · 3 distinct outcomes

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

WhenInstructionsCalls it makes
$pre !== null12apply_filters()
$pre === null && $data === false19apply_filters(), ->get_data()
$pre === null && $data !== false29apply_filters(), ->get_data(), ->data2html(), apply_filters()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 31 instructions, 12–29 executed per call, 2 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 · 2

2 hooks fire while WP_oEmbed::get_html() runs, in this order:

  1. apply_filters( pre_oembed_result )filterline 408 (+18 into the body)

    Filters the oEmbed result before any HTTP requests are made.

  2. apply_filters( oembed_result )filterline 430 (+40 into the body)

    Filters the HTML returned by the oEmbed provider.

Uses · 3

Source code

	public function get_html( $url, $args = '' ) {		/**		 * Filters the oEmbed result before any HTTP requests are made.		 *		 * This allows one to short-circuit the default logic, perhaps by		 * replacing it with a routine that is more optimal for your setup.		 *		 * Returning a non-null value from the filter will effectively short-circuit retrieval		 * and return the passed value instead.		 *		 * @since 4.5.3		 *		 * @param null|string  $result The UNSANITIZED (and potentially unsafe) HTML that should be used to embed.		 *                             Default null to continue retrieving the result.		 * @param string       $url    The URL to the content that should be attempted to be embedded.		 * @param string|array $args   Optional. Additional arguments for retrieving embed HTML.		 *                             See wp_oembed_get() for accepted arguments. Default empty.		 */		$pre = apply_filters( 'pre_oembed_result', null, $url, $args ); 		if ( null !== $pre ) {			return $pre;		} 		$data = $this->get_data( $url, $args ); 		if ( false === $data ) {			return false;		} 		/**		 * Filters the HTML returned by the oEmbed provider.		 *		 * @since 2.9.0		 *		 * @param string|false $data The returned oEmbed HTML (false if unsafe).		 * @param string       $url  URL of the content to be embedded.		 * @param string|array $args Optional. Additional arguments for retrieving embed HTML.		 *                           See wp_oembed_get() for accepted arguments. Default empty.		 */		return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args );	}

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.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.