Add Twitch tab in BuddyPress profile

Thanks Destac for solution.

  1. First of all, add this code in child theme functions.php or create a custom plugin:
// Add's Twitch Channel To BuddyPress Profiles
if(!class_exists('BP_Twitch_Tab')):
class BP_Twitch_Tab {
    public $tab_name = 'Twitch TV';
    public $content_title = 'Twitch TV Channel';
    public $url_slug = 'twitchtv';
    public $subnav_slug = 'twtchtv';
    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';
    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="//www.twitch.tv/<?php echo $this->channelName; ?>/embed" frameborder="0" scrolling="no" height="500" width="100%"></iframe> <?php
        // show chat
        if ($this->show_chat) {
            ?> <iframe frameborder="0" scrolling="no" class="chat_embed" src="//twitch.tv/chat/embed?channel=<?php echo $this->channelName; ?>&popout_chat=true" height="400" width="100%"></iframe> <?php
        }
    }
}
endif;
new BP_Twitch_Tab;
  1. In admin dashboard open Users > Profile Fields and create a field with name Twitch Channel.
  2. Open your profile settings Users > Select User > Extended Profile and add your channel name in the Twitch Channel field.
Was this page helpful?