wppaste
WordPress

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

Since
4.0.0
Source
wp-includes/class-wp-oembed.php:266
Takes a URL and returns the corresponding oEmbed provider's URL, if there is one.

Compatibility

WordPress
since 4.0.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.
$argsstring|arrayoptional
Additional provider arguments. Default empty.Default: ''
  • $discoverbooldefault: true

    Optional. Determines whether to attempt to discover link tags at the given URL for an oEmbed provider when the provider URL is not found in the built-in providers list.

Return value

string|false
The oEmbed provider URL on success, false on failure.

Performance profile

How much work a call to WP_oEmbed::get_provider() 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
14–49

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

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

What one call costs · 4 distinct outcomes

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

WhenInstructionsCalls it makes
always14–31wp_parse_args()
$args20–35wp_parse_args(), ->discover()
$matchmask41–45wp_parse_args(), preg_quote()
$matchmask && $args47–49wp_parse_args(), preg_quote(), ->discover()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev4914–497
8.54914–497
8.44914–49716 fewer instructions than PHP 8.3
8.36514–657
8.26514–657
8.16514–657
7.46514–657

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.

Uses · 2

Used by · 1

Source code

	public function get_provider( $url, $args = '' ) {		$args = wp_parse_args( $args ); 		$provider = false; 		if ( ! isset( $args['discover'] ) ) {			$args['discover'] = true;		} 		foreach ( $this->providers as $matchmask => $data ) {			list( $providerurl, $regex ) = $data; 			// Turn the asterisk-type provider URLs into regex.			if ( ! $regex ) {				$matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';				$matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask );			} 			if ( preg_match( $matchmask, $url ) ) {				$provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML.				break;			}		} 		if ( ! $provider && $args['discover'] ) {			$provider = $this->discover( $url );		} 		return $provider;	}

Changelog

Introduced in 4.0.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.9.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.