Skip to content

Instantly share code, notes, and snippets.

@specialosis
Created April 15, 2019 20:03
Show Gist options
  • Save specialosis/972f646e917c4962af962241080f2333 to your computer and use it in GitHub Desktop.
Save specialosis/972f646e917c4962af962241080f2333 to your computer and use it in GitHub Desktop.
/* ADDing twitch from bp profile*/
/* Still in development phase, */
/* you would need to add a new field group from the bp profile field in the users tab called twitch channel Name */
$channelsApi = 'https://glass.twitch.tv/console';
$channelName = 'null';
$clientId = 'kr48dgy7mckk8vg3aj0tgezou1okuw';
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array(
'Client-ID: ' . $clientId
),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $channelsApi . $channelName
));
$response = curl_exec($ch);
curl_close($ch);
/* ADDing twitch from bp profile*/
/* ADDing twitch from bp profile*/
// Add's Twitch Channel To BuddyPress Profiles
if(!class_exists('BP_Twitch_Tab')):
class BP_Twitch_Tab {
public $tab_name = 'Twitch Stream';
public $content_title = 'Helping to promote Our Users Twitch TV Channel';
public $url_slug = 'twitchstream';
public $subnav_slug = 'twitch-stream';
public $tab_position = 40;
public $show_chat = true;
// channel name will be grabbed from buddypress field $field_name
public $channelName = null;
public $field_name = 'Twitch Channel Name';
public function __construct () {
add_action('bp_setup_nav', array($this, 'profile_tab'));
}
// add profile tab
public function profile_tab() {
global $bp;
// get channel name
$this->channelName = bp_get_profile_field_data('field=' . $this->field_name . '&user_id=' . bp_loggedin_user_id());
if($this->channelName) {
bp_core_new_nav_item( array(
'parent_url' => bp_loggedin_user_domain() . '/' . $this->url_slug . '/',
'slug' => $this->url_slug,
'default_subnav_slug' => $this->subnav_slug,
'parent_slug' => $bp->profile->slug,
'name' => $this->tab_name,
'position' => $this->tab_position,
'screen_function' => array($this, 'screen_function')
) );
}
}
// call actions on profile screen
public function screen_function() {
add_action( 'bp_template_title', array($this, 'template_title') );
add_action( 'bp_template_content', array($this, 'template_content') );
bp_core_load_template( 'buddypress/members/single/plugins' );
}
// add content title
public function template_title() {
echo $this->content_title;
}
// show iframe
public function template_content() {
?> <iframe src="https://player.twitch.tv/?channel=<?php echo $this->channelName?>" frameborder="0" scrolling="no" allowFullScreen="yes" height="500"width="100%"> </iframe>
<?php
// show chat
if ($this->show_chat) {
?> <iframe frameborder="0" scrolling="no" class="chat_embed" src="https://www.twitch.tv/embed?channel=<?php echo $this->channelName;?> /chat="height="500" width="100%"></iframe> <?php
}
}
}
endif;
new BP_Twitch_Tab;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment