wp_filter_pre_oembed_result

Filters the oEmbed result before any HTTP requests are made.

Description

(null|string) wp_filter_pre_oembed_result( (null|string) $result, (string) $url, (array) $args ); 

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

  1. if ( !function_exists( 'wp_filter_pre_oembed_result' ) ) { 
  2. require_once ABSPATH . WPINC . '/embed.php'; 
  3.  
  4. // The UNSANITIZED (and potentially unsafe) HTML that should be used to embed. Default null. 
  5. $result = null; 
  6.  
  7. // The URL that should be inspected for discovery `` tags. 
  8. $url = ''; 
  9.  
  10. // oEmbed remote get arguments. 
  11. $args = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_filter_pre_oembed_result($result, $url, $args); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/embed.php  
  1. function wp_filter_pre_oembed_result( $result, $url, $args ) { 
  2. $post_id = url_to_postid( $url ); 
  3.  
  4. /** This filter is documented in wp-includes/class-wp-oembed-controller.php */ 
  5. $post_id = apply_filters( 'oembed_request_post_id', $post_id, $url ); 
  6.  
  7. if ( ! $post_id ) { 
  8. return $result; 
  9.  
  10. $width = isset( $args['width'] ) ? $args['width'] : 0; 
  11.  
  12. $data = get_oembed_response_data( $post_id, $width ); 
  13. $data = _wp_oembed_get_object()->data2html( (object) $data, $url ); 
  14.  
  15. if ( ! $data ) { 
  16. return $result; 
  17.  
  18. return $data;