WP_oEmbed::get_provider( string $url, string|array $args = '' ): string|false
- Since
- 4.0.0
- Source
wp-includes/class-wp-oembed.php:266
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: trueOptional. 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
- Scaling
- Scales with input
- Instructions
- 14–49
- Plugin surface
- None
- 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 49.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14–31 | wp_parse_args() |
$args | 20–35 | wp_parse_args(), ->discover() |
$matchmask | 41–45 | wp_parse_args(), preg_quote() |
$matchmask && $args | 47–49 | wp_parse_args(), preg_quote(), ->discover() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 49 | 14–49 | 7 | |
| 8.5 | 49 | 14–49 | 7 | |
| 8.4 | 49 | 14–49 | 7 | 16 fewer instructions than PHP 8.3 |
| 8.3 | 65 | 14–65 | 7 | |
| 8.2 | 65 | 14–65 | 7 | |
| 8.1 | 65 | 14–65 | 7 | |
| 7.4 | 65 | 14–65 | 7 |
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
- wp_parse_args()Merges user defined arguments into defaults array.
- WP_oEmbed::discover()Attempts to discover link tags at the given URL for an oEmbed provider.
Used by · 1
- WP_oEmbed::get_data()Takes a URL and attempts to return the oEmbed data.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.