PluginProbe
Gutenberg / 22.9.0
Gutenberg v22.9.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / block-library / playlist-track.php

playlist-track.php in Gutenberg 22.9.0, at build/scripts/block-library/playlist-track.php

75 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering of the `core/playlist-track` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Renders the `core/playlist-track` block on server.
10 *
11 * @since 6.9.0
12 *
13 * @param array $attributes The block attributes.
14 *
15 * @return string Returns the Playlist Track.
16 */
17 function gutenberg_render_block_core_playlist_track( $attributes ) {
18 if ( empty( $attributes['id'] ) ) {
19 return '';
20 }
21
22 $wrapper_attributes = get_block_wrapper_attributes();
23
24 $unique_id = $attributes['uniqueId'] ?? wp_unique_id( 'playlist-track-' );
25 $artist = $attributes['artist'] ?? '';
26 $length = $attributes['length'] ?? '';
27 $title = isset( $attributes['title'] ) && ! empty( $attributes['title'] ) ? $attributes['title'] : __( 'Unknown title' );
28
29 $context = wp_interactivity_data_wp_context(
30 array(
31 'uniqueId' => $unique_id,
32 )
33 );
34
35 $html = '<li ' . $wrapper_attributes . '>';
36 $html .= '<button ' . $context . 'data-wp-on--click="actions.changeTrack" data-wp-bind--aria-current="state.isCurrentTrack" class="wp-block-playlist-track__button">';
37
38 $html .= '<span class="wp-block-playlist-track__content">';
39 if ( $title ) {
40 $html .= '<span class="wp-block-playlist-track__title">' . wp_kses_post( $title ) . '</span>';
41 }
42 if ( $artist ) {
43 $html .= '<span class="wp-block-playlist-track__artist">' . wp_kses_post( $artist ) . '</span>';
44 }
45 $html .= '</span>';
46
47 if ( $length ) {
48 $html .= '<span class="wp-block-playlist-track__length">';
49 $html .= '<span class="screen-reader-text">' . esc_html__( 'Length:' ) . ' </span>';
50 $html .= esc_html( $length );
51 $html .= '</span>';
52 }
53
54 $html .= '<span class="screen-reader-text">' . esc_html__( 'Select to play this track' ) . '</span>';
55 $html .= '</button>';
56 $html .= '</li>';
57
58 return $html;
59 }
60
61 /**
62 * Registers the `core/playlist-track` block on server.
63 *
64 * @since 6.9.0
65 */
66 function gutenberg_register_block_core_playlist_track() {
67 register_block_type_from_metadata(
68 __DIR__ . '/playlist-track',
69 array(
70 'render_callback' => 'gutenberg_render_block_core_playlist_track',
71 )
72 );
73 }
74 add_action( 'init', 'gutenberg_register_block_core_playlist_track', 20 );
75