| @@ -7,59 +7,52 @@ | ||
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Renders the `core/playlist-track` block on server. |
| 10 | 10 | * |
| 11 | - * @since 7.1.0 | |
| 11 | + * @since 6.9.0 | |
| 12 | 12 | * |
| 13 | - * @param array $attributes The block attributes. | |
| 14 | - * @param string $content The block content. | |
| 15 | - * @param WP_Block|null $block The block instance. | |
| 13 | + * @param array $attributes The block attributes. | |
| 16 | 14 | * |
| 17 | 15 | * @return string Returns the Playlist Track. |
| 18 | 16 | */ |
| 19 | -function gutenberg_render_block_core_playlist_track( $attributes, $content = '', $block = null ) { | |
| 17 | +function gutenberg_render_block_core_playlist_track( $attributes ) { | |
| 20 | 18 | if ( empty( $attributes['id'] ) ) { |
| 21 | 19 | return ''; |
| 22 | 20 | } |
| 23 | 21 | |
| 24 | 22 | $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 | 23 | |
| 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' ); | |
| 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' ); | |
| 35 | 28 | |
| 29 | + $context = wp_interactivity_data_wp_context( | |
| 30 | + array( | |
| 31 | + 'uniqueId' => $unique_id, | |
| 32 | + ) | |
| 33 | + ); | |
| 34 | + | |
| 36 | 35 | $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">'; | |
| 36 | + $html .= '<button ' . $context . 'data-wp-on--click="actions.changeTrack" data-wp-bind--aria-current="state.isCurrentTrack" class="wp-block-playlist-track__button">'; | |
| 38 | 37 | |
| 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 | 38 | $html .= '<span class="wp-block-playlist-track__content">'; |
| 44 | 39 | if ( $title ) { |
| 45 | - $html .= '<span class="wp-block-playlist-track__title">' . esc_html( $title ) . '</span>'; | |
| 40 | + $html .= '<span class="wp-block-playlist-track__title">' . wp_kses_post( $title ) . '</span>'; | |
| 46 | 41 | } |
| 47 | 42 | if ( $artist ) { |
| 48 | - $html .= '<span class="wp-block-playlist-track__artist">' . esc_html( $artist ) . '</span>'; | |
| 43 | + $html .= '<span class="wp-block-playlist-track__artist">' . wp_kses_post( $artist ) . '</span>'; | |
| 49 | 44 | } |
| 50 | 45 | $html .= '</span>'; |
| 51 | 46 | |
| 52 | 47 | if ( $length ) { |
| 53 | 48 | $html .= '<span class="wp-block-playlist-track__length">'; |
| 54 | - $html .= '<span class="screen-reader-text">' . esc_html__( 'Duration:' ) . ' </span>'; | |
| 49 | + $html .= '<span class="screen-reader-text">' . esc_html__( 'Length:' ) . ' </span>'; | |
| 55 | 50 | $html .= esc_html( $length ); |
| 56 | 51 | $html .= '</span>'; |
| 57 | 52 | } |
| 58 | 53 | |
| 59 | - $html .= '<span class="screen-reader-text" data-wp-text="state.trackButtonActionLabel">'; | |
| 60 | - $html .= esc_html__( 'Play' ); | |
| 61 | - $html .= '</span>'; | |
| 54 | + $html .= '<span class="screen-reader-text">' . esc_html__( 'Select to play this track' ) . '</span>'; | |
| 62 | 55 | $html .= '</button>'; |
| 63 | 56 | $html .= '</li>'; |
| 64 | 57 | |
| 65 | 58 | return $html; |
| @@ -67,9 +60,9 @@ | ||
| 67 | 60 | |
| 68 | 61 | /** |
| 69 | 62 | * Registers the `core/playlist-track` block on server. |
| 70 | 63 | * |
| 71 | - * @since 7.1.0 | |
| 64 | + * @since 6.9.0 | |
| 72 | 65 | */ |
| 73 | 66 | function gutenberg_register_block_core_playlist_track() { |
| 74 | 67 | register_block_type_from_metadata( |
| 75 | 68 | __DIR__ . '/playlist-track', |