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?