wp_filter_pre_oembed_result
Filters the oEmbed result before any HTTP requests are made.
Description
If the URL belongs to the current site, the result is fetched directly instead of going through the oEmbed discovery process.
Returns (null|string)
The UNSANITIZED (and potentially unsafe) HTML that should be used to embed. Null if the URL does not belong to the current site.
Parameters (3)
- 0. $result (null|string)
- The UNSANITIZED (and potentially unsafe) HTML that should be used to embed. Default null.
- 1. $url (string)
- The URL that should be inspected for discovery tags.
- 2. $args (array)
- OEmbed remote get arguments.
Usage
if ( !function_exists( 'wp_filter_pre_oembed_result' ) ) { require_once ABSPATH . WPINC . '/embed.php'; } // The UNSANITIZED (and potentially unsafe) HTML that should be used to embed. Default null. $result = null; // The URL that should be inspected for discovery `` tags. $url = ''; // oEmbed remote get arguments. $args = array(); // NOTICE! Understand what this does before running. $result = wp_filter_pre_oembed_result($result, $url, $args);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/embed.php
- function wp_filter_pre_oembed_result( $result, $url, $args ) {
- $post_id = url_to_postid( $url );
- /** This filter is documented in wp-includes/class-wp-oembed-controller.php */
- $post_id = apply_filters( 'oembed_request_post_id', $post_id, $url );
- if ( ! $post_id ) {
- return $result;
- }
- $width = isset( $args['width'] ) ? $args['width'] : 0;
- $data = get_oembed_response_data( $post_id, $width );
- $data = _wp_oembed_get_object()->data2html( (object) $data, $url );
- if ( ! $data ) {
- return $result;
- }
- return $data;
- }