WP_oEmbed::get_provider()publicWP 4.0.0

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

Метод класса: WP_oEmbed{}

Хуков нет.

Возвращает

Строку|false. The oEmbed provider URL on success, false on failure.

Использование

$WP_oEmbed = new WP_oEmbed();
$WP_oEmbed->get_provider( $url, $args );
$url(строка) (обязательный)
The URL to the content.
$args(строка|массив)

Additional provider arguments.

По умолчанию: ''

  • 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.
    По умолчанию: true

Заметки

Список изменений

С версии 4.0.0 Введена.

Код WP_oEmbed::get_provider() WP 6.4.3

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