Created
March 25, 2014 17:50
-
-
Save dobsondev/9767299 to your computer and use it in GitHub Desktop.
Shortcode for Embedding a Twitch.tv Stream - Used in DobsonDev Shortcodes Plugin for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Adds a shortcode to embed a Twitch Stream */ | |
function dobson_embed_twitch($atts) { | |
extract(shortcode_atts(array( | |
'username' => "Invalid Username", | |
'width' => "620", | |
'height' => "378", | |
), $atts)); | |
$source_headers = @get_headers("http://twitch.tv/" . $username); | |
if (strpos($source_headers[0], '404 Not Found')) { | |
return '<p> Invalid Twitch channel name. Please check your username and channel settings on Twitch to make ' | |
. 'sure they are setup correctly. </p>'; | |
} else { | |
return '<object type="application/x-shockwave-flash" height="' . $height . '" width="' . $width | |
. '" id="live_embed_player_flash" data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=' | |
. $username . '" bgcolor="#000000"> | |
<param name="allowFullScreen" value="true" /> | |
<param name="allowScriptAccess" value="always" /> | |
<param name="allowNetworking" value="all" /> | |
<param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" /> | |
<param name="flashvars" value="hostname=www.twitch.tv&channel=' . $username . '&auto_play=true&start_volume=25" /> | |
</object>'; | |
} | |
} | |
add_shortcode('embedTwitch', 'dobson_embed_twitch'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment