Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created February 1, 2018 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/7b05942a441839bd8b4068f65c46741a to your computer and use it in GitHub Desktop.
Save billerickson/7b05942a441839bd8b4068f65c46741a to your computer and use it in GitHub Desktop.
<?php
/**
* Get Youtube Videos
*
*/
function ea_get_youtube_videos( $user = '' ) {
if( empty( $user ) )
return;
$key = 'ea_youtube_gallery_' . sanitize_text_field( $user );
$data = get_transient( $key );
if( false === $data ) {
$channel = ea_get_youtube_channel( $user );
$url = add_query_arg( array(
'part' => 'snippet',
'channelId' => $channel,
'order' => 'date',
'maxResults' => 24,
'key' => EA_YOUTUBE_API_KEY,
), 'https://www.googleapis.com/youtube/v3/search' );
$data = wp_remote_retrieve_body( wp_remote_get( $url ) );
set_transient( $key, $data, DAY_IN_SECONDS );
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment