acf_field_oembed::wp_oembed_get
Attempts to fetch the HTML for the provided URL using oEmbed.
Method of the class: acf_field_oembed{}
No Hooks.
Returns
String|false. The embedded HTML on success, false on failure.
Usage
$acf_field_oembed = new acf_field_oembed(); $acf_field_oembed->wp_oembed_get( $url, $width, $height, $args );
- $url(string)
- The URL that should be embedded.
Default:'' - $width(int|string)
- Optional maxwidth value passed to the provider URL.
- $height(int|string)
- Optional maxheight value passed to the provider URL.
- $args(array)
- Additional arguments merged into the oEmbed request (e.g. 'discover').
Default:array()
Changelog
| Since 5.0.0 | Introduced. |
acf_field_oembed::wp_oembed_get() acf field oembed::wp oembed get code ACF 6.8.8
function wp_oembed_get( $url = '', $width = 0, $height = 0, $args = array() ) {
$embed = false;
$res = array_merge(
array(
'width' => $width,
'height' => $height,
),
$args
);
if ( function_exists( 'wp_oembed_get' ) ) {
$embed = wp_oembed_get( $url, $res );
}
// try shortcode
if ( ! $embed ) {
global $wp_embed;
/**
* Mirror our discover restriction onto WP_Embed::shortcode(),
* which otherwise forces discover=true via embed_oembed_discover.
*/
$force_discover_off = isset( $args['discover'] ) && false === $args['discover'];
if ( $force_discover_off ) {
add_filter( 'embed_oembed_discover', '__return_false', PHP_INT_MAX );
}
$embed = $wp_embed->shortcode( $res, $url );
if ( $force_discover_off ) {
remove_filter( 'embed_oembed_discover', '__return_false', PHP_INT_MAX );
}
}
return $embed;
}