| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 * @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 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 6.9.0 72 */ 73 function register_block_core_playlist_track() { 74 register_block_type_from_metadata( 75 __DIR__ . '/playlist-track', 76 array( 77 'render_callback' => 'render_block_core_playlist_track', 78 ) 79 ); 80 } 81 add_action( 'init', 'register_block_core_playlist_track' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Jul 16 08:20:16 2026 | Cross-referenced by PHPXref |