Last active
July 10, 2020 12:12
-
-
Save jeherve/ec1293761c71f56d4362e2260fbe810f to your computer and use it in GitHub Desktop.
[Jetpack] Display a Podcast player anywhere. See https://wordpress.org/support/topic/embedding-the-podcast-player-with-code/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Display a Podcast player anywhere. | |
* Pulled from extensions/blocks/podcast-player/podcast-player.php | |
* @see https://github.com/Automattic/jetpack/blob/b88b1edbdce4d8576ce9be02a9093702ae112fed/extensions/blocks/podcast-player/podcast-player.php | |
* @see https://wordpress.org/support/topic/embedding-the-podcast-player-with-code/ | |
*/ | |
function jeherve_display_podcast() { | |
// bail early if Jetpack isn't installed. | |
if ( ! class_exists( 'Jetpack' ) ) { | |
return; | |
} | |
// Load the necessary libs. | |
if ( ! class_exists( 'Jetpack_Podcast_Helper' ) ) { | |
jetpack_require_lib( 'class-jetpack-podcast-helper' ); | |
} | |
$attributes = array( | |
'url' => 'https://distributed.blog/category/podcast/feed/', | |
'itemsToShow' => 2, | |
'primaryColor' => 'accent', | |
'hexPrimaryColor' => '#e22658', | |
'secondaryColor' => 'primary', | |
'hexSecondaryColor' => '#000000', | |
'backgroundColor' => 'subtle-background', | |
'hexBackgroundColor' => '#dbdbdb', | |
'showCoverArt' => true, | |
'showEpisodeDescription' => true, | |
); | |
$player_data = Jetpack_Podcast_Helper::get_player_data( $attributes['url'] ); | |
// No info from that feed. Bail. | |
if ( is_wp_error( $player_data ) ) { | |
return; | |
} | |
echo \Automattic\Jetpack\Extensions\Podcast_Player\render_player( $player_data, $attributes ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment