render_block_core_cover( array $attributes, string $content ): string
- Since
- 6.0.0
- Source
wp-includes/blocks/cover.php:18
core/cover block on server.Compatibility
- WordPress
- since 6.0.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
$attributesarray- The block attributes.
$contentstring- The block rendered content.
Return value
string- Returns the cover block markup, if useFeaturedImage is true.
Performance profile
How much work a call to render_block_core_cover() 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
- 8–141
- Plugin surface
- None
- Called by
- 0
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 314.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below render_block_core_cover() - querycontent query
get_post()one call below render_block_core_cover()
Further down the call graph this can also reach cache, serialize, option 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 · 49 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_cover() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8–21 | none |
isset($attributes) && !empty($attributes) | 21 | wp_oembed_get() |
!isset($attributes) && $attributes && !in_the_loop() | 28–41 | in_the_loop(), get_the_post_thumbnail_url() |
isset($attributes) && !empty($attributes) && empty($src_matches) | 28 | wp_oembed_get(), preg_match() |
!isset($attributes) && $attributes && in_the_loop() | 30–43 | in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url() |
!isset($attributes) && !$attributes | 38–63 | get_the_post_thumbnail(), preg_match() |
isset($attributes) && $attributes && !in_the_loop() | 43–56 | round(), round(), in_the_loop(), get_the_post_thumbnail_url() |
isset($attributes) && $attributes && in_the_loop() | 45–58 | round(), round(), in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url() |
isset($attributes) && !$attributes | 53–78 | round(), round(), get_the_post_thumbnail(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && !->next_tag() | 57–97 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), esc_url(), ->next_tag() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && ->next_tag() | 65–117 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), esc_url(), ->next_tag(), preg_match() |
!isset($attributes) && !in_the_loop() | 82–104 | in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
37 further outcomes, up to 141 instructions
isset($attributes) && !empty($attributes) && !empty($src_matches) && $provider !== "youtube" && !empty($query_params) && !->next_tag() | 84–102 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), http_build_query(), esc_url(), ->next_tag() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && isset($parsed_url) && $provider !== "youtube" && empty($query_params) && !->next_tag() | 84–102 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), parse_str(), esc_url(), ->next_tag() |
!isset($attributes) && in_the_loop() | 84–106 | in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
!isset($attributes) && !in_the_loop() | 85–107 | in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
!isset($attributes) && in_the_loop() | 87–109 | in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
!isset($attributes) && $attributes && !in_the_loop() | 88–110 | in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && isset($parsed_url) && $provider !== "youtube" && !empty($query_params) && !->next_tag() | 89–107 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), parse_str(), http_build_query(), esc_url(), ->next_tag() |
!isset($attributes) && !in_the_loop() | 90–112 | in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
!isset($attributes) && $attributes && in_the_loop() | 90–112 | in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && $provider !== "youtube" && !empty($query_params) && ->next_tag() | 92–122 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), http_build_query(), esc_url(), ->next_tag(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && isset($parsed_url) && $provider !== "youtube" && empty($query_params) && ->next_tag() | 92–122 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), parse_str(), esc_url(), ->next_tag(), preg_match() |
!isset($attributes) && in_the_loop() | 92–114 | in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
!isset($attributes) && !in_the_loop() | 93–115 | in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
!isset($attributes) && in_the_loop() | 95–117 | in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
!isset($attributes) && $attributes && !in_the_loop() | 96–118 | in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && isset($parsed_url) && $provider !== "youtube" && !empty($query_params) && ->next_tag() | 97–127 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), parse_str(), http_build_query(), esc_url(), ->next_tag(), preg_match() |
isset($attributes) && !in_the_loop() | 97–119 | round(), round(), in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && $provider === "youtube" && empty($query_params) && !->next_tag() | 98–111 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), explode(), end(), esc_url(), ->next_tag() |
!isset($attributes) && $attributes && in_the_loop() | 98–120 | in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && in_the_loop() | 99–121 | round(), round(), in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !in_the_loop() | 100–122 | round(), round(), in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && in_the_loop() | 102–124 | round(), round(), in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && $provider === "youtube" && !empty($query_params) && !->next_tag() | 103–116 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), explode(), end(), http_build_query(), esc_url(), ->next_tag() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && isset($parsed_url) && $provider === "youtube" && empty($query_params) && !->next_tag() | 103–116 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), parse_str(), explode(), end(), esc_url(), ->next_tag() |
isset($attributes) && $attributes && !in_the_loop() | 103–125 | round(), round(), in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !in_the_loop() | 105–127 | round(), round(), in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && $attributes && in_the_loop() | 105–127 | round(), round(), in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->add_class(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && $provider === "youtube" && empty($query_params) && ->next_tag() | 106–131 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), explode(), end(), esc_url(), ->next_tag(), preg_match() |
isset($attributes) && in_the_loop() | 107–129 | round(), round(), in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && isset($parsed_url) && $provider === "youtube" && !empty($query_params) && !->next_tag() | 108–121 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), parse_str(), explode(), end(), http_build_query(), esc_url(), ->next_tag() |
isset($attributes) && !in_the_loop() | 108–130 | round(), round(), in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && in_the_loop() | 110–132 | round(), round(), in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && $provider === "youtube" && !empty($query_params) && ->next_tag() | 111–136 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), explode(), end(), http_build_query(), esc_url(), ->next_tag(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && isset($parsed_url) && $provider === "youtube" && empty($query_params) && ->next_tag() | 111–136 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), parse_str(), explode(), end(), esc_url(), ->next_tag(), preg_match() |
isset($attributes) && $attributes && !in_the_loop() | 111–133 | round(), round(), in_the_loop(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && $attributes && in_the_loop() | 113–135 | round(), round(), in_the_loop(), update_post_thumbnail_cache(), get_the_post_thumbnail_url(), get_post_thumbnail_id(), ->next_tag(), get_post_meta(), strip_tags(), ->set_attribute(), ->set_attribute(), ->add_class(), ->add_class(), ->add_class(), ->add_class(), esc_url(), ->set_attribute(), ->get_updated_html(), preg_match() |
isset($attributes) && !empty($attributes) && !empty($src_matches) && isset($parsed_url) && $provider === "youtube" && !empty($query_params) && ->next_tag() | 116–141 | wp_oembed_get(), preg_match(), strtolower(), wp_parse_url(), parse_str(), explode(), end(), http_build_query(), esc_url(), ->next_tag(), preg_match() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 314 | 8–141 | 40 | |
| 8.5 | 314 | 8–141 | 40 | |
| 8.4 | 314 | 8–141 | 40 | 32 fewer instructions than PHP 8.3 |
| 8.3 | 346 | 8–164 | 40 | |
| 8.2 | 346 | 8–164 | 40 | |
| 8.1 | 346 | 8–164 | 40 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 347 | 8–164 | 40 |
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.
Uses · 11
- wp_oembed_get()Attempts to fetch the embed HTML for a provided URL using oEmbed.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- wp_parse_url()A wrapper for PHP's parse_url() function that handles consistency in the return values across PHP versions.
- esc_url()Checks and cleans a URL.
- get_the_post_thumbnail()Retrieves the post thumbnail.
- in_the_loop()Determines whether the caller is in the Loop.
- update_post_thumbnail_cache()Updates cache for thumbnails in the current loop.
- get_the_post_thumbnail_url()Returns the post thumbnail URL.
- get_post_thumbnail_id()Retrieves the post thumbnail ID.
- get_post_meta()Retrieves a post meta field for the given post ID.
- WP_HTML_Tag_Processor::__construct()Constructor.
Source code
function render_block_core_cover( $attributes, $content ) { // Handle embed video background. if ( isset( $attributes['backgroundType'] ) && 'embed-video' === $attributes['backgroundType'] && isset( $attributes['url'] ) && ! empty( $attributes['url'] ) && is_string( $attributes['url'] ) ) { $url = $attributes['url']; // Use WordPress's native oEmbed processing (includes caching). $oembed_html = wp_oembed_get( $url ); if ( $oembed_html ) { // Extract iframe src from the oEmbed HTML. preg_match( '/src=["\']([^"\']+)["\']/', $oembed_html, $src_matches ); if ( ! empty( $src_matches[1] ) ) { $iframe_src = $src_matches[1]; // Detect provider from iframe src URL. $lower_src = strtolower( $iframe_src ); $provider = null; if ( str_contains( $lower_src, 'youtube.com' ) || str_contains( $lower_src, 'youtu.be' ) ) { $provider = 'youtube'; } elseif ( str_contains( $lower_src, 'vimeo.com' ) ) { $provider = 'vimeo'; } elseif ( str_contains( $lower_src, 'videopress.com' ) ) { $provider = 'videopress'; } elseif ( str_contains( $lower_src, 'wordpress.tv' ) ) { $provider = 'wordpress-tv'; } // Modify iframe src to add background video parameters based on provider. $parsed_url = wp_parse_url( $iframe_src ); if ( $parsed_url && isset( $parsed_url['host'] ) ) { // Parse existing query parameters. $query_params = array(); if ( isset( $parsed_url['query'] ) ) { parse_str( $parsed_url['query'], $query_params ); } // Add background video parameters based on provider. if ( 'youtube' === $provider ) { $query_params['autoplay'] = '1'; $query_params['mute'] = '1'; $query_params['loop'] = '1'; $query_params['controls'] = '0'; $query_params['modestbranding'] = '1'; $query_params['playsinline'] = '1'; // For loop to work, we need the playlist parameter. $path = $parsed_url['path'] ?? ''; $path_segments = explode( '/', $path ); $video_id = end( $path_segments ); if ( $video_id ) { $query_params['playlist'] = $video_id; } } elseif ( 'vimeo' === $provider ) { $query_params['autoplay'] = '1'; $query_params['muted'] = '1'; $query_params['loop'] = '1'; $query_params['background'] = '1'; $query_params['controls'] = '0'; $query_params['transparent'] = '0'; } elseif ( 'videopress' === $provider || 'wordpress-tv' === $provider ) { $query_params['autoplay'] = '1'; $query_params['loop'] = '1'; $query_params['muted'] = '1'; } // Rebuild the URL with new parameters. $iframe_src = $parsed_url['scheme'] . '://' . $parsed_url['host']; if ( isset( $parsed_url['path'] ) ) { $iframe_src .= $parsed_url['path']; } if ( ! empty( $query_params ) ) { $iframe_src .= '?' . http_build_query( $query_params ); }Changelog
Introduced in 6.0.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 7.1.0 tag, from
src/wp-includes/blocks/cover.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.