[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/blocks/ -> playlist-track.php (source)

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


Generated : Sat Nov 14 08:20:01 2026 Cross-referenced by PHPXref