get_post_embed_html( int $width, int $height, int|WP_Post $post = null ): string|false
- Since
- 4.4.0
- Source
wp-includes/embed.php:479
Compatibility
- WordPress
- since 4.4.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
$widthint- The width for the response.
$heightint- The height for the response.
$postint|WP_Postoptional- Post ID or object. Default is global
$post.Default:null
Return value
string|false- Embed code on success, false if post doesn't exist.
Performance profile
How much work a call to get_post_embed_html() 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
- 9–99
- Plugin surface
- 1 hook
- Called by
- 2
Reads or writes the filesystem via file_get_contents().
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 100.
Third-party callbacks on 'embed_html' 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 - filesystemfilesystem access
file_get_contents()called directly - optionoption read or write
get_option()one call below get_post_embed_html()
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 · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_post_embed_html() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9 | get_post() |
| always | 99 | get_post(), get_post_embed_url(), wp_generate_password(), esc_attr(), get_permalink(), esc_url(), get_the_title(), sprintf(), esc_url(), absint(), absint(), __(), get_the_title(), get_bloginfo(), sprintf(), esc_attr(), esc_attr(), sprintf(), wp_scripts_get_suffix(), file_get_contents(), wp_get_inline_script_tag(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 100 instructions, 9–99 executed per call, 1 branch. The work does not change between versions.
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 · 1
One hook fires while get_post_embed_html() runs, in this order:
- apply_filters( embed_html )filterline 535 (+56 into the body)
Filters the embed HTML output for a given post.
Uses · 13
- get_post()Retrieves post data given a post ID or post object.
- get_post_embed_url()Retrieves the URL to embed a specific post in an iframe.
- wp_generate_password()Generates a random password drawn from the defined set of characters.
- esc_attr()Escaping for HTML attributes.
- esc_url()Checks and cleans a URL.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- get_the_title()Retrieves the post title.
- absint()Converts a value to non-negative integer.
- __()Retrieves the translation of $text.
- get_bloginfo()Retrieves information about the current site.
- wp_get_inline_script_tag()Constructs an inline script tag.
- wp_scripts_get_suffix()Returns the suffix that can be used for the scripts.
Show all 13
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 2
- get_oembed_response_data_rich()Filters the oEmbed response data to return an iframe embed code.
- print_embed_sharing_dialog()Prints the necessary markup for the embed sharing dialog.
Source code
function get_post_embed_html( $width, $height, $post = null ) { $post = get_post( $post ); if ( ! $post ) { return false; } $embed_url = get_post_embed_url( $post ); $secret = wp_generate_password( 10, false ); $embed_url .= "#?secret={$secret}"; $output = sprintf( '<blockquote class="wp-embedded-content" data-secret="%1$s"><a href="%2$s">%3$s</a></blockquote>', esc_attr( $secret ), esc_url( get_permalink( $post ) ), get_the_title( $post ) ); $output .= sprintf( '<iframe sandbox="allow-scripts" security="restricted" src="%1$s" width="%2$d" height="%3$d" title="%4$s" data-secret="%5$s" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>', esc_url( $embed_url ), absint( $width ), absint( $height ), esc_attr( sprintf( /* translators: 1: Post title, 2: Site title. */ __( '“%1$s” — %2$s' ), get_the_title( $post ), get_bloginfo( 'name' ) ) ), esc_attr( $secret ) ); /* * Note that the script must be placed after the <blockquote> and <iframe> due to a regexp parsing issue in * `wp_filter_oembed_result()`. Because of the regex pattern starts with `|(<blockquote>.*?</blockquote>)?.*|` * wherein the <blockquote> is marked as being optional, if it is not at the beginning of the string then the group * will fail to match and everything will be matched by `.*` and not included in the group. This regex issue goes * back to WordPress 4.4, so in order to not break older installs this script must come at the end. */ $output .= wp_get_inline_script_tag( file_get_contents( ABSPATH . WPINC . '/js/wp-embed' . wp_scripts_get_suffix() . '.js' ) ); /** * Filters the embed HTML output for a given post. * * @since 4.4.0 * * @param string $output The default iframe tag to display embedded content. * @param WP_Post $post Current post object. * @param int $width Width of the response. * @param int $height Height of the response. */ return apply_filters( 'embed_html', $output, $post, $width, $height );}Changelog
Introduced in 4.4.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$post retyped from int|WP_Post to int|WP_Post|null.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.