wppaste
WordPress

render_block_core_playlist( array $attributes, string $content, WP_Block $block ): string

Since
7.1.0
Source
wp-includes/blocks/playlist.php:19
Renders the 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
16–175

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
empty($playlist_tracks)16–20wp_unique_id()
!empty($playlist_tracks) && empty($attributes) && empty($figure)120–131wp_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–139wp_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–140wp_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–148wp_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–149wp_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–157wp_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–158wp_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–166wp_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–167wp_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–175wp_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

PHPCompiledExecutedBranchesNotes
8.6-dev27316–175251 fewer instruction than PHP 8.5
8.527416–17525
8.427416–175254 fewer instructions than PHP 8.3
8.327816–17925
8.227816–17925
8.127816–179251 fewer instruction than PHP 7.4
7.427916–17925

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

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.