wp_playlist_shortcode() – Builds the Playlist shortcode output.

You appear to be a bot. Output may be restricted

Description

Builds the Playlist shortcode output.

This implements the functionality of the playlist shortcode for displaying a collection of WordPress audio or video files in a post.

Usage

$string = wp_playlist_shortcode( $attr );

Parameters

$attr
( array ) required – { Array of default playlist attributes.
$type
( string ) required – Type of playlist to display. Accepts 'audio' or 'video'. Default 'audio'.
$order
( string ) required – Designates ascending or descending order of items in the playlist. Accepts 'ASC', 'DESC'. Default 'ASC'.
$orderby
( string ) required – Any column, or columns, to sort the playlist. If $ids are passed, this defaults to the order of the $ids array ('post__in'). Otherwise default is 'menu_order ID'.
$id
( int ) required – If an explicit $ids array is not present, this parameter will determine which attachments are used for the playlist. Default is the current post ID.
$ids
( array ) required – Create a playlist out of these explicit attachment IDs. If empty, a playlist will be created from all $type attachments of $id. Default empty.
$exclude
( array ) required – List of specific attachment IDs to exclude from the playlist. Default empty.
$style
( string ) required – Playlist style to use. Accepts 'light' or 'dark'. Default 'light'.
$tracklist
( bool ) required – Whether to show or hide the playlist. Default true.
$tracknumbers
( bool ) required – Whether to show or hide the numbers next to entries in the playlist. Default true.
$images
( bool ) required – Show or hide the video or audio thumbnail (Featured Image/post thumbnail). Default true.
$artists
( bool ) required – Whether to show or hide artist name in the playlist. Default true. }

Returns

string Playlist output. Empty string if the passed type is unsupported.

Source

File name: wordpress/wp-includes/media.php
Lines:

1 to 100 of 218
function wp_playlist_shortcode( $attr ) {
  global $content_width;
  $post = get_post();

  static $instance = 0;
  $instance++;

  if ( ! empty( $attr['ids'] ) ) {
    // 'ids' is explicitly ordered, unless you specify otherwise.
    if ( empty( $attr['orderby'] ) ) {
      $attr['orderby'] = 'post__in';
    }
    $attr['include'] = $attr['ids'];
  }

  
/**
 * Filters the playlist output.
 *
 * Returning a non-empty value from the filter will short-circuit generation
 * of the default playlist output, returning the passed value instead.
 *
 * @since 3.9.0
 * @since 4.2.0 The `$instance` parameter was added.
 *
 * @param string $output   Playlist output. Default empty.
 * @param array  $attr     An array of shortcode attributes.
 * @param int    $instance Unique numeric ID of this playlist shortcode instance.
 */
  $output = apply_filters( 'post_playlist', '', $attr, $instance );

  if ( ! empty( $output ) ) {
    return $output;
  }

  $atts = shortcode_atts(
    array(
      'type'         => 'audio',
      'order'        => 'ASC',
      'orderby'      => 'menu_order ID',
      'id'           => $post ? $post->ID : 0,
      'include'      => '',
      'exclude'      => '',
      'style'        => 'light',
      'tracklist'    => true,
      'tracknumbers' => true,
      'images'       => true,
      'artists'      => true,
    ),
    $attr,
    'playlist'
  );

  $id = (int) $atts['id'];

  if ( 'audio' !== $atts['type'] ) {
    $atts['type'] = 'video';
  }

  $args = array(
    'post_status'    => 'inherit',
    'post_type'      => 'attachment',
    'post_mime_type' => $atts['type'],
    'order'          => $atts['order'],
    'orderby'        => $atts['orderby'],
  );

  if ( ! empty( $atts['include'] ) ) {
    $args['include'] = $atts['include'];
    $_attachments    = get_posts( $args );

    $attachments = array();
    foreach ( $_attachments as $key => $val ) {
      $attachments[ $val->ID ] = $_attachments[ $key ];
    }
  } elseif ( ! empty( $atts['exclude'] ) ) {
    $args['post_parent'] = $id;
    $args['exclude']     = $atts['exclude'];
    $attachments         = get_children( $args );
  } else {
    $args['post_parent'] = $id;
    $attachments         = get_children( $args );
  }

  if ( empty( $attachments ) ) {
    return '';
  }

  if ( is_feed() ) {
    $output = "\n";
    foreach ( $attachments as $att_id => $attachment ) {
      $output .= wp_get_attachment_link( $att_id ) . "\n";
    }
    return $output;
  }

  $outer = 22; // Default padding and border of wrapper.

  $default_width  = 640;
  $default_height = 360;

 

 View on GitHub View on Trac