render_block_core_playlist( array $attributes, string $content, WP_Block $block ): string
- Since
- 7.1.0
- Source
wp-includes/blocks/playlist.php:19
core/playlist block on server.Compatibility
- WordPress
- since 7.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$attributesarray- The block attributes.
$contentstring- The block content.
$blockWP_Block- The block instance.
Return value
string- Returns the Playlist.
Performance profile
How much work a call to render_block_core_playlist() 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
- Light
- Scaling
- Scales with input
- Instructions
- 16–175
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 274.
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_playlist()
Further down the call graph this can also reach option, cache, serialize, query 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 · 11 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_playlist() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($playlist_tracks) | 16–20 | wp_unique_id() |
!empty($playlist_tracks) && empty($attributes) && empty($figure) | 120–131 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), preg_match(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
!empty($playlist_tracks) && empty($attributes) && !empty($figure) | 128–139 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), preg_match(), preg_replace(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
!empty($playlist_tracks) && empty($figure) | 129–140 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), esc_attr(), preg_match(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
!empty($playlist_tracks) && !empty($figure) | 137–148 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), esc_attr(), preg_match(), preg_replace(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
!empty($playlist_tracks) && empty($figure) | 138–149 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), esc_attr(), esc_attr(), preg_match(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
!empty($playlist_tracks) && !empty($figure) | 146–157 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), esc_attr(), esc_attr(), preg_match(), preg_replace(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
!empty($playlist_tracks) && empty($figure) | 147–158 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), esc_attr(), esc_attr(), esc_attr(), preg_match(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
!empty($playlist_tracks) && !empty($figure) | 155–166 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), esc_attr(), esc_attr(), esc_attr(), preg_match(), preg_replace(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
!empty($playlist_tracks) && !empty($attributes) && empty($figure) | 156–167 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), preg_match(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
!empty($playlist_tracks) && !empty($attributes) && !empty($figure) | 164–175 | wp_unique_id(), wp_enqueue_script_module(), playlists(), esc_attr__(), esc_attr__(), esc_attr__(), esc_attr_x(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), preg_match(), preg_replace(), ->next_tag(), ->set_attribute(), __(), __(), playlistId(), wp_json_encode(), ->next_tag(), ->get_updated_html() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 273 | 16–175 | 25 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 274 | 16–175 | 25 | |
| 8.4 | 274 | 16–175 | 25 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 278 | 16–179 | 25 | |
| 8.2 | 278 | 16–179 | 25 | |
| 8.1 | 278 | 16–179 | 25 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 279 | 16–179 | 25 |
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 · 12
- wp_unique_id()Gets unique ID.
- __()Retrieves the translation of $text.
- _x()Retrieves translated string with gettext context.
- esc_url()Checks and cleans a URL.
- wp_strip_all_tags()Properly strips all HTML tags including 'script' and 'style'.
- wp_enqueue_script_module()Marks the script module to be enqueued in the page.
- wp_interactivity_state()Gets and/or sets the initial state of an Interactivity API store for a given namespace.
- esc_attr__()Retrieves the translation of $text and escapes it for safe use in an attribute.
- esc_attr_x()Translates string with gettext context, and escapes it for safe use in an attribute.
- esc_attr()Escaping for HTML attributes.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- WP_HTML_Tag_Processor::__construct()Constructor.
Source code
function render_block_core_playlist( $attributes, $content, $block ) { $playlist_id = wp_unique_id( 'playlist-' ); $playlist_tracks = array(); $tracks_data = array(); $show_play_button_artwork = ! empty( $attributes['showPlayButtonArtwork'] ); // Parse inner blocks to extract track data. // This approach avoids duplicating track data in the HTML output. if ( ! empty( $block->inner_blocks ) ) { foreach ( $block->inner_blocks as $inner_block ) { if ( 'core/playlist-track' === $inner_block->name ) { $track_attributes = $inner_block->attributes; if ( empty( $track_attributes['id'] ) ) { continue; } $track_id = 'track-' . count( $playlist_tracks ); $playlist_tracks[] = $track_id; // Extract track metadata from block attributes. $title = isset( $track_attributes['title'] ) && ! empty( $track_attributes['title'] ) ? $track_attributes['title'] : __( 'Unknown title' ); $artist = $track_attributes['artist'] ?? ''; $album = $track_attributes['album'] ?? ''; $image = $track_attributes['image'] ?? ''; $image_alt = $track_attributes['imageAlt'] ?? ''; $url = $track_attributes['src'] ?? ''; $aria_label = $title; if ( $title && $artist && $album ) { $aria_label = sprintf( /* translators: %1$s: track title, %2$s: artist name, %3$s: album name. */ _x( '%1$s by %2$s from the album %3$s', 'track title, artist name, album name' ), $title, $artist, $album ); } // Data is passed to wp_interactivity_state() which JSON-encodes it, // so we use wp_strip_all_tags() instead of esc_html() to prevent // HTML injection without double-encoding. URLs still use esc_url(). $tracks_data[ $track_id ] = array( 'url' => esc_url( $url ), 'title' => wp_strip_all_tags( $title ), 'artist' => wp_strip_all_tags( $artist ), 'album' => wp_strip_all_tags( $album ), 'image' => esc_url( $image ), 'imageAlt' => wp_strip_all_tags( $image_alt ), 'ariaLabel' => wp_strip_all_tags( $aria_label ), ); } } } if ( empty( $playlist_tracks ) ) { return ''; } wp_enqueue_script_module( '@wordpress/block-library/playlist/view' ); // Add the playlist tracks to the global state, // but keep them isolated from other playlists with the help of playlistId. wp_interactivity_state( 'core/playlist', array( 'playlists' => array( $playlist_id => array( 'tracks' => $tracks_data, ), ), ) ); // Add waveform player container with translated button labels. $label_play = esc_attr__( 'Play' ); $label_pause = esc_attr__( 'Pause' ); $label_seek = esc_attr__( 'Seek' ); /* translators: %1$s: current audio time, %2$s: total audio duration. */ $label_seek_value = esc_attr_x(Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks/playlist.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.