-
-
Save billerickson/ee2af070e768c6b811c53a535f77cc9d to your computer and use it in GitHub Desktop.
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 | |
/** | |
* 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