Wordpress plugin - twitch stream status - can someone PLEASE check the code?

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
}

What I have tried:

the plugin wasn’t working because of the outdated API. I need to use the plugin but my knowledge of json-PHP isn’t the best. I want to put a URL from a twitch account so that the plugin checks the URL and if the account streams live then the tag shows the message “LIVE NOW” else shows “offline”. I can’t make it work.
With this line: if ($array1["stream"]== NULL) { it always shows the message in the tag “offline” for every account i put even if the account is actually streaming.
But if i change the line to this: if ($array1["stream"]!= NULL) { then it shows all the accounts that are streaming right now.
what is the problem? can you check it please?

Helix output is different to krakens.

if (count($array1['data']) == 1) {
    // is live
} else {
    // not live
}

Should suffice

firstly thank you so much for the response! so the code if i make the change with your code should work? it will be ok? because i made the change and now the tag doesn’t appear at all. i don’t know if it’s a wordpress problem or the code part above.
in dev tools chrome it gives me this error:
error
for this part of code:

    jQuery('.sst-twitch').each(function () {
        var nickname = jQuery(this).data('nickname');
        
    <br />

Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\testsite\wordpress\wp-content\plugins\stream-status-for-twitch\stream-status-for-twitch.php on line 253

//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);
});

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.