Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active April 16, 2019 20:04
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/ee2af070e768c6b811c53a535f77cc9d to your computer and use it in GitHub Desktop.
Save billerickson/ee2af070e768c6b811c53a535f77cc9d to your computer and use it in GitHub Desktop.
<?php
/**
* Get Youtube Channel
*
*/
function ea_get_youtube_channel( $user = '' ) {
if( empty( $user ) )
return;
$channels = get_option( 'ea_youtube_gallery_channels' );
if( empty( $channels ) || empty( $channels[ $user ] ) ) {
$url = add_query_arg(
array(
'forUsername' => esc_attr( $user ),
'part' => 'id',
'key' => EA_YOUTUBE_API_KEY,
),
'https://www.googleapis.com/youtube/v3/channels'
);
$response = wp_remote_get( $url );
$data = json_decode( wp_remote_retrieve_body( $response ) );
if( !empty( $data->items ) )
$channels[ $user ] = $data->items[0]->id;
else
$channels[ $user ] = false;
update_option( 'ea_youtube_gallery_channels', $channels );
}
return $channels[ $user ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment