PluginProbe
Gutenberg / 23.6.2
Gutenberg v23.6.2
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 23.6.2, at build/scripts/block-library/playlist-track.php

82 lines 2.5 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 7.1.0
12 *
13 * @param array $attributes The block attributes.
14 * @param string $content The block content.
15 * @param WP_Block|null $block The block instance.
16 *
17 * @return string Returns the Playlist Track.
18 */
19 function gutenberg_render_block_core_playlist_track( $attributes, $content = '', $block = null ) {
20 if ( empty( $attributes['id'] ) ) {
21 return '';
22 }
23
24 $wrapper_attributes = get_block_wrapper_attributes();
25 $show_images = true;
26 if ( $block instanceof WP_Block && isset( $block->context['showImages'] ) ) {
27 $show_images = $block->context['showImages'];
28 }
29
30 $artist = $attributes['artist'] ?? '';
31 $image = $attributes['image'] ?? '';
32 $alt = $attributes['imageAlt'] ?? '';
33 $length = $attributes['length'] ?? '';
34 $title = isset( $attributes['title'] ) && ! empty( $attributes['title'] ) ? $attributes['title'] : __( 'Unknown title' );
35
36 $html = '<li ' . $wrapper_attributes . '>';
37 $html .= '<button data-wp-on--click="actions.changeTrack" data-wp-bind--aria-current="state.isCurrentTrack" class="wp-block-playlist-track__button">';
38
39 if ( $show_images && $image ) {
40 $html .= '<img class="wp-block-playlist-track__image" src="' . esc_url( $image ) . '" alt="' . esc_attr( $alt ) . '" />';
41 }
42
43 $html .= '<span class="wp-block-playlist-track__content">';
44 if ( $title ) {
45 $html .= '<span class="wp-block-playlist-track__title">' . esc_html( $title ) . '</span>';
46 }
47 if ( $artist ) {
48 $html .= '<span class="wp-block-playlist-track__artist">' . esc_html( $artist ) . '</span>';
49 }
50 $html .= '</span>';
51
52 if ( $length ) {
53 $html .= '<span class="wp-block-playlist-track__length">';
54 $html .= '<span class="screen-reader-text">' . esc_html__( 'Duration:' ) . ' </span>';
55 $html .= esc_html( $length );
56 $html .= '</span>';
57 }
58
59 $html .= '<span class="screen-reader-text" data-wp-text="state.trackButtonActionLabel">';
60 $html .= esc_html__( 'Play' );
61 $html .= '</span>';
62 $html .= '</button>';
63 $html .= '</li>';
64
65 return $html;
66 }
67
68 /**
69 * Registers the `core/playlist-track` block on server.
70 *
71 * @since 7.1.0
72 */
73 function gutenberg_register_block_core_playlist_track() {
74 register_block_type_from_metadata(
75 __DIR__ . '/playlist-track',
76 array(
77 'render_callback' => 'gutenberg_render_block_core_playlist_track',
78 )
79 );
80 }
81 add_action( 'init', 'gutenberg_register_block_core_playlist_track', 20 );
82