wppaste
WordPress

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
Retrieves the oEmbed response data for a given post.

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

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
12–82

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 85.

Plugin surface
2 hooks

Third-party callbacks on 'oembed_min_max_width', 'oembed_response_data' run inside this call, and their cost is not bounded by anything here.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_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.

WhenInstructionsCalls it makes
always12get_post(), absint()
!is_post_publicly_viewable()16get_post(), absint(), is_post_publicly_viewable()
is_post_publicly_viewable() && !is_post_embeddable()20get_post(), absint(), is_post_publicly_viewable(), is_post_embeddable()
is_post_publicly_viewable() && is_post_embeddable()72get_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()82get_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

PHPCompiledExecutedBranchesNotes
8.6-dev8512–824
8.58512–824
8.48512–82410 fewer instructions than PHP 8.3
8.39512–924
8.29512–924
8.19512–924
7.49512–924

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:

  1. apply_filters( oembed_min_max_width )filterline 589 (+28 into the body)

    Filters the allowed minimum and maximum widths for the oEmbed response.

  2. apply_filters( oembed_response_data )filterline 627 (+66 into the body)

    Filters the oEmbed response data.

Uses · 10

Used by · 2

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.8.0
Output was adjusted to only embed if the post type supports it.from the docblock
4.4.0
Introduced.from the docblock

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.