Class: WP_oEmbed

Core class used to implement oEmbed functionality.


Properties

Name Type(s) Default Value Summary
providers array A list of oEmbed providers.
early_providers array Static ⋅ A list of an early oEmbed providers.
compat_methods array A list of private/protected methods, used for backward compatibility.

Methods

WP_oEmbed:: __call( callable $name, array $arguments )

Exposes private/protected methods for backward compatibility. Since 4.0.0.

Arguments

Name Type(s) Default Value Description
$name callable

Method to call.

$arguments array

Arguments to pass when calling.

Returns

mixed | boolean

Return value of the callback, false otherwise.


WP_oEmbed:: __construct( )

Constructor. Since 2.9.0.


WP_oEmbed:: _add_provider_early( string $format, string $provider, boolean $regex = false )

Adds an oEmbed provider. Since 4.0.0.

The provider is added just-in-time when wp_oembed_add_provider() is called before the \'plugins_loaded' hook.

The just-in-time addition is for the benefit of the \'oembed_providers' filter.

Arguments

Name Type(s) Default Value Description
$format string

Format of URL that this provider can handle. You can use asterisks as wildcards.

$provider string

The URL to the oEmbed provider..

$regex boolean

Optional. Whether the $format parameter is in a regex format. Default false.


WP_oEmbed:: _fetch_with_format( string $provider_url_with_args, string $format )

Fetches result from an oEmbed provider for a specific format and complete provider URL Since 3.0.0.

Arguments

Name Type(s) Default Value Description
$provider_url_with_args string

URL to the provider with full arguments list (url, maxheight, etc.)

$format string

Format to use

Returns

false | object | WP_Error

False on failure, otherwise the result in the form of an object.


WP_oEmbed:: _parse_json( string $response_body )

Parses a json response body. Since 3.0.0.

Arguments

Name Type(s) Default Value Description
$response_body string

Returns

object | false


WP_oEmbed:: _parse_xml( string $response_body )

Parses an XML response body. Since 3.0.0.

Arguments

Name Type(s) Default Value Description
$response_body string

Returns

object | false


WP_oEmbed:: _parse_xml_body( string $response_body )

Serves as a helper function for parsing an XML response body. Since 3.6.0.

Arguments

Name Type(s) Default Value Description
$response_body string

Returns

\stdClass | false


WP_oEmbed:: _remove_provider_early( string $format )

Removes an oEmbed provider. Since 4.0.0.

The provider is removed just-in-time when wp_oembed_remove_provider() is called before the \'plugins_loaded' hook.

The just-in-time removal is for the benefit of the \'oembed_providers' filter.

Arguments

Name Type(s) Default Value Description
$format string

The format of URL that this provider can handle. You can use asterisks as wildcards.


WP_oEmbed:: _strip_newlines( string $html, object $data, string $url )

Strips any new lines from the HTML. Since 2.9.0. Since 3.0.0.

Arguments

Name Type(s) Default Value Description
$html string

Existing HTML.

$data object

Data object from WP_oEmbed::data2html()

$url string

The original URL passed to oEmbed.

Returns

string

Possibly modified $html


WP_oEmbed:: data2html( object $data, string $url )

Converts a data object from WP_oEmbed::fetch() and returns the HTML. Since 2.9.0.

Arguments

Name Type(s) Default Value Description
$data object

A data object result from an oEmbed provider.

$url string

The URL to the content that is desired to be embedded.

Returns

false | string

False on error, otherwise the HTML needed to embed.


WP_oEmbed:: discover( string $url )

Attempts to discover link tags at the given URL for an oEmbed provider. Since 2.9.0.

Arguments

Name Type(s) Default Value Description
$url string

The URL that should be inspected for discovery <link> tags.

Returns

false | string

False on failure, otherwise the oEmbed provider URL.


WP_oEmbed:: fetch( string $provider, string $url, array | string $args = '' )

Connects to a oEmbed provider and returns the result. Since 2.9.0.

Arguments

Name Type(s) Default Value Description
$provider string

The URL to the oEmbed provider.

$url string

The URL to the content that is desired to be embedded.

$args array | string

Optional. Arguments, usually passed from a shortcode. Default empty.

Returns

false | object

False on failure, otherwise the result in the form of an object.


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

Takes a URL and attempts to return the oEmbed data. Since 4.8.0.

Arguments

Name Type(s) Default Value Description
$url string

The URL to the content that should be attempted to be embedded.

$args array | string

Optional. Arguments, usually passed from a shortcode. Default empty.

Returns

false | object

False on failure, otherwise the result in the form of an object.


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

The do-it-all function that takes a URL and attempts to return the HTML. Since 2.9.0.

Arguments

Name Type(s) Default Value Description
$url string

The URL to the content that should be attempted to be embedded.

$args array | string

Optional. Arguments, usually passed from a shortcode. Default empty.

Returns

false | string

False on failure, otherwise the UNSANITIZED (and potentially unsafe) HTML that should be used to embed.


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

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

Arguments

Name Type(s) Default Value Description
$url string

The URL to the content.

$args string | array

Optional provider arguments.

Returns

false | string

False on failure, otherwise the oEmbed provider URL.


WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.