PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.2
Jetpack – WP Security, Backup, Speed, & Growth v6.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / twitchtv.php

twitchtv.php in Jetpack – WP Security, Backup, Speed, & Growth 6.2, at modules/shortcodes/twitchtv.php

74 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * twitch.tv shortcode
4 * [twitchtv url='http://www.twitch.tv/paperbat' height='378' width='620' autoplay='false']
5 * [twitchtv url='http://www.twitch.tv/paperbat/b/323486192' height='378' width='620' autoplay='false']
6 **/
7
8 /**
9 * (Live URL) http://www.twitch.tv/paperbat
10 *
11 * <iframe src="https://player.twitch.tv/?autoplay=false&#038;muted=false&#038;channel=paperbat" width="620" height="378" frameborder="0" scrolling="no" allowfullscreen></iframe>
12 *
13 * (Archive URL) http://www.twitch.tv/paperbat/v/323486192
14 *
15 * <iframe src="https://player.twitch.tv/?autoplay=false&#038;muted=false&#038;video=v323486192" width="620" height="378" frameborder="0" scrolling="no" allowfullscreen></iframe>
16 *
17 * @param $atts array User supplied shortcode arguments.
18 *
19 * @return string HTML output of the shortcode.
20 */
21 function wpcom_twitchtv_shortcode( $atts ) {
22 $attr = shortcode_atts(
23 array(
24 'height' => 378,
25 'width' => 620,
26 'url' => '',
27 'autoplay' => 'false',
28 'muted' => 'false',
29 'time' => null
30 ), $atts
31 );
32
33 if ( empty( $attr['url'] ) ) {
34 return '<!-- Invalid twitchtv URL -->';
35 }
36
37 preg_match( '|^http://www.twitch.tv/([^/?]+)(/v/(\d+))?|i', $attr['url'], $match );
38
39 $url_args = array(
40 'autoplay' => ( false !== $attr['autoplay'] && 'false' !== $attr['autoplay'] ) ? 'true' : 'false',
41 'muted' => ( false !== $attr['muted'] && 'false' !== $attr['muted'] ) ? 'true' : 'false',
42 'time' => $attr['time']
43 );
44
45 $width = intval( $attr['width'] );
46 $height = intval( $attr['height'] );
47
48 $user_id = $match[1];
49 $video_id = 0;
50 if ( ! empty( $match[3] ) ) {
51 $video_id = (int) $match[3];
52 }
53
54 do_action( 'jetpack_bump_stats_extras', 'twitchtv', 'shortcode' );
55
56 if ( $video_id > 0 ) {
57 $url_args['video'] = 'v' . $video_id;
58 } else {
59 $url_args['channel'] = $user_id;
60 }
61
62 $url = add_query_arg( $url_args, 'https://player.twitch.tv/' );
63
64 return sprintf(
65 '<iframe src="%s" width="%d" height="%d" frameborder="0" scrolling="no" allowfullscreen></iframe>',
66 esc_url( $url ),
67 esc_attr( $width ),
68 esc_attr( $height )
69 );
70 }
71
72 add_shortcode( 'twitch', 'wpcom_twitchtv_shortcode' );
73 add_shortcode( 'twitchtv', 'wpcom_twitchtv_shortcode' );
74