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


Generated : Mon Sep 14 08:20:31 2026 Cross-referenced by PHPXref