Wordpress-Plugin Twitch Stream Status with outdated API


#1

Hello!

I’m using a Wordpress-Plugin for displaying the Twitch Online Status which don’t seems to work since the last API changes from the Twitch website.

The author don’t update the script and even not answer in the support forum, so I want to try updating by myself. After taking a look in the main code of the script, I discovered an obviously outdated API-Link in the “stream-status-for-twitch.php” file as following:

<script>
        jQuery('.sst-twitch').each(function () {
            var nickname = jQuery(this).data('nickname');
            jQuery.getJSON("https://api.twitch.tv/kraken/streams/"+nickname+"?client_id=ls2awgx5gfg9m1q6iopdqb1b7d0y6a", function(c) {
                if (c.stream == null) {
                    // show if offline (unless 'Hide when not streaming' option enabled)
                    <?php if( get_theme_mod('sst_offline_hide') != '') { ?><?php } else { ?>jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');<?php } ?>
                    // animations
                    jQuery('.sst-status-text-offline').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-offline').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                } else {
                    // show if online
                    jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');
                    // animations
                    jQuery('.sst-status-text-live').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-live').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                }
            });
        });
        </script>

It seems that it has something to do with the following URL:
https://api.twitch.tv/kraken/streams/"+nickname+"?client_id=ls2awgx5gfg9m1q6iopdqb1b7d0y6a

Trying to open this URL just show me the message “It’s time to kick ass and serve v3… and I’m all outta v3. See https://dev.twitch.tv/docs”.

So my question is wether it’s possible to change this URL to make the script working again for our website showing the Twitch Online Status when streaming? Or is this not enough and the whole script have to be rewritten? I hope that someone can help me out as I’m not a programmer.

Thank you!


#2

Migration guide is here

Needs to be change to use the TwitchID instead of the nickname and the ClientID moved to a header and an additional header set.

You should also look at moving to Helix instead.


#3

Thank you for the links. Unfortunately, I’m not quite smart from the instructions, because I do not know which parts of the link must be changed or is it enough if I change the link as follows?
https://api.twitch.tv/helix/streams/"+TwitchID+"?client_id=ls2awgx5gfg9m1q6iopdqb1b7d0y6a

I replaced “kraken” with “helix” and “nickname” with “TwitchID” like recommended but it’s still not working. :frowning:

Could please someone change the link so that the script works again or have other parts of the script in the source code to be changed? Unfortunately, I can not do it myself. But maybe someone could look at the affected file “stream-status-for-twitch.php” and change it accordingly. That would be a great help to me.


#4

Because you didn’t read the docs and constructed the Helix URL incorrectly

https://api.twitch.tv/helix/streams?user_login=?

fetch(
    'https://api.twitch.tv/helix/streams?user_login='+nickname,
    {
        headers: {
            'client-id': 'ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
        }
    }
)
.then(resp => { return resp.json() })
.then(resp => {
                if (resp.data && resp.data[0] {
                    // show if offline (unless 'Hide when not streaming' option enabled)
                    <?php if( get_theme_mod('sst_offline_hide') != '') { ?><?php } else { ?>jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');<?php } ?>
                    // animations
                    jQuery('.sst-status-text-offline').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-offline').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                } else {
                    // show if online
                    jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');
                    // animations
                    jQuery('.sst-status-text-live').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-live').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                }
})
.catch(err => { console.log(err) });

May work


#5

Many thanks for your effort! Unfortunately it still doesn’t work. The online status aren’t even displayed when im offline, although I copied the whole text from your code inside the “script” area as following.

 <script>
      fetch(
    'https://api.twitch.tv/helix/streams?user_login='+nickname,
    {
        headers: {
            'client-id': 'ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
        }
    }
)
.then(resp => { return resp.json() })
.then(resp => {
                if (resp.data && resp.data[0] {
                    // show if offline (unless 'Hide when not streaming' option enabled)
                    <?php if( get_theme_mod('sst_offline_hide') != '') { ?><?php } else { ?>jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');<?php } ?>
                    // animations
                    jQuery('.sst-status-text-offline').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-offline').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                } else {
                    // show if online
                    jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');
                    // animations
                    jQuery('.sst-status-text-live').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-live').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                }
})
.catch(err => { console.log(err) });
        </script>

I just wonder that the first lines of the original code:

jQuery('.sst-twitch').each(function () {
            var nickname = jQuery(this).data('nickname');
            jQuery.getJSON

are not considered in your changes. Did you forgot this lines? I even try to re-add them before your new code but it still don’t work. :frowning:


#6

I only gave you the fetch function that fetches data. Not a complete fix.

That line didn’t need a change.

<script>
        jQuery('.sst-twitch').each(function () {
            var nickname = jQuery(this).data('nickname');
fetch(
    'https://api.twitch.tv/helix/streams?user_login='+nickname,
    {
        headers: {
            'client-id': 'ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
        }
    }
)
.then(resp => { return resp.json() })
.then(resp => {
                if (resp.data && resp.data[0] {
                    // show if offline (unless 'Hide when not streaming' option enabled)
                    <?php if( get_theme_mod('sst_offline_hide') != '') { ?><?php } else { ?>jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');<?php } ?>
                    // animations
                    jQuery('.sst-status-text-offline').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-offline').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                } else {
                    // show if online
                    jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');
                    // animations
                    jQuery('.sst-status-text-live').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-live').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                }
})
.catch(err => { console.log(err) });
    });</script>

Define “don’t work” do you get any console errors? What is it doing that it shouldn’t be doing?


#7

The plugin should actually show the stream status on our website as a small lamp with link to our twitch channel once the stream is online. I have temporarily adjusted the plugin via the Wordpress Customizer so that the graphic should be displayed even if the stream is not online. Unfortunately, the graphics are not displayed in online or offline mode, not even with the script you just posted a few minutes ago. It’s such a pity that the script is not developed any more and I lack the skills to program or even migrate. Only the exchange of code content or commands I still get. :frowning:

Unfortunately, there is no comparable Wordpress script, as exactly meets our requirements. That’s why I would like to have someone do it to you who knows it - of course not in vain. I’ll write you a PM if that’s okay and send you the plugin.


#8

Then you need to find someone to build you something that works to do your exact requirements. There are many ways to do a live status widget and you can utilize a lot of the new features Twitch offers, and improve how your website works under wordpress


#9

As there where no reply of my private request for migrating, I decided to publish the whole source code of both files with twitch API content. It seems that there are more code parts which have to be changed to get the plugin work again. Maybe you or something else could help me to fix it to get the plugin working again.

include.php:

<a class="sst-twitch" <?php if( get_theme_mod('sst_new_window') != '') { ?> href="https://www.radio-paralax.de/videostream-chat-wide/"<?php } ?> href="https://www.twitch.tv/<?php echo get_theme_mod('sst_channel_name'); ?>" data-nickname="<?php echo get_theme_mod('sst_channel_name'); ?>">
    <!-- BEGIN TWITCH LOGO -->
    <div class="sst-twitch-logo-wrapper">
        <div class="sst-icon-twitch"></div>
    </div>
    <!-- END TWITCH LOGO -->
    <!-- BEGIN STATUS -->
    <div class="sst-status-wrapper">
        <div class="sst-status-wrapper-inner">
            <!-- BEGIN IF ONLINE -->
            <div class="sst-status-text-live">
                <div class="sst-live-marker"></div>
                <span>
                    <?php if( get_theme_mod('sst_live_text') != '') { ?>
                        <?php echo get_theme_mod('sst_live_text'); ?>
                    <?php } else { ?>
                        <?php esc_html_e( 'LIVE NOW! CLICK TO VIEW.', 'stream-status-for-twitch' ); ?>
                    <?php } ?>
                </span>
            </div>
            <!-- END IF ONLINE -->
            <!-- BEGIN IF OFFLINE -->
            <div class="sst-status-text-offline">
                <span>
                    <?php if( get_theme_mod('sst_offline_text') != '') { ?>
                        <?php echo get_theme_mod('sst_offline_text'); ?>
                    <?php } else { ?>
                        <?php esc_html_e( 'CURRENTLY OFFLINE', 'stream-status-for-twitch' ); ?>
                    <?php } ?>
                </span>
            </div>
            <!-- END IF OFFLINE -->
        </div>
    </div>
    <!-- END STATUS -->
</a>

stream-status-for-twitch.php:

<?php
/*
Plugin Name: Stream Status for Twitch
Plugin URI: http://bonfirethemes.com/
Description: Setup and customize under Appearance → Customize → Stream Status for Twitch Plugin
Version: 1.3
Author: Bonfire Themes
Author URI: http://bonfirethemes.com/
Text Domain: stream-status-for-twitch
Domain Path: /languages
License: GPL2
*/

    //
	// WORDPRESS LIVE CUSTOMIZER
	//
	function bonfire_sst_theme_customizer( $wp_customize ) {
	
        //
        // ADD "Stream Status for Twitch Plugin" PANEL TO LIVE CUSTOMIZER 
        //
        $wp_customize->add_panel('sst_panel', array('title' => __('Stream Status for Twitch Plugin','stream-status-for-twitch'),'priority' => 10,));

        //
        // ADD "Main Settings" SECTION TO "Stream Status for Twitch Plugin" PANEL 
        //
        $wp_customize->add_section('sst_main_section',array('title' => __( 'Main Settings','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 1));

        /* channel name */
        $wp_customize->add_setting('sst_channel_name',array('default' => '','sanitize_callback' => 'sanitize_sst_channel_name',));
        function sanitize_sst_channel_name($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_channel_name',array('type' => 'text','label' => __('Channel name','stream-status-for-twitch'),'description' => __('Enter your Twitch channel name in order to display stream status.','stream-status-for-twitch'),'section' => 'sst_main_section',));
        
        /* hide if feed offline */
        $wp_customize->add_setting('sst_offline_hide',array('sanitize_callback' => 'sanitize_sst_offline_hide',));
        function sanitize_sst_offline_hide( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_offline_hide',array('type' => 'checkbox','label' => __('Hide when offline','stream-status-for-twitch'), 'description' => __('If checked, the stream status will be shown only when channel is actively streaming.','stream-status-for-twitch'), 'section' => 'sst_main_section',));
        
        /* open in new window */
        $wp_customize->add_setting('sst_new_window',array('sanitize_callback' => 'sanitize_sst_new_window',));
        function sanitize_sst_new_window( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_new_window',array('type' => 'checkbox','label' => __('Open in new window','stream-status-for-twitch'),'description' => __('If unchecked, Twitch will open in the same window.','stream-status-for-twitch'), 'section' => 'sst_main_section',));
        
        /* live text */
        $wp_customize->add_setting('sst_live_text',array('default' => '','sanitize_callback' => 'sanitize_sst_live_text',));
        function sanitize_sst_live_text($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_live_text',array('type' => 'text','label' => __('Status text if stream is live','stream-status-for-twitch'),'description' => __('If empty, defaults to "LIVE NOW! CLICK TO VIEW."','stream-status-for-twitch'),'section' => 'sst_main_section',));
        
        /* offline text */
        $wp_customize->add_setting('sst_offline_text',array('default' => '','sanitize_callback' => 'sanitize_sst_offline_text',));
        function sanitize_sst_offline_text($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_offline_text',array('type' => 'text','label' => __('Status text if stream is offline','stream-status-for-twitch'),'description' => __('If empty, defaults to "CURRENTLY OFFLINE".','stream-status-for-twitch'),'section' => 'sst_main_section',));
        
        //
        // ADD "Positioning" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_positioning_section',array('title' => __( 'Positioning','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 2));
        
        /* absolute position */
        $wp_customize->add_setting('sst_absolute_position',array('sanitize_callback' => 'sanitize_sst_absolute_position',));
        function sanitize_sst_absolute_position( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_absolute_position',array('type' => 'checkbox','label' => __('Absolute positioning','stream-status-for-twitch'),'description' => __('If unchecked, fixed positioning is applied.','stream-status-for-twitch'), 'section' => 'sst_positioning_section',));
        
        /* vertical placemenet */
        $wp_customize->add_setting('sst_placement',array(
            'default' => 'top',
        ));
        $wp_customize->add_control('sst_placement',array(
            'type' => 'select',
            'label' => __('Vertical placement','stream-status-for-twitch'),
            'section' => 'sst_positioning_section',
            'choices' => array(
                'top' => __('Top','stream-status-for-twitch'),
                'bottom' => __('Bottom','stream-status-for-twitch'),
        ),
        ));
        
        /* horizontal placemenet */
        $wp_customize->add_setting('sst_placement_horizontal',array(
            'default' => 'left',
        ));
        $wp_customize->add_control('sst_placement_horizontal',array(
            'type' => 'select',
            'label' => __('Horizontal placement','stream-status-for-twitch'),
            'section' => 'sst_positioning_section',
            'choices' => array(
                'left' => __('Left','stream-status-for-twitch'),
                'right' => __('Right','stream-status-for-twitch'),
        ),
        ));
        
        /* top/bottom distance */
        $wp_customize->add_setting('sst_vertical_distance',array('default' => '','sanitize_callback' => 'sanitize_sst_vertical_distance',));
        function sanitize_sst_vertical_distance($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_vertical_distance',array('type' => 'text','label' => __('Top/bottom distance (in pixels)','stream-status-for-twitch'),'description' => __('Example: 50 (if empty, defaults to 25).','stream-status-for-twitch'),'section' => 'sst_positioning_section',));
        
        /* left distance */
        $wp_customize->add_setting('sst_horizontal_distance',array('default' => '','sanitize_callback' => 'sanitize_sst_horizontal_distance',));
        function sanitize_sst_horizontal_distance($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_horizontal_distance',array('type' => 'text','label' => __('Left/right distance (in pixels)','stream-status-for-twitch'),'description' => __('Example: 50 (if empty, defaults to 25).','stream-status-for-twitch'),'section' => 'sst_positioning_section',));
        
        //
        // ADD "Customization" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_customization_section',array('title' => __( 'Customization','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 3));
        
        /* background color */
        $wp_customize->add_setting('sst_background_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_background_color',array(
            'label'=>__('Background','stream-status-for-twitch'),'settings'=>'sst_background_color','section'=>'sst_customization_section')
        ));
        
        /* status text color */
        $wp_customize->add_setting('sst_status_text_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_status_text_color',array(
            'label'=>__('Status text','stream-status-for-twitch'),'settings'=>'sst_status_text_color','section'=>'sst_customization_section')
        ));
        
        /* status text hover color */
        $wp_customize->add_setting('sst_status_text_hover_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_status_text_hover_color',array(
            'label'=>__('Status text (hover)','stream-status-for-twitch'),'settings'=>'sst_status_text_hover_color','section'=>'sst_customization_section')
        ));
        
        /* Twitch icon color */
        $wp_customize->add_setting('sst_twitch_icon_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_twitch_icon_color',array(
            'label'=>__('Twitch icon','stream-status-for-twitch'),'settings'=>'sst_twitch_icon_color','section'=>'sst_customization_section')
        ));
        
        /* Twitch icon background color */
        $wp_customize->add_setting('sst_twitch_icon_background_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_twitch_icon_background_color',array(
            'label'=>__('Twitch icon background','stream-status-for-twitch'),'settings'=>'sst_twitch_icon_background_color','section'=>'sst_customization_section')
        ));
        
        /* rounded corners */
        $wp_customize->add_setting('sst_rounded_corners',array('default' => '','sanitize_callback' => 'sanitize_sst_rounded_corners',));
        function sanitize_sst_rounded_corners($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_rounded_corners',array('type' => 'text','label' => __('Rounded corners (in pixels)','stream-status-for-twitch'),'description' => __('Example: 5 (if empty, defaults to 0).','stream-status-for-twitch'),'section' => 'sst_customization_section',));
        
        /* larger design */
        $wp_customize->add_setting('sst_larger_design',array('sanitize_callback' => 'sanitize_sst_larger_design',));
        function sanitize_sst_larger_design( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_larger_design',array('type' => 'checkbox','label' => __('Larger design','stream-status-for-twitch'),'description' => __('When checked, the status indicator will look a bit larger.','stream-status-for-twitch'), 'section' => 'sst_customization_section',));
        
        /* disable status text underline */
        $wp_customize->add_setting('sst_no_underline',array('sanitize_callback' => 'sanitize_sst_no_underline',));
        function sanitize_sst_no_underline( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_no_underline',array('type' => 'checkbox','label' => __('Disable status text underline','stream-status-for-twitch'),'description' => __('When checked, status text will not be underlined when hovered.','stream-status-for-twitch'), 'section' => 'sst_customization_section',));
        
        //
        // ADD "Misc" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_misc_section',array('title' => __( 'Misc','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 3));
        
        /* disable animation */
        $wp_customize->add_setting('sst_disable_animation',array('sanitize_callback' => 'sanitize_sst_disable_animation',));
        function sanitize_sst_disable_animation( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_disable_animation',array('type' => 'checkbox','label' => __('Disable appearance animation','stream-status-for-twitch'), 'section' => 'sst_misc_section',));
        
        /* smaller than */
        $wp_customize->add_setting('sst_smaller_than',array('sanitize_callback' => 'sanitize_sst_smaller_than',));
        function sanitize_sst_smaller_than($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_smaller_than',array(
            'type' => 'text',
            'label' => __('Hide at certain width/resolution','stream-status-for-twitch'),
            'description' => __('<strong>Example #1:</strong> If you want to show the stream status on desktop only, enter the values as 0 and 500. <br><br> <strong>Example #2:</strong> If you want to show the stream status on mobile only, enter the values as 500 and 5000. <br><br> Feel free to experiment with your own values to get the result that is right for you. If fields are empty, the stream status will be visible at all browser widths and resolutions. <br><br> Hide stream status if browser width or screen resolution (in pixels) is between...','stream-status-for-twitch'),
            'section' => 'sst_misc_section',
        ));
        
        /* larger than */
        $wp_customize->add_setting('sst_larger_than',array('sanitize_callback' => 'sanitize_sst_larger_than',));
        function sanitize_sst_larger_than($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_larger_than',array(
            'type' => 'text',
            'description' => __('..and:','stream-status-for-twitch'),
            'section' => 'sst_misc_section',
        ));
        
        //
        // ADD "Go Pro!" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_gopro_section',array('title' => __( 'Go Pro!','stream-status-for-twitch' ), 'panel' => 'sst_panel','priority' => 10));

        require_once 'sst_custom_controls.php';
        /* custom notice custom contol */
        $wp_customize->add_setting('sst_custom_info', array(
            'default'           => '',
            'sanitize_callback' => 'sst_text_sanitization',
        ));
        $wp_customize->add_control(new Info_Custom_Control_sst($wp_customize, 'sst_custom_info', array(
            'settings'		=> 'sst_custom_info',
            'section'  		=> 'sst_gopro_section',
        )));
        
        //
        // ADD "Need a video game theme?" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_theme_section',array('title' => __( 'Need a video game theme?','stream-status-for-twitch' ), 'panel' => 'sst_panel','priority' => 10));

        require_once 'sst_custom_controls.php';
        /* custom notice custom contol */
        $wp_customize->add_setting('sst_custom_info_theme', array(
            'default'           => '',
            'sanitize_callback' => 'sst_text_sanitization',
        ));
        $wp_customize->add_control(new Info_Custom_Control_sst_theme($wp_customize, 'sst_custom_info_theme', array(
            'settings'		=> 'sst_custom_info_theme',
            'section'  		=> 'sst_theme_section',
        )));

	}
	add_action('customize_register', 'bonfire_sst_theme_customizer');

	//
	// Add stream status to theme
	//
	
	function bonfire_sst_header() {
	?>

        <!-- BEGIN MAIN WRAPPER (show only if Twitch channel name entered) -->
        <?php if( get_theme_mod('sst_channel_name') != '') { ?>
        <div class="sst-main-wrapper">
            <?php include( plugin_dir_path( __FILE__ ) . 'include.php'); ?>
        </div>
        <?php } ?>
        <!-- END MAIN WRAPPER (show only if Twitch channel name entered) -->
        
        <script>
        jQuery('.sst-twitch').each(function () {
            var nickname = jQuery(this).data('nickname');
            jQuery.getJSON("https://api.twitch.tv/kraken/streams/"+nickname+"?client_id=ls2awgx5gfg9m1q6iopdqb1b7d0y6a", function(c) {
                if (c.stream == null) {
                    // show if offline (unless 'Hide when not streaming' option enabled)
                    <?php if( get_theme_mod('sst_offline_hide') != '') { ?><?php } else { ?>jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');<?php } ?>
                    // animations
                    jQuery('.sst-status-text-offline').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-offline').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                } else {
                    // show if online
                    jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');
                    // animations
                    jQuery('.sst-status-text-live').addClass('sst-current-status');
                    setTimeout(function() {
                        jQuery('.sst-status-text-live').addClass('sst-current-status-active');
                        jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
                    }, 25);
                }
            });
        });
        </script>

	<?php
	}
	add_action('wp_footer','bonfire_sst_header');
    
    //
	// Add 'Settings' link to plugin page
	//
    add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'add_sst_action_links' );
    function add_sst_action_links ( $links ) {
        $mylinks = array(
        '<a href="' . admin_url( 'customize.php?autofocus[panel]=sst_panel' ) . '">Settings</a>',
        '<a href="https://codecanyon.net/item/twitch-status-for-wordpress/21844114?ref=BonfireThemes" target="_blank" style="color:red;">Go Pro!</a>',
        );
    return array_merge( $links, $mylinks );
    }

	//
	// ENQUEUE stream-status-for-twitch.css
	//
	function bonfire_sst_css() {
		wp_register_style( 'bonfire-stream-status-for-twitch-css', plugins_url( '/stream-status-for-twitch.css', __FILE__ ) . '', array(), '1', 'all' );
		wp_enqueue_style( 'bonfire-stream-status-for-twitch-css' );
	}
	add_action( 'wp_enqueue_scripts', 'bonfire_sst_css' );

	//
	// ENQUEUE Google WebFonts
	//
    function bonfire_sst_fonts_url() {
		$font_url = '';

		if ( 'off' !== _x( 'on', 'Google font: on or off', 'stream-status-for-twitch' ) ) {
			$font_url = add_query_arg( 'family', urlencode( 'Roboto:500' ), "//fonts.googleapis.com/css" );
		}
		return $font_url;
	}
	function bonfire_sst_scripts() {
		wp_enqueue_style( 'stream-status-for-twitch-fonts', bonfire_sst_fonts_url(), array(), '1.0.0' );
	}
	add_action( 'wp_enqueue_scripts', 'bonfire_sst_scripts' );
    
    //
	// Translation-ready
	//
    function sst_load_plugin_textdomain() {
        load_plugin_textdomain( 'stream-status-for-twitch', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
    }
    add_action( 'plugins_loaded', 'sst_load_plugin_textdomain' );
    
    //
	// Widget
	//
    class sst_widget extends WP_Widget {
        // Main constructor
        public function __construct() {
            parent::__construct(
                'sst_widget',
                __( 'Stream Status for Twitch', 'sst' ),
                array(
                    'description' => esc_html__( 'Set up channel under Appearance > Customize > Stream Status for Twitch Plugin', 'sst' ),
                    'customize_selective_refresh' => true,
                )
            );
        }
        // The widget form (for the backend)
        public function form( $instance ) {
            // widget defaults
            $defaults = array(
                'title'    => '',
            );
            
            // Parse current settings with defaults
            extract( wp_parse_args( ( array ) $instance, $defaults ) ); ?>

            <!-- Widget title -->
            <p>
                <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Widget Title', 'sst' ); ?></label>
                <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
            </p>

        <?php }
        // Update widget settings
        public function update( $new_instance, $old_instance ) {
            $instance = $old_instance;
            $instance['title']    = isset( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
            return $instance;
        }
        // Display the widget
        public function widget( $args, $instance ) {
            extract( $args );
            // Check the widget options
            $title    = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : '';
            echo $before_widget;
            // Display the widget on the front end
                // Display widget title if defined ?>
                <div class="sst-main-widget-wrapper">
                    <?php if ( $title ) {
                        echo $before_title . $title . $after_title;
                    } ?>
                    <div class="sst-widget-wrapper">
                        <?php include( plugin_dir_path( __FILE__ ) . 'include.php'); ?>
                    </div>
                </div>
            <?php echo $after_widget;
        }
    }
    // Register the widget
    function sst_register_channels_widget() {
        register_widget( 'sst_widget' );
    }
    add_action( 'widgets_init', 'sst_register_channels_widget' );

	//
	// Insert customization options into the header
	//
	function bonfire_sst_customize() {
	?>
		<!-- BEGIN CUSTOM COLORS (WP THEME CUSTOMIZER) -->
        <style>
        /* background color */
		.sst-status-wrapper { background-color:<?php echo get_theme_mod('sst_background_color'); ?>; }
        /* status text color */
        .sst-status-text-live,
        .sst-status-text-offline { color:<?php echo get_theme_mod('sst_status_text_color'); ?>; }
        /* status text hover */
        .sst-main-wrapper:hover .sst-status-text-live span,
        .sst-main-wrapper:hover .sst-status-text-offline span { color:<?php echo get_theme_mod('sst_status_text_hover_color'); ?>; }
        /* Twitch icon color */
        .sst-icon-twitch { color:<?php echo get_theme_mod('sst_twitch_icon_color'); ?>; }
        /* Twitch icon background color */
        .sst-twitch-logo-wrapper { background-color:<?php echo get_theme_mod('sst_twitch_icon_background_color'); ?>; }
        .sst-status-wrapper { border-color:<?php echo get_theme_mod('sst_twitch_icon_background_color'); ?>; }
        
        /* rounded corners */
        <?php if( get_theme_mod('sst_rounded_corners') != '') { ?>
        /* left positioning */
        .sst-twitch-logo-wrapper {
            border-top-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        .sst-status-wrapper {
            border-top-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        /* right positioning */
        <?php $bonfire_sst_placement_horizontal = get_theme_mod('sst_placement_horizontal'); if($bonfire_sst_placement_horizontal != '') { switch ($bonfire_sst_placement_horizontal) { case 'right': ?>
        .sst-twitch-logo-wrapper {
            border-top-left-radius:0px;
            border-bottom-left-radius:0px;
            border-top-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        .sst-status-wrapper {
            border-top-right-radius:0px;
            border-bottom-right-radius:0px;
            border-top-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        <?php break; } } ?>
        <?php } ?>
        
        /* larger design */
        <?php if( get_theme_mod('sst_larger_design') != '') { ?>
        .sst-main-wrapper {
            height:45px;
        }
        .sst-twitch-logo-wrapper {
            width:45px;
            height:45px;
        }
        .sst-icon-twitch {
            top:12px;
            left:12px;
            font-size:22px;
        }
        .sst-twitch-logo-wrapper::after {
            width:45x;
        }
        .sst-status-wrapper {
            left:45px;
            height:45px;
        }
        .sst-widget-wrapper .sst-status-wrapper {
            width:calc(100% - 47px);
        }
        .sst-status-text-live,
        .sst-status-text-offline {
            font-size:13px;
        
            -webkit-transform:translateY(0);
            -moz-transform:translateY(0);
            transform:translateY(0);
        }
        <?php } ?>
        
        /* absolute positioning */
        <?php if( get_theme_mod('sst_absolute_position') != '') { ?>
        .sst-main-wrapper { position:absolute; }
        <?php } ?>
        
        /* distances (if at top) */
        .sst-main-wrapper {
            top:<?php echo get_theme_mod('sst_vertical_distance'); ?>px;
            left:<?php echo get_theme_mod('sst_horizontal_distance'); ?>px;
        }
        
        /* bottom placement + distances */
        <?php $bonfire_sst_placement = get_theme_mod('sst_placement'); if($bonfire_sst_placement != '') { switch ($bonfire_sst_placement) { case 'bottom': ?>
        .sst-main-wrapper {
            top:auto;
            bottom:<?php if( get_theme_mod('sst_vertical_distance') != '') { ?><?php echo get_theme_mod('sst_vertical_distance'); ?><?php } else { ?>25<?php } ?>px;
        }
        <?php break; } } ?>

        /* right placement + distances */
        <?php $bonfire_sst_placement_horizontal = get_theme_mod('sst_placement_horizontal'); if($bonfire_sst_placement_horizontal != '') { switch ($bonfire_sst_placement_horizontal) { case 'right': ?>
        .sst-main-wrapper {
            left:auto;
            right:<?php if( get_theme_mod('sst_horizontal_distance') != '') { ?><?php echo get_theme_mod('sst_horizontal_distance'); ?><?php } else { ?>25<?php } ?>px;
        }
        .sst-status-wrapper {
            left:auto;
            <?php if( get_theme_mod('sst_larger_design') != '') { ?>right:45px;<?php } else { ?>right:32px;<?php } ?>
            border-right:none;
            border-left-width:2px;
            
            -webkit-transform-origin:right top;
            -moz-transform-origin:right top;
            transform-origin:right top;
        }
        .sst-twitch-logo-wrapper { right:0; }
        <?php break; } } ?>
        
        /* disable animation */
        <?php if( get_theme_mod('sst_disable_animation') != '') { ?>
        .sst-status-wrapper {
            -webkit-transform:scaleX(1);
            -moz-transform:scaleX(1);
            transform:scaleX(1);
        }
        .sst-status-text-live,
        .sst-status-text-offline {
            opacity:1;
        }
        <?php } ?>
        
        /* no status text underline */
        <?php if( get_theme_mod('sst_no_underline') != '') { ?>
        .sst-main-wrapper:hover .sst-status-text-live span,
        .sst-main-wrapper:hover .sst-status-text-offline span { text-decoration:none; }
        <?php } ?>
        
        /* hide between resolutions */
		@media ( min-width:<?php echo get_theme_mod('sst_smaller_than'); ?>px) and (max-width:<?php echo get_theme_mod('sst_larger_than'); ?>px) {
			.sst-main-wrapper { display:none !important; }
		}
		</style>
		<!-- END CUSTOM COLORS (WP THEME CUSTOMIZER) -->
	
	<?php
	}
	add_action('wp_head','bonfire_sst_customize');

?>

#10

Meanwhile we have found a programmer who has solved problem with a curl solution as following:

<?php if( get_theme_mod('sst_channel_name') != '') { 
		
		$channel=get_theme_mod('sst_channel_name');
		$url0="https://api.twitch.tv/helix/users?login=".$channel;
		
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			'Accept: application/vnd.twitchtv.v5+json',
			'Client-ID: ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
		));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		
		curl_setopt($ch, CURLOPT_URL,$url0);
		$result=curl_exec($ch);
		$array0=json_decode($result, true);

		$channel_id=$array0["data"][0]["id"];
		$url1="https://api.twitch.tv/kraken/streams/".$channel_id;
		
		curl_setopt($ch, CURLOPT_URL,$url1);
		$result=curl_exec($ch);
		$array1=json_decode($result, true);
		
		?>


<?php
		if ($array1["stream"]==NULL) {
			if( get_theme_mod('sst_offline_hide') != '') { ?><?php } else { ?>jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');<?php } ?>
			// animations
			jQuery('.sst-status-text-offline').addClass('sst-current-status');
			setTimeout(function() {
				jQuery('.sst-status-text-offline').addClass('sst-current-status-active');
				jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
			}, 25);
		<?php
		} else {
		?>

It seems to work just as well and ultimately have the same effect or are there any disadvantages or unwanted side effects? I don’t hope so…


#11

That’s still using v5, which is a deprecated API and will be removed at some point in the future. If you’re going to update your code anyway you should update to the new API, Helix, to future proof your app or otherwise you’ll just be going through all of this again at a later date anyway.


#12

So, what whould you suggest? Would you be prepared to fix it to the correct API if I send you the new files with the full code?


#13

I’m not a PHP dev, I can’t help with that.


#14

I covered the correct URLs/calls above ^^

<?php if( get_theme_mod('sst_channel_name') != '') { 
        
        $url="https://api.twitch.tv/helix/streams?user_login=".get_theme_mod('sst_channel_name');
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Client-ID: ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
        ));
        $result=curl_exec($ch);
        $array1=json_decode($result, true);


#15

Sorry but your changes don’t work. The status stays offline when using your code. Here is the full content of the new file:

<?php
/*
Plugin Name: Stream Status for Twitch
Plugin URI: http://bonfirethemes.com/
Description: Setup and customize under Appearance → Customize → Stream Status for Twitch Plugin
Version: 1.4a
Author: Bonfire Themes
Author URI: http://bonfirethemes.com/
Text Domain: stream-status-for-twitch
Domain Path: /languages
License: GPL2
*/

    //
	// WORDPRESS LIVE CUSTOMIZER
	//
	function bonfire_sst_theme_customizer( $wp_customize ) {
	
        //
        // ADD "Stream Status for Twitch Plugin" PANEL TO LIVE CUSTOMIZER 
        //
        $wp_customize->add_panel('sst_panel', array('title' => __('Stream Status for Twitch Plugin','stream-status-for-twitch'),'priority' => 10,));

        //
        // ADD "Main Settings" SECTION TO "Stream Status for Twitch Plugin" PANEL 
        //
        $wp_customize->add_section('sst_main_section',array('title' => __( 'Main Settings','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 1));

        /* channel name */
        $wp_customize->add_setting('sst_channel_name',array('default' => '','sanitize_callback' => 'sanitize_sst_channel_name',));
        function sanitize_sst_channel_name($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_channel_name',array('type' => 'text','label' => __('Channel name','stream-status-for-twitch'),'description' => __('Enter your Twitch channel name in order to display stream status.','stream-status-for-twitch'),'section' => 'sst_main_section',));
		
        /* custom url */
        $wp_customize->add_setting('sst_channel_url',array('default' => '','sanitize_callback' => 'sanitize_sst_channel_url',));
        function sanitize_sst_channel_url($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_channel_url',array('type' => 'text','label' => __('Channel URL','stream-status-for-twitch'),'description' => __('Enter your Stream URL (optional).','stream-status-for-twitch'),'section' => 'sst_main_section',));
        
        /* hide if feed offline */
        $wp_customize->add_setting('sst_offline_hide',array('sanitize_callback' => 'sanitize_sst_offline_hide',));
        function sanitize_sst_offline_hide( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_offline_hide',array('type' => 'checkbox','label' => __('Hide when offline','stream-status-for-twitch'), 'description' => __('If checked, the stream status will be shown only when channel is actively streaming.','stream-status-for-twitch'), 'section' => 'sst_main_section',));
        
        /* open in new window */
        $wp_customize->add_setting('sst_new_window',array('sanitize_callback' => 'sanitize_sst_new_window',));
        function sanitize_sst_new_window( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_new_window',array('type' => 'checkbox','label' => __('Open in new window','stream-status-for-twitch'),'description' => __('If unchecked, Twitch will open in the same window.','stream-status-for-twitch'), 'section' => 'sst_main_section',));
        
        /* live text */
        $wp_customize->add_setting('sst_live_text',array('default' => '','sanitize_callback' => 'sanitize_sst_live_text',));
        function sanitize_sst_live_text($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_live_text',array('type' => 'text','label' => __('Status text if stream is live','stream-status-for-twitch'),'description' => __('If empty, defaults to "LIVE NOW! CLICK TO VIEW."','stream-status-for-twitch'),'section' => 'sst_main_section',));
        
        /* offline text */
        $wp_customize->add_setting('sst_offline_text',array('default' => '','sanitize_callback' => 'sanitize_sst_offline_text',));
        function sanitize_sst_offline_text($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_offline_text',array('type' => 'text','label' => __('Status text if stream is offline','stream-status-for-twitch'),'description' => __('If empty, defaults to "CURRENTLY OFFLINE".','stream-status-for-twitch'),'section' => 'sst_main_section',));
        
        //
        // ADD "Positioning" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_positioning_section',array('title' => __( 'Positioning','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 2));
        
        /* absolute position */
        $wp_customize->add_setting('sst_absolute_position',array('sanitize_callback' => 'sanitize_sst_absolute_position',));
        function sanitize_sst_absolute_position( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_absolute_position',array('type' => 'checkbox','label' => __('Absolute positioning','stream-status-for-twitch'),'description' => __('If unchecked, fixed positioning is applied.','stream-status-for-twitch'), 'section' => 'sst_positioning_section',));
        
        /* vertical placemenet */
        $wp_customize->add_setting('sst_placement',array(
            'default' => 'top',
        ));
        $wp_customize->add_control('sst_placement',array(
            'type' => 'select',
            'label' => __('Vertical placement','stream-status-for-twitch'),
            'section' => 'sst_positioning_section',
            'choices' => array(
                'top' => __('Top','stream-status-for-twitch'),
                'bottom' => __('Bottom','stream-status-for-twitch'),
        ),
        ));
        
        /* horizontal placemenet */
        $wp_customize->add_setting('sst_placement_horizontal',array(
            'default' => 'left',
        ));
        $wp_customize->add_control('sst_placement_horizontal',array(
            'type' => 'select',
            'label' => __('Horizontal placement','stream-status-for-twitch'),
            'section' => 'sst_positioning_section',
            'choices' => array(
                'left' => __('Left','stream-status-for-twitch'),
                'right' => __('Right','stream-status-for-twitch'),
        ),
        ));
        
        /* top/bottom distance */
        $wp_customize->add_setting('sst_vertical_distance',array('default' => '','sanitize_callback' => 'sanitize_sst_vertical_distance',));
        function sanitize_sst_vertical_distance($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_vertical_distance',array('type' => 'text','label' => __('Top/bottom distance (in pixels)','stream-status-for-twitch'),'description' => __('Example: 50 (if empty, defaults to 25).','stream-status-for-twitch'),'section' => 'sst_positioning_section',));
        
        /* left distance */
        $wp_customize->add_setting('sst_horizontal_distance',array('default' => '','sanitize_callback' => 'sanitize_sst_horizontal_distance',));
        function sanitize_sst_horizontal_distance($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_horizontal_distance',array('type' => 'text','label' => __('Left/right distance (in pixels)','stream-status-for-twitch'),'description' => __('Example: 50 (if empty, defaults to 25).','stream-status-for-twitch'),'section' => 'sst_positioning_section',));
        
        //
        // ADD "Customization" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_customization_section',array('title' => __( 'Customization','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 3));
        
        /* background color */
        $wp_customize->add_setting('sst_background_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_background_color',array(
            'label'=>__('Background','stream-status-for-twitch'),'settings'=>'sst_background_color','section'=>'sst_customization_section')
        ));
        
        /* status text color */
        $wp_customize->add_setting('sst_status_text_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_status_text_color',array(
            'label'=>__('Status text','stream-status-for-twitch'),'settings'=>'sst_status_text_color','section'=>'sst_customization_section')
        ));
        
        /* status text hover color */
        $wp_customize->add_setting('sst_status_text_hover_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_status_text_hover_color',array(
            'label'=>__('Status text (hover)','stream-status-for-twitch'),'settings'=>'sst_status_text_hover_color','section'=>'sst_customization_section')
        ));
        
        /* Twitch icon color */
        $wp_customize->add_setting('sst_twitch_icon_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_twitch_icon_color',array(
            'label'=>__('Twitch icon','stream-status-for-twitch'),'settings'=>'sst_twitch_icon_color','section'=>'sst_customization_section')
        ));
        
        /* Twitch icon background color */
        $wp_customize->add_setting('sst_twitch_icon_background_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_twitch_icon_background_color',array(
            'label'=>__('Twitch icon background','stream-status-for-twitch'),'settings'=>'sst_twitch_icon_background_color','section'=>'sst_customization_section')
        ));
        
        /* rounded corners */
        $wp_customize->add_setting('sst_rounded_corners',array('default' => '','sanitize_callback' => 'sanitize_sst_rounded_corners',));
        function sanitize_sst_rounded_corners($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_rounded_corners',array('type' => 'text','label' => __('Rounded corners (in pixels)','stream-status-for-twitch'),'description' => __('Example: 5 (if empty, defaults to 0).','stream-status-for-twitch'),'section' => 'sst_customization_section',));
        
        /* larger design */
        $wp_customize->add_setting('sst_larger_design',array('sanitize_callback' => 'sanitize_sst_larger_design',));
        function sanitize_sst_larger_design( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_larger_design',array('type' => 'checkbox','label' => __('Larger design','stream-status-for-twitch'),'description' => __('When checked, the status indicator will look a bit larger.','stream-status-for-twitch'), 'section' => 'sst_customization_section',));
        
        /* disable status text underline */
        $wp_customize->add_setting('sst_no_underline',array('sanitize_callback' => 'sanitize_sst_no_underline',));
        function sanitize_sst_no_underline( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_no_underline',array('type' => 'checkbox','label' => __('Disable status text underline','stream-status-for-twitch'),'description' => __('When checked, status text will not be underlined when hovered.','stream-status-for-twitch'), 'section' => 'sst_customization_section',));
        
        //
        // ADD "Misc" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_misc_section',array('title' => __( 'Misc','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 3));
        
        /* disable animation */
        $wp_customize->add_setting('sst_disable_animation',array('sanitize_callback' => 'sanitize_sst_disable_animation',));
        function sanitize_sst_disable_animation( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_disable_animation',array('type' => 'checkbox','label' => __('Disable appearance animation','stream-status-for-twitch'), 'section' => 'sst_misc_section',));
        
        /* smaller than */
        $wp_customize->add_setting('sst_smaller_than',array('sanitize_callback' => 'sanitize_sst_smaller_than',));
        function sanitize_sst_smaller_than($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_smaller_than',array(
            'type' => 'text',
            'label' => __('Hide at certain width/resolution','stream-status-for-twitch'),
            'description' => __('<strong>Example #1:</strong> If you want to show the stream status on desktop only, enter the values as 0 and 500. <br><br> <strong>Example #2:</strong> If you want to show the stream status on mobile only, enter the values as 500 and 5000. <br><br> Feel free to experiment with your own values to get the result that is right for you. If fields are empty, the stream status will be visible at all browser widths and resolutions. <br><br> Hide stream status if browser width or screen resolution (in pixels) is between...','stream-status-for-twitch'),
            'section' => 'sst_misc_section',
        ));
        
        /* larger than */
        $wp_customize->add_setting('sst_larger_than',array('sanitize_callback' => 'sanitize_sst_larger_than',));
        function sanitize_sst_larger_than($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_larger_than',array(
            'type' => 'text',
            'description' => __('..and:','stream-status-for-twitch'),
            'section' => 'sst_misc_section',
        ));
        
        //
        // ADD "Go Pro!" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_gopro_section',array('title' => __( 'Go Pro!','stream-status-for-twitch' ), 'panel' => 'sst_panel','priority' => 10));

        require_once 'sst_custom_controls.php';
        /* custom notice custom contol */
        $wp_customize->add_setting('sst_custom_info', array(
            'default'           => '',
            'sanitize_callback' => 'sst_text_sanitization',
        ));
        $wp_customize->add_control(new Info_Custom_Control_sst($wp_customize, 'sst_custom_info', array(
            'settings'		=> 'sst_custom_info',
            'section'  		=> 'sst_gopro_section',
        )));
        
        //
        // ADD "Need a video game theme?" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_theme_section',array('title' => __( 'Need a video game theme?','stream-status-for-twitch' ), 'panel' => 'sst_panel','priority' => 10));

        require_once 'sst_custom_controls.php';
        /* custom notice custom contol */
        $wp_customize->add_setting('sst_custom_info_theme', array(
            'default'           => '',
            'sanitize_callback' => 'sst_text_sanitization',
        ));
        $wp_customize->add_control(new Info_Custom_Control_sst_theme($wp_customize, 'sst_custom_info_theme', array(
            'settings'		=> 'sst_custom_info_theme',
            'section'  		=> 'sst_theme_section',
        )));

	}
	add_action('customize_register', 'bonfire_sst_theme_customizer');

	//
	// Add stream status to theme
	//
	
	function bonfire_sst_header() {
	?>

        <!-- BEGIN MAIN WRAPPER (show only if Twitch channel name entered) -->
        <?php if( get_theme_mod('sst_channel_name') != '') { 
		
        $url="https://api.twitch.tv/helix/streams?user_login=".get_theme_mod('sst_channel_name');
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Client-ID: ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
        ));
        $result=curl_exec($ch);
        $array1=json_decode($result, true);

		$channel_id=$array0["data"][0]["id"];
		$url1="https://api.twitch.tv/kraken/streams/".$channel_id;
		
		curl_setopt($ch, CURLOPT_URL,$url1);
		$result=curl_exec($ch);
		$array1=json_decode($result, true);
		
		?>
        <div class="sst-main-wrapper">
            <?php include( plugin_dir_path( __FILE__ ) . 'include.php'); ?>
        </div>
        <?php } ?>
        <!-- END MAIN WRAPPER (show only if Twitch channel name entered) -->
        
        <script>
        jQuery('.sst-twitch').each(function () {
            var nickname = jQuery(this).data('nickname');
			
		<?php
		if ($array1["stream"]==NULL) {
			if( get_theme_mod('sst_offline_hide') != '') { ?><?php } else { ?>jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');<?php } ?>
			// animations
			jQuery('.sst-status-text-offline').addClass('sst-current-status');
			setTimeout(function() {
				jQuery('.sst-status-text-offline').addClass('sst-current-status-active');
				jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
			}, 25);
		<?php
		} else {
		?>
			// show if online
			jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');
			// animations
			jQuery('.sst-status-text-live').addClass('sst-current-status');
			setTimeout(function() {
				jQuery('.sst-status-text-live').addClass('sst-current-status-active');
				jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
			}, 25);
		<?php
		}
		?>
        });
        </script>

	<?php
	}
	add_action('wp_footer','bonfire_sst_header');
    
    //
	// Add 'Settings' link to plugin page
	//
    add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'add_sst_action_links' );
    function add_sst_action_links ( $links ) {
        $mylinks = array(
        '<a href="' . admin_url( 'customize.php?autofocus[panel]=sst_panel' ) . '">Settings</a>',
        '<a href="https://codecanyon.net/item/twitch-status-for-wordpress/21844114?ref=BonfireThemes" target="_blank" style="color:red;">Go Pro!</a>',
        );
    return array_merge( $links, $mylinks );
    }

	//
	// ENQUEUE stream-status-for-twitch.css
	//
	function bonfire_sst_css() {
		wp_register_style( 'bonfire-stream-status-for-twitch-css', plugins_url( '/stream-status-for-twitch.css', __FILE__ ) . '', array(), '1', 'all' );
		wp_enqueue_style( 'bonfire-stream-status-for-twitch-css' );
	}
	add_action( 'wp_enqueue_scripts', 'bonfire_sst_css' );

	//
	// ENQUEUE Google WebFonts
	//
    function bonfire_sst_fonts_url() {
		$font_url = '';

		if ( 'off' !== _x( 'on', 'Google font: on or off', 'stream-status-for-twitch' ) ) {
			$font_url = add_query_arg( 'family', urlencode( 'Roboto:500' ), "//fonts.googleapis.com/css" );
		}
		return $font_url;
	}
	function bonfire_sst_scripts() {
		wp_enqueue_style( 'stream-status-for-twitch-fonts', bonfire_sst_fonts_url(), array(), '1.0.0' );
	}
	add_action( 'wp_enqueue_scripts', 'bonfire_sst_scripts' );
    
    //
	// Translation-ready
	//
    function sst_load_plugin_textdomain() {
        load_plugin_textdomain( 'stream-status-for-twitch', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
    }
    add_action( 'plugins_loaded', 'sst_load_plugin_textdomain' );
    
    //
	// Widget
	//
    class sst_widget extends WP_Widget {
        // Main constructor
        public function __construct() {
            parent::__construct(
                'sst_widget',
                __( 'Stream Status for Twitch', 'sst' ),
                array(
                    'description' => esc_html__( 'Set up channel under Appearance > Customize > Stream Status for Twitch Plugin', 'sst' ),
                    'customize_selective_refresh' => true,
                )
            );
        }
        // The widget form (for the backend)
        public function form( $instance ) {
            // widget defaults
            $defaults = array(
                'title'    => '',
            );
            
            // Parse current settings with defaults
            extract( wp_parse_args( ( array ) $instance, $defaults ) ); ?>

            <!-- Widget title -->
            <p>
                <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Widget Title', 'sst' ); ?></label>
                <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
            </p>

        <?php }
        // Update widget settings
        public function update( $new_instance, $old_instance ) {
            $instance = $old_instance;
            $instance['title']    = isset( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
            return $instance;
        }
        // Display the widget
        public function widget( $args, $instance ) {
            extract( $args );
            // Check the widget options
            $title    = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : '';
            echo $before_widget;
            // Display the widget on the front end
                // Display widget title if defined ?>
                <div class="sst-main-widget-wrapper">
                    <?php if ( $title ) {
                        echo $before_title . $title . $after_title;
                    } ?>
                    <div class="sst-widget-wrapper">
                        <?php include( plugin_dir_path( __FILE__ ) . 'include.php'); ?>
                    </div>
                </div>
            <?php echo $after_widget;
        }
    }
    // Register the widget
    function sst_register_channels_widget() {
        register_widget( 'sst_widget' );
    }
    add_action( 'widgets_init', 'sst_register_channels_widget' );

	//
	// Insert customization options into the header
	//
	function bonfire_sst_customize() {
	?>
		<!-- BEGIN CUSTOM COLORS (WP THEME CUSTOMIZER) -->
        <style>
        /* background color */
		.sst-status-wrapper { background-color:<?php echo get_theme_mod('sst_background_color'); ?>; }
        /* status text color */
        .sst-status-text-live,
        .sst-status-text-offline { color:<?php echo get_theme_mod('sst_status_text_color'); ?>; }
        /* status text hover */
        .sst-main-wrapper:hover .sst-status-text-live span,
        .sst-main-wrapper:hover .sst-status-text-offline span { color:<?php echo get_theme_mod('sst_status_text_hover_color'); ?>; }
        /* Twitch icon color */
        .sst-icon-twitch { color:<?php echo get_theme_mod('sst_twitch_icon_color'); ?>; }
        /* Twitch icon background color */
        .sst-twitch-logo-wrapper { background-color:<?php echo get_theme_mod('sst_twitch_icon_background_color'); ?>; }
        .sst-status-wrapper { border-color:<?php echo get_theme_mod('sst_twitch_icon_background_color'); ?>; }
        
        /* rounded corners */
        <?php if( get_theme_mod('sst_rounded_corners') != '') { ?>
        /* left positioning */
        .sst-twitch-logo-wrapper {
            border-top-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        .sst-status-wrapper {
            border-top-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        /* right positioning */
        <?php $bonfire_sst_placement_horizontal = get_theme_mod('sst_placement_horizontal'); if($bonfire_sst_placement_horizontal != '') { switch ($bonfire_sst_placement_horizontal) { case 'right': ?>
        .sst-twitch-logo-wrapper {
            border-top-left-radius:0px;
            border-bottom-left-radius:0px;
            border-top-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        .sst-status-wrapper {
            border-top-right-radius:0px;
            border-bottom-right-radius:0px;
            border-top-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        <?php break; } } ?>
        <?php } ?>
        
        /* larger design */
        <?php if( get_theme_mod('sst_larger_design') != '') { ?>
        .sst-main-wrapper {
            height:45px;
        }
        .sst-twitch-logo-wrapper {
            width:45px;
            height:45px;
        }
        .sst-icon-twitch {
            top:12px;
            left:12px;
            font-size:22px;
        }
        .sst-twitch-logo-wrapper::after {
            width:45x;
        }
        .sst-status-wrapper {
            left:45px;
            height:45px;
        }
        .sst-widget-wrapper .sst-status-wrapper {
            width:calc(100% - 47px);
        }
        .sst-status-text-live,
        .sst-status-text-offline {
            font-size:13px;
        
            -webkit-transform:translateY(0);
            -moz-transform:translateY(0);
            transform:translateY(0);
        }
        <?php } ?>
        
        /* absolute positioning */
        <?php if( get_theme_mod('sst_absolute_position') != '') { ?>
        .sst-main-wrapper { position:absolute; }
        <?php } ?>
        
        /* distances (if at top) */
        .sst-main-wrapper {
            top:<?php echo get_theme_mod('sst_vertical_distance'); ?>px;
            left:<?php echo get_theme_mod('sst_horizontal_distance'); ?>px;
        }
        
        /* bottom placement + distances */
        <?php $bonfire_sst_placement = get_theme_mod('sst_placement'); if($bonfire_sst_placement != '') { switch ($bonfire_sst_placement) { case 'bottom': ?>
        .sst-main-wrapper {
            top:auto;
            bottom:<?php if( get_theme_mod('sst_vertical_distance') != '') { ?><?php echo get_theme_mod('sst_vertical_distance'); ?><?php } else { ?>25<?php } ?>px;
        }
        <?php break; } } ?>

        /* right placement + distances */
        <?php $bonfire_sst_placement_horizontal = get_theme_mod('sst_placement_horizontal'); if($bonfire_sst_placement_horizontal != '') { switch ($bonfire_sst_placement_horizontal) { case 'right': ?>
        .sst-main-wrapper {
            left:auto;
            right:<?php if( get_theme_mod('sst_horizontal_distance') != '') { ?><?php echo get_theme_mod('sst_horizontal_distance'); ?><?php } else { ?>25<?php } ?>px;
        }
        .sst-status-wrapper {
            left:auto;
            <?php if( get_theme_mod('sst_larger_design') != '') { ?>right:45px;<?php } else { ?>right:32px;<?php } ?>
            border-right:none;
            border-left-width:2px;
            
            -webkit-transform-origin:right top;
            -moz-transform-origin:right top;
            transform-origin:right top;
        }
        .sst-twitch-logo-wrapper { right:0; }
        <?php break; } } ?>
        
        /* disable animation */
        <?php if( get_theme_mod('sst_disable_animation') != '') { ?>
        .sst-status-wrapper {
            -webkit-transform:scaleX(1);
            -moz-transform:scaleX(1);
            transform:scaleX(1);
        }
        .sst-status-text-live,
        .sst-status-text-offline {
            opacity:1;
        }
        <?php } ?>
        
        /* no status text underline */
        <?php if( get_theme_mod('sst_no_underline') != '') { ?>
        .sst-main-wrapper:hover .sst-status-text-live span,
        .sst-main-wrapper:hover .sst-status-text-offline span { text-decoration:none; }
        <?php } ?>
        
        /* hide between resolutions */
		@media ( min-width:<?php echo get_theme_mod('sst_smaller_than'); ?>px) and (max-width:<?php echo get_theme_mod('sst_larger_than'); ?>px) {
			.sst-main-wrapper { display:none !important; }
		}
		</style>
		<!-- END CUSTOM COLORS (WP THEME CUSTOMIZER) -->
	
	<?php
	}
	add_action('wp_head','bonfire_sst_customize');

?>

In my view, it makes no sense to publish any code snippets, where you do not know exactly where they belong. If you really want to help us then please with specific information, where to change which lines or the complete code from the PHP file.


#16

Because you didn’t listen

The code I pasted last replaces the WHOLE code from your paste. You are not learning. You are expecting someone else to just fix someone else plugin.

We have given the documentation, which covers the solution on how to repair the code.

This is neither a Wordpress or PHP support forum, which was why we linked to the documentation to start with.

<?php
/*
Plugin Name: Stream Status for Twitch
Plugin URI: http://bonfirethemes.com/
Description: Setup and customize under Appearance → Customize → Stream Status for Twitch Plugin
Version: 1.4a
Author: Bonfire Themes
Author URI: http://bonfirethemes.com/
Text Domain: stream-status-for-twitch
Domain Path: /languages
License: GPL2
*/

    //
	// WORDPRESS LIVE CUSTOMIZER
	//
	function bonfire_sst_theme_customizer( $wp_customize ) {
	
        //
        // ADD "Stream Status for Twitch Plugin" PANEL TO LIVE CUSTOMIZER 
        //
        $wp_customize->add_panel('sst_panel', array('title' => __('Stream Status for Twitch Plugin','stream-status-for-twitch'),'priority' => 10,));

        //
        // ADD "Main Settings" SECTION TO "Stream Status for Twitch Plugin" PANEL 
        //
        $wp_customize->add_section('sst_main_section',array('title' => __( 'Main Settings','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 1));

        /* channel name */
        $wp_customize->add_setting('sst_channel_name',array('default' => '','sanitize_callback' => 'sanitize_sst_channel_name',));
        function sanitize_sst_channel_name($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_channel_name',array('type' => 'text','label' => __('Channel name','stream-status-for-twitch'),'description' => __('Enter your Twitch channel name in order to display stream status.','stream-status-for-twitch'),'section' => 'sst_main_section',));
		
        /* custom url */
        $wp_customize->add_setting('sst_channel_url',array('default' => '','sanitize_callback' => 'sanitize_sst_channel_url',));
        function sanitize_sst_channel_url($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_channel_url',array('type' => 'text','label' => __('Channel URL','stream-status-for-twitch'),'description' => __('Enter your Stream URL (optional).','stream-status-for-twitch'),'section' => 'sst_main_section',));
        
        /* hide if feed offline */
        $wp_customize->add_setting('sst_offline_hide',array('sanitize_callback' => 'sanitize_sst_offline_hide',));
        function sanitize_sst_offline_hide( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_offline_hide',array('type' => 'checkbox','label' => __('Hide when offline','stream-status-for-twitch'), 'description' => __('If checked, the stream status will be shown only when channel is actively streaming.','stream-status-for-twitch'), 'section' => 'sst_main_section',));
        
        /* open in new window */
        $wp_customize->add_setting('sst_new_window',array('sanitize_callback' => 'sanitize_sst_new_window',));
        function sanitize_sst_new_window( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_new_window',array('type' => 'checkbox','label' => __('Open in new window','stream-status-for-twitch'),'description' => __('If unchecked, Twitch will open in the same window.','stream-status-for-twitch'), 'section' => 'sst_main_section',));
        
        /* live text */
        $wp_customize->add_setting('sst_live_text',array('default' => '','sanitize_callback' => 'sanitize_sst_live_text',));
        function sanitize_sst_live_text($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_live_text',array('type' => 'text','label' => __('Status text if stream is live','stream-status-for-twitch'),'description' => __('If empty, defaults to "LIVE NOW! CLICK TO VIEW."','stream-status-for-twitch'),'section' => 'sst_main_section',));
        
        /* offline text */
        $wp_customize->add_setting('sst_offline_text',array('default' => '','sanitize_callback' => 'sanitize_sst_offline_text',));
        function sanitize_sst_offline_text($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_offline_text',array('type' => 'text','label' => __('Status text if stream is offline','stream-status-for-twitch'),'description' => __('If empty, defaults to "CURRENTLY OFFLINE".','stream-status-for-twitch'),'section' => 'sst_main_section',));
        
        //
        // ADD "Positioning" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_positioning_section',array('title' => __( 'Positioning','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 2));
        
        /* absolute position */
        $wp_customize->add_setting('sst_absolute_position',array('sanitize_callback' => 'sanitize_sst_absolute_position',));
        function sanitize_sst_absolute_position( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_absolute_position',array('type' => 'checkbox','label' => __('Absolute positioning','stream-status-for-twitch'),'description' => __('If unchecked, fixed positioning is applied.','stream-status-for-twitch'), 'section' => 'sst_positioning_section',));
        
        /* vertical placemenet */
        $wp_customize->add_setting('sst_placement',array(
            'default' => 'top',
        ));
        $wp_customize->add_control('sst_placement',array(
            'type' => 'select',
            'label' => __('Vertical placement','stream-status-for-twitch'),
            'section' => 'sst_positioning_section',
            'choices' => array(
                'top' => __('Top','stream-status-for-twitch'),
                'bottom' => __('Bottom','stream-status-for-twitch'),
        ),
        ));
        
        /* horizontal placemenet */
        $wp_customize->add_setting('sst_placement_horizontal',array(
            'default' => 'left',
        ));
        $wp_customize->add_control('sst_placement_horizontal',array(
            'type' => 'select',
            'label' => __('Horizontal placement','stream-status-for-twitch'),
            'section' => 'sst_positioning_section',
            'choices' => array(
                'left' => __('Left','stream-status-for-twitch'),
                'right' => __('Right','stream-status-for-twitch'),
        ),
        ));
        
        /* top/bottom distance */
        $wp_customize->add_setting('sst_vertical_distance',array('default' => '','sanitize_callback' => 'sanitize_sst_vertical_distance',));
        function sanitize_sst_vertical_distance($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_vertical_distance',array('type' => 'text','label' => __('Top/bottom distance (in pixels)','stream-status-for-twitch'),'description' => __('Example: 50 (if empty, defaults to 25).','stream-status-for-twitch'),'section' => 'sst_positioning_section',));
        
        /* left distance */
        $wp_customize->add_setting('sst_horizontal_distance',array('default' => '','sanitize_callback' => 'sanitize_sst_horizontal_distance',));
        function sanitize_sst_horizontal_distance($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_horizontal_distance',array('type' => 'text','label' => __('Left/right distance (in pixels)','stream-status-for-twitch'),'description' => __('Example: 50 (if empty, defaults to 25).','stream-status-for-twitch'),'section' => 'sst_positioning_section',));
        
        //
        // ADD "Customization" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_customization_section',array('title' => __( 'Customization','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 3));
        
        /* background color */
        $wp_customize->add_setting('sst_background_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_background_color',array(
            'label'=>__('Background','stream-status-for-twitch'),'settings'=>'sst_background_color','section'=>'sst_customization_section')
        ));
        
        /* status text color */
        $wp_customize->add_setting('sst_status_text_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_status_text_color',array(
            'label'=>__('Status text','stream-status-for-twitch'),'settings'=>'sst_status_text_color','section'=>'sst_customization_section')
        ));
        
        /* status text hover color */
        $wp_customize->add_setting('sst_status_text_hover_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_status_text_hover_color',array(
            'label'=>__('Status text (hover)','stream-status-for-twitch'),'settings'=>'sst_status_text_hover_color','section'=>'sst_customization_section')
        ));
        
        /* Twitch icon color */
        $wp_customize->add_setting('sst_twitch_icon_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_twitch_icon_color',array(
            'label'=>__('Twitch icon','stream-status-for-twitch'),'settings'=>'sst_twitch_icon_color','section'=>'sst_customization_section')
        ));
        
        /* Twitch icon background color */
        $wp_customize->add_setting('sst_twitch_icon_background_color',array('sanitize_callback'=>'sanitize_hex_color'));
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'sst_twitch_icon_background_color',array(
            'label'=>__('Twitch icon background','stream-status-for-twitch'),'settings'=>'sst_twitch_icon_background_color','section'=>'sst_customization_section')
        ));
        
        /* rounded corners */
        $wp_customize->add_setting('sst_rounded_corners',array('default' => '','sanitize_callback' => 'sanitize_sst_rounded_corners',));
        function sanitize_sst_rounded_corners($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_rounded_corners',array('type' => 'text','label' => __('Rounded corners (in pixels)','stream-status-for-twitch'),'description' => __('Example: 5 (if empty, defaults to 0).','stream-status-for-twitch'),'section' => 'sst_customization_section',));
        
        /* larger design */
        $wp_customize->add_setting('sst_larger_design',array('sanitize_callback' => 'sanitize_sst_larger_design',));
        function sanitize_sst_larger_design( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_larger_design',array('type' => 'checkbox','label' => __('Larger design','stream-status-for-twitch'),'description' => __('When checked, the status indicator will look a bit larger.','stream-status-for-twitch'), 'section' => 'sst_customization_section',));
        
        /* disable status text underline */
        $wp_customize->add_setting('sst_no_underline',array('sanitize_callback' => 'sanitize_sst_no_underline',));
        function sanitize_sst_no_underline( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_no_underline',array('type' => 'checkbox','label' => __('Disable status text underline','stream-status-for-twitch'),'description' => __('When checked, status text will not be underlined when hovered.','stream-status-for-twitch'), 'section' => 'sst_customization_section',));
        
        //
        // ADD "Misc" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_misc_section',array('title' => __( 'Misc','stream-status-for-twitch' ),'panel' => 'sst_panel','priority' => 3));
        
        /* disable animation */
        $wp_customize->add_setting('sst_disable_animation',array('sanitize_callback' => 'sanitize_sst_disable_animation',));
        function sanitize_sst_disable_animation( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } }
        $wp_customize->add_control('sst_disable_animation',array('type' => 'checkbox','label' => __('Disable appearance animation','stream-status-for-twitch'), 'section' => 'sst_misc_section',));
        
        /* smaller than */
        $wp_customize->add_setting('sst_smaller_than',array('sanitize_callback' => 'sanitize_sst_smaller_than',));
        function sanitize_sst_smaller_than($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_smaller_than',array(
            'type' => 'text',
            'label' => __('Hide at certain width/resolution','stream-status-for-twitch'),
            'description' => __('<strong>Example #1:</strong> If you want to show the stream status on desktop only, enter the values as 0 and 500. <br><br> <strong>Example #2:</strong> If you want to show the stream status on mobile only, enter the values as 500 and 5000. <br><br> Feel free to experiment with your own values to get the result that is right for you. If fields are empty, the stream status will be visible at all browser widths and resolutions. <br><br> Hide stream status if browser width or screen resolution (in pixels) is between...','stream-status-for-twitch'),
            'section' => 'sst_misc_section',
        ));
        
        /* larger than */
        $wp_customize->add_setting('sst_larger_than',array('sanitize_callback' => 'sanitize_sst_larger_than',));
        function sanitize_sst_larger_than($input) {return wp_kses_post(force_balance_tags($input));}
        $wp_customize->add_control('sst_larger_than',array(
            'type' => 'text',
            'description' => __('..and:','stream-status-for-twitch'),
            'section' => 'sst_misc_section',
        ));
        
        //
        // ADD "Go Pro!" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_gopro_section',array('title' => __( 'Go Pro!','stream-status-for-twitch' ), 'panel' => 'sst_panel','priority' => 10));

        require_once 'sst_custom_controls.php';
        /* custom notice custom contol */
        $wp_customize->add_setting('sst_custom_info', array(
            'default'           => '',
            'sanitize_callback' => 'sst_text_sanitization',
        ));
        $wp_customize->add_control(new Info_Custom_Control_sst($wp_customize, 'sst_custom_info', array(
            'settings'		=> 'sst_custom_info',
            'section'  		=> 'sst_gopro_section',
        )));
        
        //
        // ADD "Need a video game theme?" SECTION TO "Stream Status for Twitch" PANEL 
        //
        $wp_customize->add_section('sst_theme_section',array('title' => __( 'Need a video game theme?','stream-status-for-twitch' ), 'panel' => 'sst_panel','priority' => 10));

        require_once 'sst_custom_controls.php';
        /* custom notice custom contol */
        $wp_customize->add_setting('sst_custom_info_theme', array(
            'default'           => '',
            'sanitize_callback' => 'sst_text_sanitization',
        ));
        $wp_customize->add_control(new Info_Custom_Control_sst_theme($wp_customize, 'sst_custom_info_theme', array(
            'settings'		=> 'sst_custom_info_theme',
            'section'  		=> 'sst_theme_section',
        )));

	}
	add_action('customize_register', 'bonfire_sst_theme_customizer');

	//
	// Add stream status to theme
	//
	
	function bonfire_sst_header() {
	?>

        <!-- BEGIN MAIN WRAPPER (show only if Twitch channel name entered) -->
        <?php if( get_theme_mod('sst_channel_name') != '') { 
		
        $url="https://api.twitch.tv/helix/streams?user_login=".get_theme_mod('sst_channel_name');
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Client-ID: ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
        ));
        $result=curl_exec($ch);
        $array1=json_decode($result, true);

		?>
        <div class="sst-main-wrapper">
            <?php include( plugin_dir_path( __FILE__ ) . 'include.php'); ?>
        </div>
        <?php } ?>
        <!-- END MAIN WRAPPER (show only if Twitch channel name entered) -->
        
        <script>
        jQuery('.sst-twitch').each(function () {
            var nickname = jQuery(this).data('nickname');
			
		<?php
		if ($array1["stream"]==NULL) {
			if( get_theme_mod('sst_offline_hide') != '') { ?><?php } else { ?>jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');<?php } ?>
			// animations
			jQuery('.sst-status-text-offline').addClass('sst-current-status');
			setTimeout(function() {
				jQuery('.sst-status-text-offline').addClass('sst-current-status-active');
				jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
			}, 25);
		<?php
		} else {
		?>
			// show if online
			jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');
			// animations
			jQuery('.sst-status-text-live').addClass('sst-current-status');
			setTimeout(function() {
				jQuery('.sst-status-text-live').addClass('sst-current-status-active');
				jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
			}, 25);
		<?php
		}
		?>
        });
        </script>

	<?php
	}
	add_action('wp_footer','bonfire_sst_header');
    
    //
	// Add 'Settings' link to plugin page
	//
    add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'add_sst_action_links' );
    function add_sst_action_links ( $links ) {
        $mylinks = array(
        '<a href="' . admin_url( 'customize.php?autofocus[panel]=sst_panel' ) . '">Settings</a>',
        '<a href="https://codecanyon.net/item/twitch-status-for-wordpress/21844114?ref=BonfireThemes" target="_blank" style="color:red;">Go Pro!</a>',
        );
    return array_merge( $links, $mylinks );
    }

	//
	// ENQUEUE stream-status-for-twitch.css
	//
	function bonfire_sst_css() {
		wp_register_style( 'bonfire-stream-status-for-twitch-css', plugins_url( '/stream-status-for-twitch.css', __FILE__ ) . '', array(), '1', 'all' );
		wp_enqueue_style( 'bonfire-stream-status-for-twitch-css' );
	}
	add_action( 'wp_enqueue_scripts', 'bonfire_sst_css' );

	//
	// ENQUEUE Google WebFonts
	//
    function bonfire_sst_fonts_url() {
		$font_url = '';

		if ( 'off' !== _x( 'on', 'Google font: on or off', 'stream-status-for-twitch' ) ) {
			$font_url = add_query_arg( 'family', urlencode( 'Roboto:500' ), "//fonts.googleapis.com/css" );
		}
		return $font_url;
	}
	function bonfire_sst_scripts() {
		wp_enqueue_style( 'stream-status-for-twitch-fonts', bonfire_sst_fonts_url(), array(), '1.0.0' );
	}
	add_action( 'wp_enqueue_scripts', 'bonfire_sst_scripts' );
    
    //
	// Translation-ready
	//
    function sst_load_plugin_textdomain() {
        load_plugin_textdomain( 'stream-status-for-twitch', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
    }
    add_action( 'plugins_loaded', 'sst_load_plugin_textdomain' );
    
    //
	// Widget
	//
    class sst_widget extends WP_Widget {
        // Main constructor
        public function __construct() {
            parent::__construct(
                'sst_widget',
                __( 'Stream Status for Twitch', 'sst' ),
                array(
                    'description' => esc_html__( 'Set up channel under Appearance > Customize > Stream Status for Twitch Plugin', 'sst' ),
                    'customize_selective_refresh' => true,
                )
            );
        }
        // The widget form (for the backend)
        public function form( $instance ) {
            // widget defaults
            $defaults = array(
                'title'    => '',
            );
            
            // Parse current settings with defaults
            extract( wp_parse_args( ( array ) $instance, $defaults ) ); ?>

            <!-- Widget title -->
            <p>
                <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Widget Title', 'sst' ); ?></label>
                <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
            </p>

        <?php }
        // Update widget settings
        public function update( $new_instance, $old_instance ) {
            $instance = $old_instance;
            $instance['title']    = isset( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
            return $instance;
        }
        // Display the widget
        public function widget( $args, $instance ) {
            extract( $args );
            // Check the widget options
            $title    = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : '';
            echo $before_widget;
            // Display the widget on the front end
                // Display widget title if defined ?>
                <div class="sst-main-widget-wrapper">
                    <?php if ( $title ) {
                        echo $before_title . $title . $after_title;
                    } ?>
                    <div class="sst-widget-wrapper">
                        <?php include( plugin_dir_path( __FILE__ ) . 'include.php'); ?>
                    </div>
                </div>
            <?php echo $after_widget;
        }
    }
    // Register the widget
    function sst_register_channels_widget() {
        register_widget( 'sst_widget' );
    }
    add_action( 'widgets_init', 'sst_register_channels_widget' );

	//
	// Insert customization options into the header
	//
	function bonfire_sst_customize() {
	?>
		<!-- BEGIN CUSTOM COLORS (WP THEME CUSTOMIZER) -->
        <style>
        /* background color */
		.sst-status-wrapper { background-color:<?php echo get_theme_mod('sst_background_color'); ?>; }
        /* status text color */
        .sst-status-text-live,
        .sst-status-text-offline { color:<?php echo get_theme_mod('sst_status_text_color'); ?>; }
        /* status text hover */
        .sst-main-wrapper:hover .sst-status-text-live span,
        .sst-main-wrapper:hover .sst-status-text-offline span { color:<?php echo get_theme_mod('sst_status_text_hover_color'); ?>; }
        /* Twitch icon color */
        .sst-icon-twitch { color:<?php echo get_theme_mod('sst_twitch_icon_color'); ?>; }
        /* Twitch icon background color */
        .sst-twitch-logo-wrapper { background-color:<?php echo get_theme_mod('sst_twitch_icon_background_color'); ?>; }
        .sst-status-wrapper { border-color:<?php echo get_theme_mod('sst_twitch_icon_background_color'); ?>; }
        
        /* rounded corners */
        <?php if( get_theme_mod('sst_rounded_corners') != '') { ?>
        /* left positioning */
        .sst-twitch-logo-wrapper {
            border-top-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        .sst-status-wrapper {
            border-top-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        /* right positioning */
        <?php $bonfire_sst_placement_horizontal = get_theme_mod('sst_placement_horizontal'); if($bonfire_sst_placement_horizontal != '') { switch ($bonfire_sst_placement_horizontal) { case 'right': ?>
        .sst-twitch-logo-wrapper {
            border-top-left-radius:0px;
            border-bottom-left-radius:0px;
            border-top-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-right-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        .sst-status-wrapper {
            border-top-right-radius:0px;
            border-bottom-right-radius:0px;
            border-top-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
            border-bottom-left-radius:<?php echo get_theme_mod('sst_rounded_corners'); ?>px;
        }
        <?php break; } } ?>
        <?php } ?>
        
        /* larger design */
        <?php if( get_theme_mod('sst_larger_design') != '') { ?>
        .sst-main-wrapper {
            height:45px;
        }
        .sst-twitch-logo-wrapper {
            width:45px;
            height:45px;
        }
        .sst-icon-twitch {
            top:12px;
            left:12px;
            font-size:22px;
        }
        .sst-twitch-logo-wrapper::after {
            width:45x;
        }
        .sst-status-wrapper {
            left:45px;
            height:45px;
        }
        .sst-widget-wrapper .sst-status-wrapper {
            width:calc(100% - 47px);
        }
        .sst-status-text-live,
        .sst-status-text-offline {
            font-size:13px;
        
            -webkit-transform:translateY(0);
            -moz-transform:translateY(0);
            transform:translateY(0);
        }
        <?php } ?>
        
        /* absolute positioning */
        <?php if( get_theme_mod('sst_absolute_position') != '') { ?>
        .sst-main-wrapper { position:absolute; }
        <?php } ?>
        
        /* distances (if at top) */
        .sst-main-wrapper {
            top:<?php echo get_theme_mod('sst_vertical_distance'); ?>px;
            left:<?php echo get_theme_mod('sst_horizontal_distance'); ?>px;
        }
        
        /* bottom placement + distances */
        <?php $bonfire_sst_placement = get_theme_mod('sst_placement'); if($bonfire_sst_placement != '') { switch ($bonfire_sst_placement) { case 'bottom': ?>
        .sst-main-wrapper {
            top:auto;
            bottom:<?php if( get_theme_mod('sst_vertical_distance') != '') { ?><?php echo get_theme_mod('sst_vertical_distance'); ?><?php } else { ?>25<?php } ?>px;
        }
        <?php break; } } ?>

        /* right placement + distances */
        <?php $bonfire_sst_placement_horizontal = get_theme_mod('sst_placement_horizontal'); if($bonfire_sst_placement_horizontal != '') { switch ($bonfire_sst_placement_horizontal) { case 'right': ?>
        .sst-main-wrapper {
            left:auto;
            right:<?php if( get_theme_mod('sst_horizontal_distance') != '') { ?><?php echo get_theme_mod('sst_horizontal_distance'); ?><?php } else { ?>25<?php } ?>px;
        }
        .sst-status-wrapper {
            left:auto;
            <?php if( get_theme_mod('sst_larger_design') != '') { ?>right:45px;<?php } else { ?>right:32px;<?php } ?>
            border-right:none;
            border-left-width:2px;
            
            -webkit-transform-origin:right top;
            -moz-transform-origin:right top;
            transform-origin:right top;
        }
        .sst-twitch-logo-wrapper { right:0; }
        <?php break; } } ?>
        
        /* disable animation */
        <?php if( get_theme_mod('sst_disable_animation') != '') { ?>
        .sst-status-wrapper {
            -webkit-transform:scaleX(1);
            -moz-transform:scaleX(1);
            transform:scaleX(1);
        }
        .sst-status-text-live,
        .sst-status-text-offline {
            opacity:1;
        }
        <?php } ?>
        
        /* no status text underline */
        <?php if( get_theme_mod('sst_no_underline') != '') { ?>
        .sst-main-wrapper:hover .sst-status-text-live span,
        .sst-main-wrapper:hover .sst-status-text-offline span { text-decoration:none; }
        <?php } ?>
        
        /* hide between resolutions */
		@media ( min-width:<?php echo get_theme_mod('sst_smaller_than'); ?>px) and (max-width:<?php echo get_theme_mod('sst_larger_than'); ?>px) {
			.sst-main-wrapper { display:none !important; }
		}
		</style>
		<!-- END CUSTOM COLORS (WP THEME CUSTOMIZER) -->
	
	<?php
	}
	add_action('wp_head','bonfire_sst_customize');

?>

Should correct the code

You left the redundant second call to the streams API in


#17

Thanks for your effort. I really try to forward all informations to the guy helping us to update the code, as I’m not able to do it. Unfortunately, even content of the “main wrapper” still don’t work and the image displays “Offline”, even when streaming over the channel.

In details this means:

 <!-- BEGIN MAIN WRAPPER (show only if Twitch channel name entered) -->
        <?php if( get_theme_mod('sst_channel_name') != '') { 
		
		$channel=get_theme_mod('sst_channel_name');
		$url0="https://api.twitch.tv/helix/users?login=".$channel;
		
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			'Accept: application/vnd.twitchtv.v5+json',
			'Client-ID: ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
		));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		
		curl_setopt($ch, CURLOPT_URL,$url0);
		$result=curl_exec($ch);
		$array0=json_decode($result, true);

		$channel_id=$array0["data"][0]["id"];
		$url1="https://api.twitch.tv/kraken/streams/".$channel_id;
		
		curl_setopt($ch, CURLOPT_URL,$url1);
		$result=curl_exec($ch);
		$array1=json_decode($result, true);
		
		?>
        <div class="sst-main-wrapper">
            <?php include( plugin_dir_path( __FILE__ ) . 'include.php'); ?>
        </div>
        <?php } ?>
        <!-- END MAIN WRAPPER (show only if Twitch channel name entered) -->

works (yet).

And this from your changes…

<!-- BEGIN MAIN WRAPPER (show only if Twitch channel name entered) -->
        <?php if( get_theme_mod('sst_channel_name') != '') { 
		
        $url="https://api.twitch.tv/helix/streams?user_login=".get_theme_mod('sst_channel_name');
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Client-ID: ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
        ));
        $result=curl_exec($ch);
        $array1=json_decode($result, true);

		?>
        <div class="sst-main-wrapper">
            <?php include( plugin_dir_path( __FILE__ ) . 'include.php'); ?>
        </div>
        <?php } ?>
        <!-- END MAIN WRAPPER (show only if Twitch channel name entered) -->

works not.

Can it have something to do with the additional “include.php”-file as following?

<?php
$stream_url = "https://twitch.tv/".get_theme_mod('sst_channel_name');
if (get_theme_mod('sst_channel_url')!="") {
	$stream_url = get_theme_mod('sst_channel_url');
}
?>

<a class="sst-twitch" <?php if( get_theme_mod('sst_new_window') != '') { ?>target="_blank"<?php } ?> href="<?php echo $stream_url; ?>" data-nickname="<?php echo get_theme_mod('sst_channel_name'); ?>">
    <!-- BEGIN TWITCH LOGO -->
    <div class="sst-twitch-logo-wrapper">
        <div class="sst-icon-twitch"></div>
    </div>
    <!-- END TWITCH LOGO -->
    <!-- BEGIN STATUS -->
    <div class="sst-status-wrapper">
        <div class="sst-status-wrapper-inner">
            <!-- BEGIN IF ONLINE -->
            <div class="sst-status-text-live">
                <div class="sst-live-marker"></div>
                <span>
                    <?php if( get_theme_mod('sst_live_text') != '') { ?>
                        <?php echo get_theme_mod('sst_live_text'); ?>
                    <?php } else { ?>
                        <?php esc_html_e( 'LIVE NOW! CLICK TO VIEW.', 'stream-status-for-twitch' ); ?>
                    <?php } ?>
                </span>
            </div>
            <!-- END IF ONLINE -->
            <!-- BEGIN IF OFFLINE -->
            <div class="sst-status-text-offline">
                <span>
                    <?php if( get_theme_mod('sst_offline_text') != '') { ?>
                        <?php echo get_theme_mod('sst_offline_text'); ?>
                    <?php } else { ?>
                        <?php esc_html_e( 'CURRENTLY OFFLINE', 'stream-status-for-twitch' ); ?>
                    <?php } ?>
                </span>
            </div>
            <!-- END IF OFFLINE -->
        </div>
    </div>
    <!-- END STATUS -->
</a>

#18

All your code does is json_decode the response from Twitch it doesn’t process the return data.

The format of the return is documented here

If you have `{“data”:[]}’ then no stream is active, if you have ‘{"data:[{ASTREAM}]}’ (where ASTREAM is a payload as documented) then you are live. Your code doesn’t process this

The contents of the include.php file don’t make any sense. There are not if switches testing for a stream present data returned from the API.

if it’s using template switches, then the template tag ONLINE (which seems unlikely) if is never set anyway.

This is a Wordpress/plugin problem not a Twitch API one.


#19

I’ve forwarded that information now and I think it’s finally solved now with the new API code:

<!-- BEGIN MAIN WRAPPER (show only if Twitch channel name entered) -->
<?php if( get_theme_mod('sst_channel_name') != '') { 
	
	$channel=get_theme_mod('sst_channel_name');
	$api_url="https://api.twitch.tv/helix/streams?first=1&user_login=".$channel;
	
	$ch = curl_init();

	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		'Client-ID: ls2awgx5gfg9m1q6iopdqb1b7d0y6a'
	));
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	
	curl_setopt($ch, CURLOPT_URL,$api_url);
	$result=curl_exec($ch);
	$twitch_array=json_decode($result, true);

	$online_status=$twitch_array["data"][0]["type"];
	curl_close($ch);
	
	?>
<div class="sst-main-wrapper">
    <?php include( plugin_dir_path( __FILE__ ) . 'include.php'); ?>
</div>
<?php } ?>
<!-- END MAIN WRAPPER (show only if Twitch channel name entered) -->

<script>
jQuery('.sst-twitch').each(function () {
    var nickname = jQuery(this).data('nickname');
		
	<?php
	if ($online_status!="live") {
		if( get_theme_mod('sst_offline_hide') != '') { ?><?php } else { ?>jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');<?php } ?>
		// animations
		jQuery('.sst-status-text-offline').addClass('sst-current-status');
		setTimeout(function() {
			jQuery('.sst-status-text-offline').addClass('sst-current-status-active');
			jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
		}, 25);
	<?php
	} else {
	?>
		// show if online
		jQuery('.sst-main-wrapper, .sst-main-widget-wrapper').addClass('sst-main-wrapper-active');
		// animations
		jQuery('.sst-status-text-live').addClass('sst-current-status');
		setTimeout(function() {
			jQuery('.sst-status-text-live').addClass('sst-current-status-active');
			jQuery('.sst-status-wrapper').addClass('sst-status-wrapper-active');
		}, 25);
	<?php
	}
	?>
});
</script>