On this page
WP_oEmbed::get_html( string $url, string|array $args = '' ): string|false
The do-it-all function that takes a URL and attempts to return the HTML.
Description
See also
Parameters
$urlstring Required-
The URL to the content that should be attempted to be embedded.
$argsstring|array Optional-
Additional arguments for retrieving embed HTML.
See wp_oembed_get() for accepted arguments.More Arguments from wp_oembed_get( ... $args )
Additional arguments for retrieving embed HTML.
widthint|stringOptional. Themaxwidthvalue passed to the provider URL.heightint|stringOptional. Themaxheightvalue passed to the provider URL.discoverboolOptional. 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:
''
Return
string|false The UNSANITIZED (and potentially unsafe) HTML that should be used to embed on success, false on failure.
Source
File: wp-includes/class-wp-oembed.php. View all references
public function get_html( $url, $args = '' ) {
/**
* Filters the oEmbed result before any HTTP requests are made.
*
* This allows one to short-circuit the default logic, perhaps by
* replacing it with a routine that is more optimal for your setup.
*
* Returning a non-null value from the filter will effectively short-circuit retrieval
* and return the passed value instead.
*
* @since 4.5.3
*
* @param null|string $result The UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
* Default null to continue retrieving the result.
* @param string $url The URL to the content that should be attempted to be embedded.
* @param string|array $args Optional. Additional arguments for retrieving embed HTML.
* See wp_oembed_get() for accepted arguments. Default empty.
*/
$pre = apply_filters( 'pre_oembed_result', null, $url, $args );
if ( null !== $pre ) {
return $pre;
}
$data = $this->get_data( $url, $args );
if ( false === $data ) {
return false;
}
/**
* Filters the HTML returned by the oEmbed provider.
*
* @since 2.9.0
*
* @param string|false $data The returned oEmbed HTML (false if unsafe).
* @param string $url URL of the content to be embedded.
* @param string|array $args Optional. Additional arguments for retrieving embed HTML.
* See wp_oembed_get() for accepted arguments. Default empty.
*/
return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args );
}
Hooks
- apply_filters( 'oembed_result',
string|false $data ,string $url ,string|array $args ) -
Filters the HTML returned by the oEmbed provider.
- apply_filters( 'pre_oembed_result',
null|string $result ,string $url ,string|array $args ) -
Filters the oEmbed result before any HTTP requests are made.
Related
Uses
| Uses | Description |
|---|---|
| WP_oEmbed::get_data() wp-includes/class-wp-oembed.php | Takes a URL and attempts to return the oEmbed data. |
| WP_oEmbed::data2html() wp-includes/class-wp-oembed.php | Converts a data object from WP_oEmbed::fetch() and returns the HTML. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Changelog
| Version | Description |
|---|---|
| 2.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_oembed/get_html