WP_oEmbed::get_provider() WordPress Method

The WP_oEmbed::get_provider() method is used to get the URL of the oEmbed provider for a given URL. This is useful for finding the oEmbed provider for a URL when the provider is not known.

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

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


Description

Top ↑

See also


Top ↑

Parameters

$url

(string)(Required)The URL to the content.

$args

(string|array)(Optional)Additional provider arguments.

  • 'discover'
    (bool) 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.

Default value: ''


Top ↑

Return

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


Top ↑

Source

File: wp-includes/class-wp-oembed.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.