get_oembed_response_data

Retrieves the oEmbed response data for a given post.

Description

(array|false) get_oembed_response_data( (WP_Post|int) $post, (int) $width ); 

Returns (array|false)

Response data on success, false if post doesn't exist.

Parameters (2)

0. $post (WP_Post|int)
Post object or ID.
1. $width (int)
The requested width.

Usage

  1. if ( !function_exists( 'get_oembed_response_data' ) ) { 
  2. require_once ABSPATH . WPINC . '/embed.php'; 
  3.  
  4. // Post object or ID. 
  5. $post = null; 
  6.  
  7. // The requested width. 
  8. $width = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_oembed_response_data($post, $width); 
  12.  

Defined (1)

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

/wp-includes/embed.php  
  1. function get_oembed_response_data( $post, $width ) { 
  2. $post = get_post( $post ); 
  3. $width = absint( $width ); 
  4.  
  5. if ( ! $post ) { 
  6. return false; 
  7.  
  8. if ( 'publish' !== get_post_status( $post ) ) { 
  9. return false; 
  10.  
  11. /** 
  12. * Filters the allowed minimum and maximum widths for the oEmbed response. 
  13. * @since 4.4.0 
  14. * @param array $min_max_width { 
  15. * Minimum and maximum widths for the oEmbed response. 
  16. * @type int $min Minimum width. Default 200. 
  17. * @type int $max Maximum width. Default 600. 
  18. * } 
  19. */ 
  20. $min_max_width = apply_filters( 'oembed_min_max_width', array( 
  21. 'min' => 200,  
  22. 'max' => 600 
  23. ) ); 
  24.  
  25. $width = min( max( $min_max_width['min'], $width ), $min_max_width['max'] ); 
  26. $height = max( ceil( $width / 16 * 9 ), 200 ); 
  27.  
  28. $data = array( 
  29. 'version' => '1.0',  
  30. 'provider_name' => get_bloginfo( 'name' ),  
  31. 'provider_url' => get_home_url(),  
  32. 'author_name' => get_bloginfo( 'name' ),  
  33. 'author_url' => get_home_url(),  
  34. 'title' => $post->post_title,  
  35. 'type' => 'link',  
  36. ); 
  37.  
  38. $author = get_userdata( $post->post_author ); 
  39.  
  40. if ( $author ) { 
  41. $data['author_name'] = $author->display_name; 
  42. $data['author_url'] = get_author_posts_url( $author->ID ); 
  43.  
  44. /** 
  45. * Filters the oEmbed response data. 
  46. * @since 4.4.0 
  47. * @param array $data The response data. 
  48. * @param WP_Post $post The post object. 
  49. * @param int $width The requested width. 
  50. * @param int $height The calculated height. 
  51. */ 
  52. return apply_filters( 'oembed_response_data', $data, $post, $width, $height );