WP_oEmbed::get_providerpublicWP 4.0.0

Takes a URL and returns the corresponding oEmbed provider's URL, if there is one.

Method of the class: WP_oEmbed{}

No Hooks.

Returns

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

Usage

$WP_oEmbed = new WP_oEmbed();
$WP_oEmbed->get_provider( $url, $args );
$url(string) (required)
The URL to the content.
$args(string|array)

Additional provider arguments.

Default: ''

  • discover(true|false)
    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.
    Default: true

Notes

See: WP_oEmbed::discover()

Changelog

Since 4.0.0 Introduced.

WP_oEmbed::get_provider() code WP 7.1

public function get_provider( $url, $args = '' ) {
	$args = wp_parse_args( $args );

	$provider = false;

	if ( ! isset( $args['discover'] ) ) {
		$args['discover'] = true;
	}

	foreach ( $this->providers as $match_mask => $data ) {
		$provider_data = $this->sanitize_provider( $match_mask, $data );
		if ( null === $provider_data ) {
			continue;
		}
		$match_mask = $provider_data['match_mask'];

		// Turn the asterisk-type provider URLs into regex.
		if ( ! $provider_data['is_regex'] ) {
			$match_mask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $match_mask ), '#' ) ) . '#i';
			$match_mask = (string) preg_replace( '|^#http\\\://|', '#https?\://', $match_mask );
		}

		if ( preg_match( $match_mask, $url ) ) {
			$provider = str_replace( '{format}', 'json', $provider_data['endpoint'] ); // JSON is easier to deal with than XML.
			break;
		}
	}

	if ( ! $provider && $args['discover'] ) {
		$provider = $this->discover( $url );
	}

	return $provider;
}