get_oembed_response_data( WP_Post|int $post, int $width ): array|false
- Since
- 4.4.0, 6.8.0
- Source
wp-includes/embed.php:561
Compatibility
- WordPress
- since 6.8.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$postWP_Post|int- Post ID or post object.
$widthint- The requested width.
Return value
array|false- Response data on success, false if post doesn't exist, is not publicly viewable or post type is not embeddable.
Performance profile
How much work a call to get_oembed_response_data() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 12–82
- Plugin surface
- 2 hooks
- Called by
- 2
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 85.
Third-party callbacks on 'oembed_min_max_width', 'oembed_response_data' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()one call below get_oembed_response_data()
Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_oembed_response_data() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12 | get_post(), absint() |
!is_post_publicly_viewable() | 16 | get_post(), absint(), is_post_publicly_viewable() |
is_post_publicly_viewable() && !is_post_embeddable() | 20 | get_post(), absint(), is_post_publicly_viewable(), is_post_embeddable() |
is_post_publicly_viewable() && is_post_embeddable() | 72 | get_post(), absint(), is_post_publicly_viewable(), is_post_embeddable(), apply_filters(), ceil(), get_bloginfo(), get_home_url(), get_bloginfo(), get_home_url(), get_the_title(), get_userdata(), apply_filters() |
is_post_publicly_viewable() && is_post_embeddable() | 82 | get_post(), absint(), is_post_publicly_viewable(), is_post_embeddable(), apply_filters(), ceil(), get_bloginfo(), get_home_url(), get_bloginfo(), get_home_url(), get_the_title(), get_userdata(), get_author_posts_url(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 85 | 12–82 | 4 | |
| 8.5 | 85 | 12–82 | 4 | |
| 8.4 | 85 | 12–82 | 4 | 10 fewer instructions than PHP 8.3 |
| 8.3 | 95 | 12–92 | 4 | |
| 8.2 | 95 | 12–92 | 4 | |
| 8.1 | 95 | 12–92 | 4 | |
| 7.4 | 95 | 12–92 | 4 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while get_oembed_response_data() runs, in this order:
- apply_filters( oembed_min_max_width )filterline 589 (+28 into the body)
Filters the allowed minimum and maximum widths for the oEmbed response.
- apply_filters( oembed_response_data )filterline 627 (+66 into the body)
Filters the oEmbed response data.
Uses · 10
- get_post()Retrieves post data given a post ID or post object.
- absint()Converts a value to non-negative integer.
- is_post_publicly_viewable()Determines whether a post is publicly viewable.
- is_post_embeddable()Determines whether a post is embeddable.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_bloginfo()Retrieves information about the current site.
- get_home_url()Retrieves the URL for a given site where the front end is accessible.
- get_the_title()Retrieves the post title.
- get_userdata()Retrieves user info by user ID.
- get_author_posts_url()Retrieves the URL to the author page for the user with the ID provided.
Used by · 2
- WP_oEmbed_Controller::get_item()Callback for the embed API endpoint.
- get_oembed_response_data_for_url()Retrieves the oEmbed response data for a given URL.
Source code
function get_oembed_response_data( $post, $width ) { $post = get_post( $post ); $width = absint( $width ); if ( ! $post ) { return false; } if ( ! is_post_publicly_viewable( $post ) ) { return false; } if ( ! is_post_embeddable( $post ) ) { return false; } /** * Filters the allowed minimum and maximum widths for the oEmbed response. * * @since 4.4.0 * * @param array $min_max_width { * Minimum and maximum widths for the oEmbed response. * * @type int $min Minimum width. Default 200. * @type int $max Maximum width. Default 600. * } */ $min_max_width = apply_filters( 'oembed_min_max_width', array( 'min' => 200, 'max' => 600, ) ); $width = min( max( $min_max_width['min'], $width ), $min_max_width['max'] ); $height = max( (int) ceil( $width / 16 * 9 ), 200 ); $data = array( 'version' => '1.0', 'provider_name' => get_bloginfo( 'name' ), 'provider_url' => get_home_url(), 'author_name' => get_bloginfo( 'name' ), 'author_url' => get_home_url(), 'title' => get_the_title( $post ), 'type' => 'link', ); $author = get_userdata( $post->post_author ); if ( $author ) { $data['author_name'] = $author->display_name; $data['author_url'] = get_author_posts_url( $author->ID ); } /** * Filters the oEmbed response data. * * @since 4.4.0 * * @param array $data The response data. * @param WP_Post $post The post object. * @param int $width The requested width. * @param int $height The calculated height. */ return apply_filters( 'oembed_response_data', $data, $post, $width, $height );}Changelog
Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/embed.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.