Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
function render_block( $attributes ) {
do_shortcode( '[playlist type="podcast"]');
}
function podcast_playlist( $output, $attributes, $instance ) {
if ( 'podcast' !== $attributes['type'] ) {
return $output;
}
global $content_width;
$post = get_post();
$attributes = 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,
),
$attributes,
'playlist'
);
$attachments = [
'https://d3ctxlq1ktw2nl.cloudfront.net/production/2020-1-24/52173267-44100-2-730ecc202597b.mp3',
];
$safe_type = 'audio';
$data = array(
'type' => 'audio',
// Don't pass strings to JSON, will be truthy in JS.
'tracklist' => true,
'tracknumbers' => true,
'images' => true,
'artists' => true,
'tracks' => [
[
'src' => 'https://d3ctxlq1ktw2nl.cloudfront.net/production/2020-1-24/52173267-44100-2-730ecc202597b.mp3',
'type' => 'audio/mp3',
'title' => 'test title',
'caption' => 'test caption',
'description' => 'test description',
'meta' => [],
]
]
);
$outer = 22; // Default padding and border of wrapper.
$default_width = 640;
$default_height = 360;
$theme_width = empty( $content_width ) ? $default_width : ( $content_width - $outer );
$theme_height = empty( $content_width ) ? $default_height : round( ( $default_height * $theme_width ) / $default_width );
if ( 1 === $instance ) {
/**
* Prints and enqueues playlist scripts, styles, and JavaScript templates.
*
* @since 3.9.0
*
* @param string $type Type of playlist. Possible values are 'audio' or 'video'.
* @param string $style The 'theme' for the playlist. Core provides 'light' and 'dark'.
*/
do_action( 'wp_playlist_scripts', $attributes['type'], $attributes['style'] );
}
?>
<div class="wp-playlist wp-<?php echo $safe_type; ?>-playlist wp-playlist-<?php echo esc_attr( $attributes['style'] ); ?>">
<div class="wp-playlist-current-item"></div>
<audio controls="controls" preload="none" width="<?php echo (int) $theme_width; ?>"></audio>
<div class="wp-playlist-next"></div>
<div class="wp-playlist-prev"></div>
<noscript>
<ol>
<?php
foreach ( $attachments as $att_id => $attachment ) :
printf( '<li>%s</li>', $attachment );
endforeach;
?>
</ol>
</noscript>
<script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode( $data ); ?></script>
</div>
<?php
return ob_get_clean();
}
add_filter( 'post_playlist', 'podcast_playlist', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment